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?
Beta regression problemHi, I am using panel data for 27 different countries in 5 different time periods. My IV and DV both …
How to put frequency, mean and other specific values into WORD and EXCELHi there, I am currently dealing with descriptive analysis. In my dataset, there are many categoric…
Postfile command gives error/notification ''File not found''Dear all, I ran the following code in Stata: Code: clear all set seed 312312 set obs 100 gen t = _…
How to add two variables with one conditions each using graph barI would like to graph two variables with one condition each. For example, I would like to graph wage…
Making graphs of variablesHello, I want to make two graphs in Stata but I don't know how to do that. I have the following dat…
Subscribe to:
Post Comments (Atom)
0 Response to Egen mean using only one value per subgroup?
Post a Comment