Combining Macros and Loops (Loops)
Here you’ll combine local macros and foreach loops along with varlist to create new variables and run multiple regressions.
- Create a local macro named
logvarsthat contains three nonnegative variables that you expect to be skewed:yield_kgharvest_value_USDtotcons_USD
Use a foreach loop over the variables in logvars to create log-transformed versions of each variable:
- For each variable
vinlogvars, generateln_v’ = ln(v') - Label each new variable
"log of v" - Use
sumto calculate the mean for each logged variable
What is the mean value of each variable?
- Now define two more local macros:
local yvars ln_*local controls plot_area_GPS irrigated nitrogen_kg female_manager
Use a foreach loop to run regressions of each outcome in yvars on the same set of controls. In each regression, what controls are not significant?