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]

AW: AW: st: AW: Syntax forvalues in Stata 11 SE


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: AW: st: AW: Syntax forvalues in Stata 11 SE
Date   Thu, 23 Sep 2010 14:58:25 +0200

<> 


It is vital that Gauri run the do-file in one piece so that her -local-s
stick around...



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Neil Shephard
Gesendet: Donnerstag, 23. September 2010 14:45
An: [email protected]
Betreff: Re: AW: st: AW: Syntax forvalues in Stata 11 SE

On Thu, Sep 23, 2010 at 12:36 PM, Gauri Khanna <[email protected]> wrote:
> Hi,
>
>
> Here is the error with - set trace on -
>
> . set trace on
>
> . forvalues svy = 1/`max1' {
>   2.         use `allsvys', clear
>   3.         keep if i==`svy'
>   4. }
> - forvalues svy = 1/`max1' {
> = forvalues svy = 1/ {
> invalid syntax
> r(198);

There you have, it despite setting the local macro max1 earlier in
your do-file, when it comes to executing the -forval- loop the local
macro is empty, so -forval- can't repeat something from 1 to
"nothing"!

However, you wrote that you have the following....

local max1=r(max)
gen error1=.
gen error2=.
*save `allsvys', replace /*OLD CODE: STATA 9*/
save "'allsvys'", replace

forvalues svy = 1/`max1' {
    use "'allsvys'", clear
    keep if i==`svy'
}


...which suggests that you are setting the local macro before the loop.

I suspect there may be some confusion from your full do-file error to
the shortened version snippet of code you have posted above where max1
is undefined.

So does...

local max1 = 2
forvalues svy = 1/`max1' {
         use `allsvys', clear
         keep if i==`svy'
}

...work?

Neil



-- 
"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email - [email protected]
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/

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