Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: RE: foreach command

From   Phil Clayton <>
Subject   Re: st: RE: foreach command
Date   Thu, 13 Dec 2012 11:40:06 +1100

Hi Megan,

Rather than using:
foreach 'var'
You should use:
foreach var

When you first create a local macro you shouldn't use the single quotes - these are only used when you want to replace the macro name with its contents.

Furthermore, when you reference it later the first quote needs to be a left quote: ` rather than '

If you just want to -summarize- four variables you don't need a loop - -summarize- accepts a varlist. Therefore you can just use:
summarize total_IS_0 free_IS_0 total_PCS_0 free_PCS_0

I don't understand your question about drop down selections - are you talking about using a dialog box? If you want to include a bunch of variable names in a command you can just double-click on them in the variables window, or if they're sequential in the dataset you can use a hyphen. See -help varlist-

Finally, when asking a new question please start a new thread rather than replying to an old one - see section 2.2 of the Statalist FAQ.


On 13/12/2012, at 11:26 AM, megan rossi <> wrote:

> Hi all,
> I am trying to use the loop function on a set of pre -existing variables 
> variable 1) total_IS_0
> variable 2) free_IS_0 
> Variable 3) total_PCS_0 
> Variable 4) free_PCS_0 
> My syntax is....
> foreach 'var' of varlist total_IS_0 free_IS_0 total_PCS_0 free_PCS_0 {
> summarize 'var'
> }
> I have stat 12 and it is coming up with r 198 invalid name... I am not sure what is wrong with my syntax? Also is there a way to incorporate this loop function with the drop down selections option or is it only avaliable with manual entry?
> Cheers,
> PhD Candidate School of Medicine, University of Queensland
> Accredited Practicing Dietitian
> Princess Alexandra Hospital Nutrition & Dietetic Department
> m: 0402 931 441 | e:
> "Let food be thy medicine and medicine be thy food." — Hippocrates (ca. 460 – 377 BC)
> ********************************************************************************
> This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.
> Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.
> **********************************************************************************
> ----------------------------------------
>> Date: Wed, 12 Dec 2012 18:25:34 -0500
>> Subject: Re: st: fixed effects quantile regression
>> From:
>> To:
>> On Wed, Dec 12, 2012 at 2:49 PM, Austin Nichols <> wrote:
>>> JVerkuilen (Gmail) <>:
>>> -suest- does not work with -qreg-.
>> :(
>>> Lisa Marie Yarnell <>:
>>> On -qreg- with FE, there are many different forms, all interpreted differently.
>>> See e.g.
>>> for a good review of how people have tackled it.
>> That's a nice reference, thanks.
>> Jay
>> *
>> * For searches and help try:
>> *
>> *
>> * 		 	   		  
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

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