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

st: RE: generating sums


From   "Frank de Libero" <frank@data2information.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: generating sums
Date   Sat, 17 Aug 2002 15:26:01 -0700

Rich's message:
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

Does anyone have a suggestion?

-------------------------------------
This should do it:
gen z = cond(x==1 & _n~=1,x[_n]+x[_n-1],x)
gen z2 = cond(y==1 & _n~=1,y[_n]+y[_n-1],y)
FYI, on the 12th there was a message forwarded to the List by Kit Baum that
was similar in kind to this solution.
Ciao..Frank



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