Hello-
Does anyone know if there is a fast way to code new variables in Stata so that
they equal the mean value of a subpopulation's score on particular other
variables?
For example, I am analyzing two main subpopulations: migrants and natives.
Both of which are nested in countries and regions. I want to calculate a new
variable which captures the mean attitudes of natives in each country/region
and then use that as an independent variable in a model predicting migrant
outcomes.
I have used the code below to calculate mean attitudes of the entire population
for country/region but I can't figure out how to make that calculation apply to
only one subgroup yet still have the variable be valid for the whole
population. (If I add an 'if' clause at the end of the code it will drop all
cases that don't apply).
by country, sort : egen float countryattitudes = mean(attitudes)
by region, sort : egen float regionattitudes = mean(attitudes)
I have been calculating subgroup means 'by hand' and then manually writing code
for the countries. Which is slow. But I have almost 300 regions and multiple
variables so I'm wondering if there is a faster way to do this?
And more generally, is it possible to create a new variable with multiple
values per country/region for means across different groups. I.E. I want
country1 to have one value for the mean attitude of natives and another value
for the mean attitude of migrants. I want to do this in order to graph
migrant/native means across the countries and regions.
Any advice is much appreciated,
Rahsaan Maxwell, Ph.D.
Assistant Professor
Department of Political Science
University of Massachusetts, Amherst
Postdoctoral Fellow
Transatlantic Academy
German Marshall Fund of the United States
http://rahsaanmaxwell.googlepages.com
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/