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

st: RE: loops


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: loops
Date   Wed, 20 Apr 2005 10:47:35 +0100

For a problem posed this generally, 
I have two very general comments. 

1. It is often a good idea 
to do the selection before the loop, 
not within it. The stuff documented
at -help macrolists- can help a lot 
to cut out the irrelevant items.  

2. 

foreach x in <list> { 
	if <x is acceptable> { 
		...
	}
} 

is sufficient but not always ideal. 

Given specific examples, I might 
be able to say more. 

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

Hans J. Baumgartner
 
> I am working on a huge project using loops over loops over loops. 
> 
> Now it happens that I would like to exclude some elements of 
> the loops, 
> i.e.:
> 
> foreach x in ? {
>                 if ?`x?? == ? {
>                         jump do the end of the loop, i.e. ignore all 
> commands till then.
>                 }
>                 some fancy commands
> }
> 

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