Statalist The Stata Listserver


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

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


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: creating a "years since event" variable in panel data
Date   Fri, 9 Mar 2007 11:48:22 -0000

Note that there is an 

FAQ     . . . . . . . . . . . . . . . First and last occurrences in panel data
         12/05   How can I identify first and last occurrences
                systematically in panel data?
                http://www.stata.com/support/faqs/data/firstoccur.html

In Christer's set-up, the first OBSYEAR in which EVENT first occurred by 
ID is

egen FIRSTYEAR = min(cond(EVENT == 1, OBSYEAR, .)), by(ID) 

after which you can subtract. The trick here is realising that many 
-egen- functions will accept _expressions_ and not just variable names. 
FIRSTYEAR will, naturally, be missing if the EVENT never occurred
to any ID. 

I'd echo Austin in also plugging -tsspell- from SSC. 

Nick 
n.j.cox@durham.ac.uk 

Christer Thrane
 
> I have a annual panel data set (1 obs per year), where ID 
> identifies the 
> person and the variable OBSYEAR the year of observation 
> (1995=1, 1996=2, 
> ..., 2002=7).
> 
> The variable TIME is the time dimension, ranging from 0 to 7.
> 
> The variable EVENT is a dymmy (1=event happened during the 
> year in question; 
> 0=event did not happen during the year in question).
> 
> 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