Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Re: creating a "years since event" variable in panel data


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Re: creating a "years since event" variable in panel data
Date   Thu, 8 Mar 2007 16:18:01 -0500

Christer Thrane --
Note that the correspondence between year and time is suspect in your
example data (year has 9 values and time 8--is there a missing year?).
You may also wish to consider a variable tracking time to first
observed change from 0 to 1, including negative time.  Whatever you
do, anyone with all 1s or all 0s (or a series of 1s followed by all
0s) will have a missing elapsed time variable...

clear
range id 1 10 10
expand 9
bys id: gen year=1993+_n
g time=y-1994
set seed 7777
gen event=uniform()>.8
bys id (t): gen obs=_n if (sum(e==1 & e[_n-1]==0)>0)
egen fobs=min(obs), by(id)
bys id (t): g elaps=_n-fobs
li in -28/-9, sepby(id) noo

You might then think about what it means to observe more than one
event, if such a thing happens. The above code also works if event is
coded as "ever had an event" (i.e. it is an absorbing state) but will
not solve the censoring problems.

clear
range id 1 10 10
expand 9
bys id: gen year=1993+_n
g time=y-1994
set seed 7777
gen event=uniform()>.8
bys id (t): replace event=(sum(event)>0)
bys id (t): gen obs=_n if (sum(e==1 & e[_n-1]==0)>0)
egen fobs=min(obs), by(id)
bys id (t): g elaps=_n-fobs
li in -28/-9, sepby(id) noo

See also -ssc desc tsspell-

On 3/8/07, Christer Thrane <lineea@broadpark.no> wrote:
Thanks! I think I understand it. Does this also hold for the following data
structure?
Q: How do I create the variable NUMBER OF YEARS SINCE (A POSSIBLE) CHANGE
>> FROM 0 to 1 on EVENT?
*
*   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