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

st: RE: Generate ongoing variable from onset variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Generate ongoing variable from onset variable
Date   Fri, 13 Jan 2006 18:24:26 -0000

There may be a better way, but this appears to work. 

You have evidently -tsset- the data. 

What we can do is count downwards by subtracting one 
from the previous length. A spell of length 3 means
that the values will go down 3, 2, 1. When we 
drop below 1 the spell has ended. 

As there is no value before the first, that needs 
to be trapped as a special case. 

gen ongoing = length 
replace ongoing = L.ongoing - 1 if length == 0 & L.ongoing < . 
replace ongoing = ongoing >= 1 

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

Drury, A. Cooper
 
> I am working with a times-series cross-section data set where the unit
> of analysis is the country-pair/year.  The data include a dichotomous
> variable indicated when a new policy was initiated.  I also have a
> variable that indicates of the duration of that policy (measured in
> years).  I need to create a variable that indicates when the 
> policy was
> in effect.  For example, one cross-section my look like this:
> 
> Policy         Policy     Policy
> Initiation     length     ongoing (new variable)
>    0             0           0
>    1             3           1
>    0             0           1
>    0             0           1
>    0             0           0
>    1             2           1
>    0             0           1
>    0             0           0
> 
> I need to create the "policy ongoing" variable.
> 
> I have tried generating a new variable, and then typing:
> replace newvariable=L.newvariable+(policylength-1)+policyinitiation
> 
> This should work, but Stata tells me: (593368 real changes 
> made, 593368
> to missing); so all the values are replaced by missing values.
> 
> I am really stumped here, any help would be greatly appreciate.
 

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