How about something like:
gen byte q=int((time-1)/3)+1 * to get quarter number
gen byte qe=q*event * event quarter
sort id
by id : egen qee=sum(qe)
gen int time2=q-qee
-----Original Message-----
From: Metcalfe, Paul [mailto:[email protected]]
Sent: Monday, October 28, 2002 1:31 PM
To: '[email protected]'
Subject: st: generating alternative time variables
Hello
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.
e.g.
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
(time2==.)*((time2[_n+1]==0)|(time2[_n+2]==0)|(time2[_n+3]==0))
by id: replace time2=1 if
(time2==.)*((time2[_n-1]==0)|(time2[_n-2]==0)|(time2[_n-3]==0))
etc...
Please can someone let me know how I can do this? Thanks in advance for any
help anyone can give me.
Paul Metcalfe
*
* 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/