[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nichols, Austin" <ANichols@ui.urban.org> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: collapse if at least X or more obs. per group are non-missing |

Date |
Tue, 24 Aug 2004 12:51:14 -0400 |

No, you just have to name the "target" variables differently, e.g. collapse (mean) mean_GDP=GDP (count) count_GDP=GDP , by(country decade) Or you could use -egen- without losing the data in memory, e.g. egen mean_GDP=mean(GDP), by(country decade) egen count_GDP=count(GDP), by(country decade) replace mean_GDP=. if count_GDP<=5 -----Original Message----- From: Jens Hainmueller [mailto:jens_hainmueller@ksg05.harvard.edu] Sent: Tuesday, August 24, 2004 3:19 PM To: statalist@hsphsun2.harvard.edu Subject: st: collapse if at least X or more obs. per group are non-missing Dear Statalisters, I'd like to convert a panel data set with annual country obs to one of decadal country averages, excluding those decadal averages for which 5 or more observations per country are missing within a decade. My first idea was to use a two step procedure along the lines of: 1. Run: collapse (mean) GDP (count) GDP , by(country decade) this should give me a) the decadal averages I want and b) the number of non-missing obs used to compute each of these decadal averages. 2. replace mean_GDP=. if count_GDP<5 (or whatever STATA will call these vars saving the means & counting the non-missing obs) this should set to missing those decadal averages for which 5 or more observations per country were missing within each decade. However, trying this I get the following error message: . collapse (count) GDP (mean) GDP, by(sftgcode decade) error: GDP = (count) GDP GDP = (mean) GDP name conflict r(198); Does this mean that I cannot get means and counts for the same variable at the same time when using collapse? Moreover, is there any way to directly aggregate annual obs to decadal country averages while omitting those averages for which a pre-specified number of obs. is missing per country? I wasn't able to find any solution to this on the archives, although I assume it's a rather common problem. Thank you very much for your help. Best, Jens Hainmueller * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: St: store estimates for ADF** - Next by Date:
**st: RE: regression question** - Previous by thread:
**st: St: store estimates for ADF** - Next by thread:
**st: RE: regression question** - Index(es):

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