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

st: RE: forvalues in Stata 7 - is there a Stata 6 equivalent?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: forvalues in Stata 7 - is there a Stata 6 equivalent?
Date   Wed, 17 Dec 2003 18:08:33 -0000

The short answer is No. -forvalues- was introduced in Stata 7. 

A longer answer is: use -while-. 

forval i = 1/6 { 
	...
} 

as one example can be mapped to 

local i = 1 
while `i' <= 6 { 
	...
	local i = `i' + 1
} 

The key differences are that with -while-, you must 
initialise whatever you use to loop and you must
increment the macro yourself. So -while- imposes
more overhead in interpretation than -forvalues-, 
but often you'd find it hard to see how much. 

Similar comments could be made about decrementing, 
stepping by steps other than 1, etc. 

Some may answer -for-. 

for num 1/6 : <statements referring to X> 

is another way of looping through, and you don't 
need to initialise or increment yourself. However, 
-for- has been abandoned, and there are lots of 
reasons why it is often not a good idea. For one 
take on that, see articles in Stata Journal 
2(2):202--222 (2002) and 3(2):185--202 (2003). 
Notes of a talk based on a draft of the first are
accessible at various places of the web, including 
http://fmwww.bc.edu/RePEc/usug2002/fortitude.pdf

Nick 
[email protected] 

Mark Hanly
> 
> I am running Stata 6 on my pc and trying to adapt some code 
> written for 
> Stata 7 (to which I have access on a network, but which 
> takes an age to run).
> 
> Is there a command (or sequence of commands) in Stata 6 
> which does the same 
> thing as the command 'forvalues' in Stata 7?

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