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]

Re: st: Syntax forvalues in Stata 11 SE


From   Neil Shephard <[email protected]>
To   [email protected]
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 <[email protected]> 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.

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index