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

st: RE: identifying lengths of runs in a binary variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: identifying lengths of runs in a binary variable
Date   Mon, 18 Apr 2005 11:10:42 +0100

Presumably your order of observations 
is meaningful, most likely a time 
order. 

One approach is to -tsset- your 
data and then apply -tsspell- from 
SSC. 

. ssc type tsspell.hlp 

gives more information, including 
a worked example for this very problem. 

Nick 
n.j.cox@durham.ac.uk 

Faye Turner
 
> 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