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

st: identifying lengths of runs in a binary variable


From   Faye Turner <Faye.Turner@cancer.org.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: identifying lengths of runs in a binary variable
Date   Mon, 18 Apr 2005 11:00:15 +0100

I have a binary variable (coded with 0's and 1's).

I would like to generate a variable that records the frequency of consecutive 1's.

A new run of 1's would begin after a zero.

E.g

binvar newvar
1 3
1 3
1 3
0
0
1 4
1 4
1 4
1 4
0

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