Hi!
I want to use the egen command to create group means, using the by() command.
Basically, "egen MEAN = mean(YearlyVariable), by(country)"
But, one twist - I want to command to consider only one value per each subgroup.
I have three-level data: individuals nested in country-years nested in countries. I have variables at each level. Now I want to take a country-year variable (which is same for all individuals in that country-year but different across years within a country) and compute a mean within each country. But I don't want years with more individuals to get more emphasis. Thus, I want to base the mean on only one value per country-year, but I want the variable to extend to all individuals within that country.
Is there a way to do this without workarounds using for example =tag command?
And if I use =tag anyway, how do I assign the value of the new variable to all individuals within the same country?
This is how I would do it with =tag:
egen TAGcountryyear = tag (country year)
egen MEAN = mean(YearlyVariable), by(country) if TAGcountryyear == 1
----- but then the new variable is assigned only to those individuals who were tagged, how do I extend it to all in the same country?
0 Response to Egen mean using only one value per subgroup?
Post a Comment