[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Stata coding
Rahsaan Maxwell <firstname.lastname@example.org>
st: Stata coding
Sun, 12 Apr 2009 22:44:53 -0400
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
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
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.
Department of Political Science
University of Massachusetts, Amherst
German Marshall Fund of the United States
* For searches and help try: