As usual I feel that I'm missing something simple but haven't managed to work out what I need to do.
So I've generated a variable:
egen var_x = mean(var_y)
however I don't want the mean of the whole variable, I want to exclude some which meet a certain condition (which I have a separate variable for). var_z=1
I tried:
egen var_x = mean(var_y) if var_z ==1
however that generates the same mean value but only generates it for cases where var_z == 1 whereas I want to generate a var_x for all cases but taking the mean from a specific subgroup of var_y.
Am I overlooking something incredibly obvious?
So I've generated a variable:
egen var_x = mean(var_y)
however I don't want the mean of the whole variable, I want to exclude some which meet a certain condition (which I have a separate variable for). var_z=1
I tried:
egen var_x = mean(var_y) if var_z ==1
however that generates the same mean value but only generates it for cases where var_z == 1 whereas I want to generate a var_x for all cases but taking the mean from a specific subgroup of var_y.
Am I overlooking something incredibly obvious?
Comment