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

st: RE: RE: Drop observations


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Drop observations
Date   Mon, 10 Nov 2003 17:52:22 -0000

There is also a non-canned solution at 

http://www.stata.com/support/faqs/data/panel.html

which you could use after (temporarily, if you like)
-drop-ping all observations with missing values. 

. egen nmiss = rmiss(y x1 x2 x3)
. drop if nmiss 
. by id: gen run = cond(L.run == ., 1, L.run + 1)
. by id: egen maxrun = max(run)
. drop if maxrun < 4 


Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Nick Cox
> Sent: 10 November 2003 16:57
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Drop observations
> 
> 
> I assume identifier variable -id-, time variable -t- 
> and that you have -tsset- the data. 
> 
> For regression it's problematic if either the response
> or any of the covariates is missing. Compute 
> 
> . egen nmiss = rmiss(y x1 x2 x3) 
> 
> One way of doing it then is to use -tsspell- from 
> SSC. 
> 
> . ssc inst tsspell 
> . tsspell, cond(nmiss == 0) 
> 
> defines spells for which all variables are present, 
> and does so automatically within panels. 
> 
> The longest spell in each panel is then 
> 
> . egen longest = max(_seq), by(id) 
> 
> and you can 
> 
> . drop if longest < 4 
> 
> 
> Nick 
> n.j.cox@durham.ac.uk 
> 
> Vidya Mahambare
> 
> > For panel data regression, I want to include only those 
> > firms which have
> > observations for at least for four consecutive years out of 
> > ten. I suppose I
> > have to use drop or keep command, but can't figure out how.
> 
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index