Dear Community,
I want to create a loop, calculating averages for few variables, so that my code would be shorter and it would save me some time. I have 6 indicators ind1 till ind6. I want to calculate yearly averages for them. I typed the code:
I saw variablr mean_ind1_year already defined. It is bizzare to me since I didn't define the variable.
I want to create a loop, calculating averages for few variables, so that my code would be shorter and it would save me some time. I have 6 indicators ind1 till ind6. I want to calculate yearly averages for them. I typed the code:
Code:
forvalues i=1(1)6{
foreach x of varlist ind1-ind6{
egen mean_ind`i'_year=mean(`x'), by(year)
}
}

Comment