Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: spell variable according to a criteria


From   Abhimanyu Arora <abhimanyu.arora1987@gmail.com>
To   statalist@hsphsun2.harvard.edu
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
<abhimanyu.arora1987@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index