[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Eva Poen <eva.poen@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Stata coding |

Date |
Mon, 13 Apr 2009 13:42:44 +0100 |

2009/4/13 Rahsaan Maxwell <rahsaan@polsci.umass.edu>: > 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. Not quite sure what you want here. Is the idea to calculate mean attitudes for each country/region of natives, and to have that value in _all_ observations of the country/region (natives and migrants)? I think this will do it: egen mean_att = mean(attitudes) if native==1, by(country region) bys country region (mean_att) : replace mean_att = mean_att[1] > 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. If you want to graph it, look at -graph bar- which does this sort of thing out of the box. If you don't like bar graphs, you could use -collapse attitude, by(country region native)- to create a dataset of means, which you can then graph in whatever form you like. Alternatively, you could obviously use the above code again with native==0. Hope this helps, Eva * * 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/

**References**:**st: Stata coding***From:*Rahsaan Maxwell <rahsaan@polsci.umass.edu>

- Prev by Date:
**st: Efficiently run three loops (or do without them)** - Next by Date:
**st: RE: Stata coding** - Previous by thread:
**st: Stata coding** - Next by thread:
**st: RE: Stata coding** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |