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

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

From   Mark Hanly <[email protected]>
To   [email protected]
Subject   Re: st: RE: forvalues in Stata 7 - is there a Stata 6 equivalent?
Date   Wed, 17 Dec 2003 18:22:44 +0000

Thanks Nick for your prompt and informative reply.

I'll try using 'while' to see what it does.


At 18:08 17/12/2003 +0000, you wrote:
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

[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:
Mark Hanly
Research Fellow

ESRC Transport Studies Unit
University College London
London WC1E 6BT
tel +44 (0)20 7679 1584
fax +44 (0)20 7679 1567

*   For searches and help try:

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