Is there some way I could use nested loop to recode the following, where one variable loops between 2014 and 2016, and the other variable loops between mean and sd?
I mean something like the following, although I know it is way off (I'm just learning to loop on Stata).
Thanks!
Code:
by villageid_2014, sort: egen village_income_mean_2014=mean(income_current_2014) by villageid_2016, sort: egen village_income_mean_2016=mean(income_current_2016) by villageid_2014, sort: egen village_income_sd_2014=sd(income_current_2014) by villageid_2016, sort: egen village_income_sd_2016=sd(income_current_2016)
Code:
local i 2014 2016 local j mean sd foreach var in `i' { foreach var in `j' { by villageid_`i', sort: egen vdc_income_`j'=`j'(income_current_`i') } }
Comment