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]

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


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Neil Shephard
Gesendet: Donnerstag, 23. September 2010 14:45
An: statalist@hsphsun2.harvard.edu
Betreff: Re: AW: st: AW: Syntax forvalues in Stata 11 SE

On Thu, Sep 23, 2010 at 12:36 PM, Gauri Khanna <gwkhanna@hotmail.com> 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 - nshephard@gmail.com
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index