Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: capturing the sizes of the sequences of countinous (uninterrupted) values equal to 1


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: capturing the sizes of the sequences of countinous (uninterrupted) values equal to 1
Date   Wed, 30 Nov 2011 09:36:31 +0000

You can't get this information given your data structure into a single
Stata variable. What you seek is a matrix.

If w <= 244, you could try concatenating your variables into a string
variable holding individuals' history.

But I guess this would be easier after -reshape long-. Then a spell is
defined as a sequence with all 1s for the same id. See then

SJ-7-2  dm0029  . . . . . . . . . . . . . . Speaking Stata: Identifying spells
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q2/07   SJ 7(2):249--265                                 (no commands)
        shows how to handle spells with complete control over
        spell specification

tsspell from http://fmwww.bc.edu/RePEc/bocode/t
    'TSSPELL': module for identification of spells or runs in time series /
    tsspell examines the data, which must be tsset time series, to / identify
    spells or runs, which are contiguous sequences defined / by some
    condition. tsspell generates new variables indicating / distinct spells,

Nick

On Wed, Nov 30, 2011 at 9:24 AM, massimiliano stacchini
<[email protected]> wrote:

> I have a huge dataset. The rows identify the person ID (i) (i=1,...,n) while in columns there are the reference dates TIME(t) (t=1,...,w). Each cells contain the value 1 or 0 (zero), alternatively.
>
> I should create a variable (LENGTH) varying both over ID and TIME.
> For each i of ID(i) in t of TIME(t), LENGTH should captures the number of continuous (uninterrupted) values which are equal to 1 in the interval of cells starting from the reference data t of TIME and moving backwards to the previous reference dates.
> In other terms , LENGTH should capture for each (i) of ID and for each (t) of TIME the number of s in T (t-s) identifying cells having values equal to 1 (i.e., the size of the sequence of uninterrupted 1 moving backwards to the previous reference dates).
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index