Bookmark and Share

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: Drop observations of groups with gaps in their data


From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index