Bookmark and Share

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]

st: Drop observations of groups with gaps in their data


From   Christopher Baum <kit.baum@bc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Drop observations of groups with gaps in their data
Date   Fri, 3 Jun 2011 05:37:48 -0400

gvkey            year
1001            1985
1001            1986
1001            1987
1001            1990
1001            1991
1200            1986
1200            1987
1200            1988
1200            1989


I want to drop all the firms that have a gap in reporting (gvkey = firm code). This means that all firms which e.g. reported from 1985 to 1987 and then again from 1990 to 1991 have to be dropped. Those companies should completely be eliminated from the data set, meaning stata should drop all observations of this company. So in the end I am left with the companies that do not have any gaps in reporting.


How about

bys gvkey: g dy = cond(_n==1, 1, year[_n]-year[_n-1])
egen tokill = max(dy), by(gvkey)
drop if tokill > 1

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index