I need to generate a new variable that is a standardized value of another variable but by a group (SAT scores by year). I calculated it using the following code:
egen mean_sat = mean(sat), by(year)
egen sd_sat = sd(sat), by(year)
gen std_dat = (sat - mean_sat) / sd_sat
Is there another more direct way to do that? I tried the following with no success...
. by year, sort : egen float std_SAT = std(sat)
egen ... std() may not be combined with by
r(190);
. egen std_SAT = std(sat), by(year)
egen ... std() may not be combined with by