Hi All:
I have a unbalanced panel data set with monthly observations. The panel id is: dispno2 and the time id is: date (formatted %tm). The variable of interest is called: stale. It is a dummy variable (0/1) that measures stalemates in negotiations. I would like to generate a running sum, but with two conditions. First, the sum restarts after stale is 0 and the sum only counts consecutive stalemates in the past 60 months.
More clearly, I would like to generate a variable that counts the consecutive number of stalemates (stale=1) in the past five years.
Similar questions have been discussed at length on the Statalist, but I haven't been able to figure it out. Based on the thread at (http://www.stata.com/statalist/archive/2007-07/msg00602.html) I was able to use the user written tool tsspell to solve the problem of restarting after every zero (or missing value based on the thread), but I can't quite figure out how to create a five year running sum within each spell. My completely copied code is below. Any help would be greatly appreciated. Thank you very much!
tsset dispno2 date
tsspell, cond(!missing(stale))
Or,
gen stalecon=.
bysort dispno2 (date): replace stalecon=cond(missing(stale[_n-1]), stale, stale+stalecon[_n-1])
*replaced stale=0 with missing to follow code on Statalist
Benjamin Appel
Ph.D. Student, GVPT at UMD
*
* 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/