| ![](/includes/contimages/spacer.gif) |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: Re: Re: Re: creating a "years since event" variable in panel data
From |
Christer Thrane <[email protected]> |
To |
[email protected] |
Subject |
st: Re: Re: Re: Re: creating a "years since event" variable in panel data |
Date |
Thu, 08 Mar 2007 21:47:41 +0100 |
That clarifies it, thanks again! (Time is the same as wave, yes.)
CT
----- Original Message -----
From: "Sergiy Radyakin" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 08, 2007 9:42 PM
Subject: st: Re: Re: Re: creating a "years since event" variable in panel
data
Hi, Christer,
My code does not make use of your "time" variable. I don't know what
"time" means. Is this month?
If "time" really means "wave" (time survey is made, typically numbered
from 1 though), i.e. data collected in 1994 are assigned time=0, in 1995
time=1, etc untill 2002 time=7 then you have nothing to change in the
code.
You can even drop this variable (it is redundant), since you can always
recreate it later with
gen time=year-1994
Note that you will have missings (d=.) until the event occurs for the
first time.
Best regards,
Sergiy Radyakin
----- Original Message -----
From: "Christer Thrane" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 08, 2007 9:12 PM
Subject: st: Re: Re: creating a "years since event" variable in panel data
Thanks! I think I understand it. Does this also hold for the following
data structure?
id year time event
1 1994 0 0
1 1995 1 0
1 1996 2 0
..
1 2002 7 0
----
2 1994 0 0
2 1995 1 0
2 1996 2 1
2 1997 3 1
..
2 2002 7 1
----
3 1994 0 1
3 1995 1 1
3 1996 2 1
..
3 2002 7 1
...
----- Original Message -----
From: "Sergiy Radyakin" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 08, 2007 8:51 PM
Subject: st: Re: creating a "years since event" variable in panel data
Hello Christer,
I assume you have data in the following form:
. l ,sepby(id)
+-------------------+
id year event
-------------------
1. 1 1997 0
2. 1 1998 0
3. 1 1999 1
4. 1 2000 0
5. 1 2001 0
6. 1 2002 1
7. 1 2003 0
8. 1 2004 0
-------------------
9. 2 1997 1
10. 2 1998 1
11. 2 1999 1
12. 2 2000 0
13. 2 2001 0
14. 2 2002 0
15. 2 2003 0
16. 2 2004 0
-------------------
17. 3 1997 0
18. 3 1998 0
19. 3 1999 0
20. 3 2000 0
21. 3 2001 0
22. 3 2002 1
+-------------------+
(Namely, I don't understand what you mean by time ranging from 0 to 7)
Type:
gen d=.
bys id (year): replace d=cond(event==1,0,d[_n-1]+1)
l ,sepby(id)
Which results in the following:
+-----------------------+
id year event d
-----------------------
1. 1 1997 0 .
2. 1 1998 0 .
3. 1 1999 1 0
4. 1 2000 0 1
5. 1 2001 0 2
6. 1 2002 1 0
7. 1 2003 0 1
8. 1 2004 0 2
-----------------------
9. 2 1997 1 0
10. 2 1998 1 0
11. 2 1999 1 0
12. 2 2000 0 1
13. 2 2001 0 2
14. 2 2002 0 3
15. 2 2003 0 4
16. 2 2004 0 5
-----------------------
17. 3 1997 0 .
18. 3 1998 0 .
19. 3 1999 0 .
20. 3 2000 0 .
21. 3 2001 0 .
22. 3 2002 1 0
+-----------------------+
Notice that in this version it is "duration since the most recent
occurance of the event". Alternatively it can be "duration since the
first occurance of the event".
First is reasonable if your event is "got a new job" -- then d is
tenure. Alternatively, if your event is something like "a child is
born", -- then dd might be "duration of life with children" (though no
account is given for possible move-outs). Then one will need to change
the program:
gen dd=.
bys id (year): replace
dd=cond(dd[_n-1]==.,cond(event==1,0,.),dd[_n-1]+1)
+----------------------------+
id year event d dd
----------------------------
1. 1 1997 0 . .
2. 1 1998 0 . .
3. 1 1999 1 0 0
4. 1 2000 0 1 1
5. 1 2001 0 2 2
6. 1 2002 1 0 3
7. 1 2003 0 1 4
8. 1 2004 0 2 5
----------------------------
9. 2 1997 1 0 0
10. 2 1998 1 0 1
11. 2 1999 1 0 2
12. 2 2000 0 1 3
13. 2 2001 0 2 4
14. 2 2002 0 3 5
15. 2 2003 0 4 6
16. 2 2004 0 5 7
----------------------------
17. 3 1997 0 . .
18. 3 1998 0 . .
19. 3 1999 0 . .
20. 3 2000 0 . .
21. 3 2001 0 . .
22. 3 2002 1 0 0
+----------------------------+
Best regards,
Sergiy Radyakin
----- Original Message -----
From: "Christer Thrane" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 08, 2007 7:23 PM
Subject: st: creating a "years since event" variable in panel data
Hi,
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?
Best regards,
Christer Thrane
*
* 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/
*
* 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/
*
* 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/
*
* 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/
*
* 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/