[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: generating alternative time variables
I need to generate a time2 variable in my panel dataset which corresponds to
quarterly time periods around an "event" which occurs in different months
for each ID. My data looks like the following except for Time2 which I am
unable to generate. The panel is unbalanced so it doesn't have observations
for every month for every ID.
ID Time Event Time2
1 1 . -1
1 2 . -1
1 3 . 0
1 4 1 0
1 5 . 0
1 6 . 1
1 7 . 1
1 8 . 1
1 9 . 2
1 10 . 2
I've tried using explicit subscripting to do this using the following syntax
but Stata cascades the changes all the way rather than changing one
observation like I want it to.
sort id time
by id: gen time2=0 if event!=.
by id: replace time2=0 if (time2[_n-1]==0)|(time2[_n+1]==0)
by id: replace time2=-1 if
by id: replace time2=1 if
Please can someone let me know how I can do this? Thanks in advance for any
help anyone can give me.
* For searches and help try: