Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: deleting observations in panel


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: deleting observations in panel
Date   Sun, 11 Dec 2005 19:48:56 -0000

The reason that 

bysort panelid: drop if sum(year) ~= 12003

does not work if that -sum()- gives a 
running or cumulative sum, not group sums. 

This would have worked 

bysort panelid : egen sumyear = total(year)
drop if sumyear != 12003

but the method recommended by Kit Baum is
greatly preferable. 

Nick 
[email protected] 

Gregor Franz
 
> Great!! Thank you so much! I knew it had to be fairly obvious, I just 
> couldn't figure it out.

Kit Baum
 
> > Gregor wrote
> > I have an unbalanced panel and would like to delete all the 
> observations
> > for which I don't have the whole date range.
> >
> > year   panelid    x
> > 1            1         5
> > 2            1         3
> > 3            1         4
> > 1            2         7
> > 3            2         4
> >
> > In this example I would like to delete panelid 2. So that 
> in the end I
> > have data for every possible year for every panelid. I 
> tried to drop if
> > the sum of the years is not equal to the sum of all the 6 
> years I have
> > data for (1998 to 2003), but that just left me with the 
> last year of my
> > data.
> > I used bysort panelid: drop if sum(year) ~= 12003
> >
> >
> > bysort panelid: drop if _N < 6
> >
> > Remember that under a by-list _n means the current obs. and 
> _N means  
> > the last obs. So for an unbalanced panel, _N will be 6 for every  
> > complete unit, and less than that for the ones you want to zap.

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



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