Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Dropping non-consecutive observations in a panel
From
Lynnae Ruberg <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Dropping non-consecutive observations in a panel
Date
Wed, 30 Jun 2010 15:19:41 -0400
Dear Statalist,
I'm relatively new to STATA, so your patience is appreciated.
I'm using STATA/SE 11.0 for Windows to analyze a panel data set. I -xtset- time and id for the panel. I would like to use only the panels that have unbroken observations across time - i.e. if id 1 was observed in time periods 1, 2, and 4, I don't want to use it, but if it was observed in 2, 3, and 4, then I do.
When I run -xtdescribe- I see that 98% of my data have an unbroken pattern (like the latter example above). Is there a straightforward way of telling STATA to only use these & drop (or simply ignore) the rest? Alternatively, is there a way to browse the data according to the pattern it has in -xtdescribe-?
Here's the work-around I've come up with for identifying skipped ids, but I'd love to know if there's any easier way of approaching it.
sort id(time)
by id: gen first_time=time[1]
by id: gen last_time=time[_N]
by id: egen a=count(time)
gen b=(last_time-first_time)+1
gen c=b-a
id time first_time last_time a b c
1 1 1 4 4 4 0
1 2 1 4 4 4 0
1 3 1 4 4 4 0
1 4 1 4 4 4 0
2 2 2 4 3 3 0
2 3 2 4 3 3 0
2 4 2 4 3 3 0
3 1 1 4 3 4 1
3 3 1 4 3 4 1
3 4 1 4 3 4 1
In id==3, time period 2 is skipped; this is "caught" by the different between the count of time periods per id (variable a) and the total number of time periods that id is observed - if an id isn't skipped, the difference will be 0. I'd use -if c==0- in my analysis. Doing it this way identifies 97% of the data as unbroken (so it's not producing the same result as -xtdescribe-, which I can't figure out).
If there is an easier/more accurate way of doing this, I'd love to know how.
Many thanks,
Lynnae
-------------------------------------------
Lynnae E. Ruberg
Technical Intern
Community Finance Department
Oxfam America
*
* 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/