Bookmark and Share

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: Measuring Relative Time (wrt an Event)


From   Austin Nichols <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Measuring Relative Time (wrt an Event)
Date   Fri, 20 Sep 2013 14:50:40 -0400

Dana Shills <[email protected]>:

egen check=sum(Event), by(Panel)
assert check==1
egen eyr=max(Year*Event), by(Panel)
g RelTime=Year-eyr

On Fri, Sep 20, 2013 at 2:43 PM, Dana Shills <[email protected]> wrote:
> I have an unbalanced panel dataset and I want a variable that shows the time to an event happening. Here is how the data looks. Is there a neat way of creating the "Relative Time" variable without a huge code?
>
> Panel ID  Year  Event  RelativeTime
> A         1996   0     t-4
> A         1998   0     t-2
> A         1999   0     t-1
> A         2000   1     t
> A         2004   0     t+4
> A         2005   0     t+5
>
> B         1999   0     t-6
> B         2000   0     t-5
> B         2001   0     t-4
> B         2003   0     t-2
> B         2005   1     t
> B         2006   0     t+1
>
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index