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

st: Re: for vs foreach and forvalues


From   baum <[email protected]>
To   [email protected]
Subject   st: Re: for vs foreach and forvalues
Date   Thu, 25 Jul 2002 08:39:23 -0400

--On Thursday, July 25, 2002 2:33 -0400 Nick wrote:

3. The syntax of -for- is idiosyncratic. Much of what you
learn is not transferable to other Stata commands, and vice
versa. The "arbitrary syntax" of \ as separator is awkward
(and confusing whenever that is needed for other meanings).
In contrast, -foreach- and -forvalues- are much closer
to the mainstream of Stata thinking and style. This is
equally important, albeit for slightly different reasons,
to those learning Stata and/or using it only occasionally
and to more advanced or more intensive users.
The other point that must be made is that Stata users do not exist in a vacuum; many may use other programming languages or packages which have their own programming language ('matrix' languages such as MATLAB, Ox, GAUSS). Most programming languages in common use today have a loop construct that resembles foreach and/or forvalues, with a bracketed expression containing one or more commands to be repeated. Experience in using these constructs carries over from experience in other contexts, and vice versa. This is important for users who are trying to say coherent things in multiple environments, as many of us are. The structure of -for- is quite idiosyncratic to Stata, and 'for' that reason I find it less useful (to say nothing of the wailing and gnashing of teeth that accompany trying to use it for a nested loop!)

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