Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: RE: RE: Dropping non-consecutive observations in a panel |

Date |
Wed, 30 Jun 2010 22:34:59 +0200 |

<> Using -fillin- functionality, we can also make the patterns more transparent than in the -xtdes- output: *********** clear* set obs 100 //id gen byte id=_n //expand to # of time periods expand 10 //get time period bys id: gen byte time=_n //xtset the thing xtset id time //induce missings set seed 742 drop if runiform()<.2 //see patterns xtdes in 1/52 //see them more clearly preserve qui{ fillin id time replace _fillin=!_fillin ren _fillin pattern reshape wide pattern, i(id) j(time) } l in 1/7, sep(1) noo restore *********** HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lynnae Ruberg Sent: Mittwoch, 30. Juni 2010 22:17 To: 'statalist@hsphsun2.harvard.edu' Subject: st: RE: RE: Dropping non-consecutive observations in a panel Many thanks! -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss Sent: Wednesday, June 30, 2010 3:32 PM To: statalist@hsphsun2.harvard.edu Subject: st: RE: Dropping non-consecutive observations in a panel <> Btw, 11.1 is out, so you should -update all- *********** clear* inp byte(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 end xtset id time bys id: gen diff=D.time by id: egen mycount=count(diff) l, sepby(id) by id: drop if mycount != _N-1 drop mycount diff l, sepby(id) *********** HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lynnae Ruberg Sent: Mittwoch, 30. Juni 2010 21:20 To: statalist@hsphsun2.harvard.edu Subject: st: Dropping non-consecutive observations in a panel 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/ * * 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/ * * 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/

**References**:**st: Dropping non-consecutive observations in a panel***From:*Lynnae Ruberg <lruberg@OxfamAmerica.org>

**st: RE: Dropping non-consecutive observations in a panel***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: RE: Dropping non-consecutive observations in a panel***From:*Lynnae Ruberg <lruberg@OxfamAmerica.org>

- Prev by Date:
**st: "Hours" in Stata** - Next by Date:
**st: RE: "Hours" in Stata** - Previous by thread:
**st: RE: RE: Dropping non-consecutive observations in a panel** - Next by thread:
**st: Trying to import an XML file into STATA** - Index(es):