Bookmark and Share

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]

Re: st: spell variable according to a criteria


From   Abhimanyu Arora <[email protected]>
To   [email protected]
Subject   Re: st: spell variable according to a criteria
Date   Wed, 4 Apr 2012 18:06:30 +0200

Hi statalist
I think I managed.

So in the line
bys panel_identifier:replace event=1 if  stretch[_n-(`i'+1)]>`i' &
stretch[_n-(`i'+1)]!=. & event==.

I changed to

bys panel_identifier:replace event=1 if  stretch[_n-`=`i'+1']>`i' &
stretch[_n-`=`i'+1']!=. & event==.

in order to evaluate the local macro at every loop.

Best regards
Abhimanyu



On Wed, Apr 4, 2012 at 5:40 PM, Abhimanyu Arora
<[email protected]> wrote:
> 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/

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index