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?
Related Posts with Egen mean using only one value per subgroup?
Analyzing two time points with regressionI am analyzing data with the mental health component score (measured 0-100) for 4500 individuals. Th…
longitudinal population survey dataHello, I have a longitudinal population survey data. This is actually my first time working with su…
groups command, export/copy table to excelthe groups function is a very useful command, however the output seems to be not very transferable -…
mi predict problemDear all, I am having problems trying to get the baseline survivor function after mi predict. I am …
Attrition and OLS estimatosHow can I prove that the attrition bias affects or does not affect my OLS estimator? Can I do it wit…
Subscribe to:
Post Comments (Atom)
0 Response to Egen mean using only one value per subgroup?
Post a Comment