Statalist The Stata Listserver


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

Re: st: looping over parallel lists - is there a alternative to "for"?


From   "Ada Ma" <[email protected]>
To   [email protected]
Subject   Re: st: looping over parallel lists - is there a alternative to "for"?
Date   Thu, 16 Mar 2006 13:44:47 +0000

I don't like marmite (don't mind it either).  I kind of think of it as
English miso...  hahaha.

About the "for" and "against" camps - I kind of sit on the fence
because although I almost always use -foreach- and -forval-, every
once in a while I'd slip in a -for- for one-liners.  I believe I'm
very far from fully exploiting the potentials of -forval- and
-foreach- so that could explain my preference.


On 3/16/06, Nick Cox <[email protected]> wrote:
> As has been said, -for- divides the world (like
> Marmite, if you know what that is).
>
> The two camps are, naturally, "for" and "against".
>
> Once you have seen the light on -forvalues- and -foreach-,
> you never want to go back.
>
> Nick
> [email protected]
>
> Ada Ma
>
> > I suppose you can have three globals and then have one loop to loop
> > through them?  Some samples can be found in C Baum's "A little bit of
> > Stata programming goes a long way ..."
> >
> > http://www.stata.com/meeting/11uk/baum.pdf
> >
> > I quite like the -for- command as well, sometimes I only want to loop
> > one line of command and using commands like -forvalue- and -foreach-
> > gets a bit complicated.  And speaking for myself, using -for- would
> > save me from making typos like using ) instead of }.
> >
> >
> >
> > On 3/16/06, Gawrich Stefan <[email protected]> wrote:
> > > Hi,
> > >
> > > I do a lot of routine or repetitive data analysis and use
> > loops and lists
> > > frequently (btw, thx to Nick Cox, his "How to fact lists
> > with fortitude"
> > > helped me a lot).
> > >
> > > I'm wondering why the "for"-command is officialy out of
> > date in Stata while
> > > one of it's best features  - the use of parallel lists -
> > can't be done
> > > otherwise. Or am I missing something?
> > >
> > > One example: I routinely map ten different diseases with
> > tmap and save the
> > > maps as a graphic file.
> > >
> > > for var var1-var10 \ any "Disease1" "Disease2" [...] \ any
> > "Filename1"
> > > "Filename2" [...] : ///
> > > tmap choro X, id(county) map("county-Coordinates.dta")
> > title("Y") \ graph
> > > export "Z.png", replace
> > >
> > > In this example each graph is determined by something like
> > a 3-tuple of
> > > variable, title and saving-filename.
> > > This is just basic code, in real life the code blows up and
> > becomes hard to
> > > read, as we all know, "for" has some disadvantages.
> > > So if it can be done in a more structured manner, I would
> > like to know...
>
> *
> *   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/
>


--
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926

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