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
[email protected]
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/