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   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: looping over parallel lists - is there a alternative to "for"?
Date   Thu, 16 Mar 2006 18:13:59 -0000

I don't particularly yearn for that, nor I do argue 
against. 

But what you can do now -- and indeed for some time past -- is
not far away: 

foreach element of loc mylist {
 	tokenize `element'
	args numeral letter roman 
 	...
}

If there was a lot in the loop this would make 
code clearer. 

Nick 
n.j.cox@durham.ac.uk 

Phil Schumm
 
> On Mar 16, 2006, at 11:44 AM, Nick Cox wrote:
> > Also, you could -tokenize- inside the loop:
> >
> > foreach element of loc nylist {
> > 	tokenize `element'
> > 	...
> > }
> 
> 
> Indeed, this would make for much cleaner code within the 
> loop, albeit  
> still a bit difficult to read (since one has to go back and forth  
> between the positional macros and what they refer to).  For this  
> reason, I still think it would be nifty if you could write:
> 
> 
> loc mylist `" "1 a I" "2 b III" "3 c III" "'
> foreach numeral, letter, roman of loc mylist {
>      ...
> }
> 
> 
> but, as I said, I haven't thought through the full implications of  
> this, nor do I have any idea how difficult it would be to 
> implement.   
> I also have no idea whether it would offend StataCorp from an  
> aesthetic perspective...

*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index