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?
Exogenous variables in rdrobustWhen using the command rdrobust, developed by Matias Cattaneo, to estimate a fuzzy RD design, I am u…
Estimating a system of (non-structural) equationsDear Statalisters, I have a cross-sectional data from many industries which I will use to estimate …
ourteg2, addtableWHy does my second table rewrite over my first table instead when I use this command? …
Interpreting Semi-Elasticities From "margins"I am estimating a multinomial logit model using mlogit. My dependent variable, y, has three outcomes…
Creating super columns with esttabHello, I'm trying to save regression results to latex using esttab in Stata 15.1. I have two outcom…
Subscribe to:
Post Comments (Atom)
0 Response to Egen mean using only one value per subgroup?
Post a Comment