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

st: generating sums


From   baum <baum@bc.edu>
To   StataList <statalist@hsphsun2.harvard.edu>
Subject   st: generating sums
Date   Sat, 17 Aug 2002 21:55:13 -0400

Rich asked

I have a data that looks like this:

_obs_  _x_ _y_
 1      1   0
 2      1   0
 3      0   1
 4      0   1
 5      1   0
 6      0   1
 7      0   1

I want to generate a 'streak' variable that will make the data look like
this:

_obs_  _x_ _y_ _z_ _z2_
 1      1   0   1   0
 2      1   0   2   0
 3      0   1   0   1
 4      0   1   0   2
 5      1   0   1   0
 6      0   1   0   1
 7      0   1   0   2

The recently described tsspell will do just that, since its 'seq' counts the length of a spell, i.e. a winning streak:

list
g t=_n
tsset t
tsspell, c(x>0) seq(z)
drop _*
tsspell, c(y>0) seq(z2)
drop _*
list



ssc install tsspell

Kit

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