Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Quick forvalues question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Quick forvalues question
Date   Wed, 19 Jan 2005 23:48:27 -0000

I've a quick answer: No. 

You should use -foreach-. 

foreach x of numlist 10(2)20 30 40(1)50 { 
	...
}

The syntax of -forvalues- is restricted
to a range, precisely as defined in the 
help. This is much more restricted than 
a numlist. 

There was a tutorial on -foreach- and -forvalues- 
in Stata Journal 2(2): 202-222 (2002) [although 
Executive Editor of the SJ at the time 
I did not contrive this bizarre bibliographic 
detail]. 

An earlier version of that tutorial also exists 
as slides for a talk on the internet in at least two places. 

Nick 
[email protected] 

Yvonne Capstick
 
> I've a quick and embarrassingly simple question on forvalues.
> 
> I know that you can type forvalues x = 10/20 to get 10, 11, ... 20
> and you can type forvalues x = 10(2)20 to get 10, 12, 14, ... 20
> 
> However, can I combine the two? I would like a list 10 12 14 
> 16 18 20 30 40 
> 41 ... 49 50
> 
> and would like to type forvalues x = 10(2)20 30 40/50, but 
> this doesn't 
> work. I know that I can still do what I want to by having 
> three separate 
> 'forvalues' loops, but does anyone know of a way in which I 
> can combine 
> everything into one?

*
*   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