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: Event time creation
From 
 
Nick Cox <[email protected]> 
To 
 
"[email protected]" <[email protected]> 
Subject 
 
Re: st: Event time creation 
Date 
 
Fri, 19 Apr 2013 09:15:33 +0100 
egen benchmark  = total(time / (event == "Yes"))
gen eventtime = time - benchmark
expand 2
There could be all sorts of complications you have not told us about.
For example: These are really panel data.
egen benchmark  = total(time / (event == "Yes"))  , by(id)
For example: The -event- variable is really 0-1 and we are just seeing
value labels.
egen benchmark  = total(time / (event == 1))  , by(id)
See also
http://stackoverflow.com/questions/15298526/determine-time-period-since-event-up-to-n-leads-lags
http://www.stata-journal.com/article.html?article=dm0055
Nick
[email protected]
On 19 April 2013 03:00, Auh, Jun Kyung <[email protected]> wrote:
> I am wondering how I can create the event time variable. For example I want to create something like this:
>
> Time            Event   EventTime
> 2000m1          No      -2
> 2000m2          No      -1
> 2000m3          Yes     0
> 2000m4          No      1
> 2000m5          No      2
>
> Furthermore, what I actually want to create is the following:
>
> Time         ID Event   EventTime
> 2000m1          No      -2
> 2000m1          No      -2
> 2000m2          No      -1
> 2000m2          No      -1
> 2000m3          Yes     0
> 2000m3          Yes     0
> 2000m4          No      1
> 2000m4          No      1
> 2000m5          No      2
> 2000m5          No      2
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/