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

st: RE: RE: RE: Creating a time from event variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: Creating a time from event variable
Date   Thu, 10 Jul 2003 11:36:04 +0100

Todd Landman
  
> > 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. 

Nick Cox 

> 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?). 
> 
> The data look as follows:
> 
> Country year treaty
> ======= ==== ======
> A       1976	0
> A       1977	1
> A       1978      1
> .
> .
> .
> A       1985      2
> A       1986      2
> 
> etc.
> 
> So, would the code you specify ... still apply?

Well, you have to change the variable names 
to what you used... 

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