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

st: RE: RE: problem with numlist in forvalues


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: problem with numlist in forvalues
Date   Fri, 11 Mar 2005 16:55:18 -0000

To expand on this point:

The syntax of -forvalues- depends on an idiosyncratic 
idea of a _range_: 

        forvalues lname = range {
                commands referring to `lname'
        }

    where range is

                       #1(#d)#2      meaning #1 to #2 in steps of #d     
                       #1/#2         meaning #1 to #2 in steps of 1      
                       #1 #t to #2   meaning #1 to #2 in steps of #t - #1
                       #1 #t :  #2   meaning #1 to #2 in steps of #t - #1

If -forvalues- accepted arbitrary numlists, it would no longer
have a separate rationale. Its rationale is that the range 
can be computed on the fly: it is not stored as the equivalent 
numlist, thus allowing an edge in speed on -foreach-. For 
some applications, e.g. when looping over many observations 
is unavoidable, this can be very important. 

Nick 
[email protected] 

Nick Cox
 
> -forval- does not accept all possible numlists. 
> 
> The documentation doesn't claim this and 
> it doesn't do it anyway. 
> 
> The limit is thus not the issue. You 
> need to use -foreach-. 
 
Daniel Mueller
  
> > I have a longer -numlist- to process with -forvalues-. I 
> > can't see why the following does not work:
> > 
> > forval n = 100(100)1000 1000(500)5000 5000(1000)10000 
> > 10000(5000)50000 50000(10000)100000 {
> > invalid syntax
> > r(198);
> > 
> > -whelp limits- says the limit of a -numlist- is 1,600. I 
> > have 36 above. And the actual list in my example is even 
> > longer than that.

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