Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: spell variable according to a criteria
From
Abhimanyu Arora <[email protected]>
To
[email protected]
Subject
st: spell variable according to a criteria
Date
Wed, 4 Apr 2012 17:40:02 +0200
Dear statalist
I have a (monthly) time indicator and a variable 'stretch' that
identifies the spell of an event. I need to create a dummy in case the
event took place or not.
Currently event=1 for the start of the event (an missing for the
rest). If stretch==1, event should equal 1 for the next time period.
If stretch =2 event=1 for 2 more time periods (besides the starting
time).
I know that stretch ranges from 1 to 18 (but may not have the values
in between).
When I try without using the following loop (putting in the numbers
manually that is), it seems OK, But with the following loop things
aren't quite right.
local i=0
while `i'< 18 {
bys panel_identifier:replace event=1 if stretch[_n-(`i'+1)]>`i' &
stretch[_n-(`i'+1)]!=. & event==.
sort panel_id time
local ++i
}
Where does the mistake lie?
Cheers
Abhimanyu
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/