I have data with a date variable and some other variables. For each date, there are multiple observations. I am looking to iterate over a range of variables and for each of these variables create a new mean variable, which indicates the mean of that variable for that date. This is the code I have so far:
Code:
foreach var in gp-lev{ egen `var'_mean = mean(var), by(fyear) }
I cannot get it to work. Any tips?
0 Response to Loop to create new variables
Post a Comment