Hello,

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)

}
These means will be used to calculate z-scores per observation per date.

I cannot get it to work. Any tips?