Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: foreach syntax


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Re: foreach syntax
Date   Wed, 21 Feb 2007 13:43:56 +0000 (GMT)

--- Paul Fenner [mailto:[email protected]] wrote:
> The following works in Stata9:
> local x = "lr1-ul6"
> foreach i of local x{
> 	su `i'
> }
> but
> local x = "lr1-ul6"
> foreach i of local x{
> 	ttest `i',by(gender)
> }
>
> with error r(103) too many variables specified.
 
In this case Stata will loop over the different 
elements in the local x. The local x contains one 
element: lr1-ul6, so the loop will go through only 
one iteration and the local i will in that 
iteration contain lr1-ul6. So in the first loop the 
first and only iteration will read -su lr1-ul6-, 
which is legal Stata syntax, and in the second loop 
the first and only iteration will read 
-ttest lr1-ul6, by(gender)-, which is illegal Stata 
syntax since you specified too many variables as 
the error message showed. What you probably want is 
the following:

local x = "lr1-ul6"
su `i'

foreach i of varlist `x'{
ttest `i',by(gender)
}

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------
 



		
___________________________________________________________ 
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index