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

RE: Re: st: Keep longest consecutive streak in panels


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: Re: st: Keep longest consecutive streak in panels
Date   Thu, 13 Jan 2005 22:34:38 -0000

I would try -tsspell- from SSC. 

Assuming 

. tsset firm time 


then get the spells 

. tsspell, fcond(L.time == .) 

get the lengths  

. egen length = max(_seq), by(firm _spell) 

keep the longest 

. bysort firm (length time) : keep if _spell == _spell[_N] 

[not tested] 

Nick 
[email protected] 


LACHENMAIER

>  thanks for the quick answer. I have not found the problem in the
> Statalist Archive yet. But I will have a closer look then. To your
> question: In the case of two streaks of equal length I would want to
> keep the newer one. I think this could be done in a second step.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index