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

Re: st: deleting observations in panel


From   Gregor Franz <[email protected]>
To   [email protected]
Subject   Re: st: deleting observations in panel
Date   Sun, 11 Dec 2005 11:25:17 -0800

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

Thanks again.


Kit Baum wrote:


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.


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html


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



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