Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Martin Weiss" <martin.weiss1@gmx.de> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: on balancing a panel data |
Date | Mon, 13 Sep 2010 12:37:46 +0200 |
<> The first two lines in Chris` code could be easily telescoped: *********** use http://www.stata-press.com/data/r11/nlswork.dta, clear qui xtset gen ones=1 bysort `r(panelvar)': egen numobs=sum(ones) qui xtset bysort `r(panelvar)': gen numobs2=_N compare numobs numobs2 *********** HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Chris Parker Sent: Montag, 13. September 2010 11:59 To: statalist@hsphsun2.harvard.edu Subject: Re: st: on balancing a panel data Sorry if this gets sent twice. I wasn't sending text only before. gen ones=1 bysort country: egen numobs=sum(ones) su numobs, meanonly drop if numobs<r(max) drop ones numobs Should do what you want. Chris Parker ________________________________ PhD Candidate | Management Science & Operations London Business School | Regent's Park | London NW1 4SA | United Kingdom Direct line +44 (0)20 7000 8816 | Email cparker.phd2007@london.edu On Mon, Sep 13, 2010 at 3:20 PM, <rado645-bg@yahoo.de> wrote: > > to avoid misunderstanding i need to correct a sentence in my post:please read > "i.e. to keep only those > > countries for which data is available for each year and exclude the rest" as > "i.e. to keep only those countries that appear each year and exclude the rest". > > In the example I have given, this would be then countries 1 and 2. > > > > ----- Ursprüngliche Mail ---- > Von: "rado645-bg@yahoo.de" <rado645-bg@yahoo.de> > An: statalist@hsphsun2.harvard.edu > Gesendet: Montag, den 13. September 2010, 11:31:36 Uhr > Betreff: st: on balancing a panel data > > Dear all, > > I have a panel data set of observations for countries over several years. The > number of countries varies: the minimum number is 52 per year and the maximum > number is 73. For certain reasons (graphs), I would like to make the panel > dataset a kind of balanced and I need to have the same countries in each year > across the sample period even if I would need to exclude some of them. > > Could you help me on how one can make this in Stata, i.e. to keep only those > countries for which data is available for each year and exclude the rest. Below > is a simplified description of the dataset: > > year country var1 > 1990 1 ... > 1990 2 ... > 1990 3 > 1991 1 > 1991 2 > 1992 1 > 1992 2 > 1992 3 > 1992 4 > 1992 5 > 1993 1 > 1993 2 > 1993 5 > ... > > > > > * > * 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/ > > > > > * > * 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/ > > ______________________________________________________________________ > > This email has been scanned by the MessageLabs Email Security System > on behalf of the London Business School community. > For more information please visit http://www.messagelabs.com/email > ______________________________________________________________________ * * 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/ * * 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/