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

st: re: keep longest consecutive streak (recently broken by Red Sox)


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: keep longest consecutive streak (recently broken by Red Sox)
Date   Fri, 14 Jan 2005 15:13:37 -0500

Nick said

More instructive in some ways is to
do it from scratch, with no use of user
add-ons. Something like

gen spell = sum(L.time == .)
bysort firm spell : gen length = _N
bysort firm length (time) : keep if spell == spell[_N]

Nice, except that it does not work:

|---------------------------|
358. | 10404 1987 .0511182 |
359. | 10404 2002 .0337511 |
360. | 10404 2003 .0296446 |
|---------------------------|

This firm has the original observations

+---------------------------+
| npermno year ita |
|---------------------------|
358. | 10404 1987 .0511182 |
359. | 10404 1989 .0159272 |
360. | 10404 1990 .0455364 |
361. | 10404 1992 .0097333 |
362. | 10404 1993 .0231792 |
363. | 10404 1995 .0534575 |
364. | 10404 1996 .0622322 |
365. | 10404 2002 .0337511 |
366. | 10404 2003 .0296446 |
+---------------------------+

By coincidence, I have been working during the last 24 hours on an ado-file that does this "keep longest streak", but does it listwise for an entire variable list, as is required by some matrix software (that is, we need to generate the longest streak for which NONE of these variables are missing). It also deals with the case, as above, where the longest streak is tied; as an earlier posting suggests, the latest streak should be retained (which is what my code does). I'm pretty sure that it works, but I have given it to Nick to see if he can break it.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* 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