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 on April 23, and its replacement, is already up and running.

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

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

From   Neil Shephard <>
Subject   Re: AW: st: AW: Syntax forvalues in Stata 11 SE
Date   Thu, 23 Sep 2010 12:44:47 +0000

On Thu, Sep 23, 2010 at 12:36 PM, Gauri Khanna <> 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

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'


"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 -
Website -
Photos -

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index