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

st: RE: Creating a time from event variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Creating a time from event variable
Date   Wed, 9 Jul 2003 17:28:14 +0100

Landman, Todd
 
> I have two separate questions:
> 
> (1) I have a treaty ratification variable that is coded as 
> follows for the period 1976-2000:
> 
> 0 = no signature
> 1 = signature
> 2 = ratification
> 
> How would I create a new variable that sums the years since 
> full ratification, i.e. the total number of years from when 
> the variable assumes a value of 2.

I guess that your data look like this: 

treaty  year  ratification 
======  ====  ============
A       1976     0 
A       1977     1 
...
A       1986     2 
... 
A       2000     2 
B       1976     0 

etc. 

Here is one way. 

gen year1 = year if rat == 2 
egen year2 = min(year1), by(treaty) 
gen year3 = year - year2 

Another approach is to use -tsspell- 
from SSC. 

tsset treaty year 
tsspell, fcond(rat == 2)

The variables created automatically 
include _seq, which should be close
to what you what (subtract 1?). 

Nick 
n.j.cox@durham.ac.uk 
*
*   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