Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: generating alternative time variables


From   "Metcalfe, Paul" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: generating alternative time variables
Date   Mon, 28 Oct 2002 18:30:58 -0000

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index