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?
Replacing multiple values, with the same conditionHi All, Although the -replace- command is fairly intuitive, it is sometimes a bit tricky. Specific…
Visualizing an interaction termDear Statalist, I have just recently started using Stata, so this might be a rookie question. I ha…
weighted transition matrixHello, I am working with a household survey panel data. I have weights (not integer, time varying) …
Question on oneway anova and pairwise comparisonRecently, I'm conducting research, we would like to see some difference between different national i…
Estimate the C-score and G-score following Khan and Watts(2009) - Journal of Accounting and EconomicsAll: I tried to estimate the C-score and G-score following Khan and Watts(2009) - Journal of Account…
Subscribe to:
Post Comments (Atom)
0 Response to Egen mean using only one value per subgroup?
Post a Comment