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

From |
Nick Winter <nw53@cornell.edu> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Wed, 25 Aug 2004 10:52:39 -0400 |

At 12:19 PM 8/24/2004 -0700, you wrote:

It has already been pointed out that you must give different names to your new variables with this solution.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.

Another way to go would be:

. bysort country decade: generate N = _N

. collapse GDP if N>5

This would be appropriate, obviously, if you only need the count in order to drop the ones you don't want; if you need it for other things then go ahead with the original twostep procedure.

Nick WINter

--------------------------------------------------------

Nicholas Winter 607.255.8819 t

Assistant Professor 607.255.4530 f

Department of Government nw53@cornell.edu e

308 White Hall falcon.arts.cornell.edu/nw53 w

Cornell University

Ithaca, NY 14853-4601

*

* 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/

**References**:**st: collapse if at least X or more obs. per group are non-missing***From:*"Jens Hainmueller" <jens_hainmueller@ksg05.harvard.edu>

- Prev by Date:
**Re: st: collapse if at least X or more obs. per group are non-missing** - Next by Date:
**st: RE: Covariance matrice.** - Previous by thread:
**st: collapse if at least X or more obs. per group are non-missing** - Next by thread:
**Re: st: collapse if at least X or more obs. per group are non-missing** - Index(es):

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