Statalist The Stata Listserver


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

RE: st: foreach program


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: foreach program
Date   Fri, 8 Sep 2006 16:49:18 +0100

Quite so. There would be little point in -forval- 
if it were not more efficient as -foreach- 
is more general and could loop over anything -forval-
loops over. 

The key difference is that  -foreach- must store 
what it loops over, which could be thousands of things, 
while -forval- can calculate the loop index on the fly. 

Nick 
[email protected] 

Scott Cunningham
 
> This appears to be working.  I'm going to have to really dig into  
> this to figure out why mine did not work, though.  I admit, I don't  
> understand when to use -forval- and -foreach-.  They seem  
> interchangeable, but you identified an efficiency gain for using - 
> forval- here that I need to better understand.  I can study the  
> manuals, though.

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