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: st: Syntax forvalues in Stata 11 SE

From   Neil Shephard <>
Subject   Re: st: Syntax forvalues in Stata 11 SE
Date   Thu, 23 Sep 2010 11:58:52 +0000

On Thu, Sep 23, 2010 at 11:52 AM, Gauri Khanna <> wrote:
> Hi,
> I am a new user to the Stata 11.1 SE
> I have run into syntax problems with the - forvalues- command while creating a loop.
> My syntax which comes from Stata 9 is the following:
> forvalues svy = 1/`max1' {
>     use "'allsvys'", clear
>     keep if i==`svy'
> }
> and I get the following error :
> invalid syntax
> r(198);

What is the value of `max1' and how are you setting it prior to your loop?

You can use -set trace on- to look at how your -forval- line is
actually being interpreted.

> Subsequently, i would also like to run the following syntax (shortened for convenience)
> foreach x of local names {
>         if "`x'"=="lgsmkc" {
>             display "`x'"
>             gen row`j'=lgcigc
>             local j=`j'+1
>         }
> }
> Can anyone help?

What are you trying to achieve here, its not clear to me?

It looks like you'll create variables row1 to row[n] that will all be
identical to the variable 'lgcigc' which doesn't seem like a useful
thing to do.


"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