Hi all,
I have an unbalanced panel data set of firms. For some firms there are
data completely missing for some years. So there are gaps existing at
the beginning, at the end and also somewhere in the middle of the time
frame.
What I want to do now, is to keep only those observations for each firm
which are part of the longest consecutive streak of existing entries.
Example:
Obs Firm year
1 1 1980
2 1 1985
3 1 1986
In this example I only want to keep Observation number 2 and 3 because
they are part of the longest streak (2 consecutive answers) and drop
observation number 1 because it is no part of the longest streak. In
this example it is quite easy to do it "manually", but I have a data set
with 30000 observations distributed over 20 years, so I would be very
happy if someone could help me with an algorithm.
Thanks a lot in advance,
Best
Stefan
*
* 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/