Statalist The Stata Listserver


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

Re: st: RE: forvalues gives "numlist has too many elements" error


From   Pablo Mitnik <pmitnik@ssc.wisc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: forvalues gives "numlist has too many elements" error
Date   Tue, 07 Mar 2006 12:00:09 -0600

Problem solved. It was not as I explained it at first. The problem was with foreach. When I replaced it by forval, I still got the same message error, but it was
because there was another foreach further down in the code, which I had forgotten about.

Thanks much Nick for pointing me towards what the real problem was (and for the suggestion re nullmat).
Pablo.


Nick Cox wrote:

I can't reproduce this as a problem with -forval-.
Much of the point of -forval- is that it doesn't construct a numlist. (By the way, it will not accept numlists in general.) If it did, there would be no rationale for it as a separate command. Rather, it constructs its counter on the fly, so enabling speed and storage gains over the equivalent -foreach-.
On a separate detail, using -nullmat()- would enable
you to remove the -if/else- branch.
How are you assigning to local macro 1?
Nick n.j.cox@durham.ac.uk
Pablo Mitnik

The code below worked fine, until I tried it with `1'==10000 (`1' refers to the number of repetitions in a simulation).
When I did this, I received the following error message:

"invalid numlist has too many elements
r(123);"

The help info on r(123) didn't help me -- it refers you to [U] 11.1.8 numlist, but I didn't find anything
useful for my problem there.

Any thoughts? Is there a workaround this issue?

-----------code begins--------------
foreach posed in o2 o3 o4 b2 b3 b4 {

forvalues rep = 1/`1' {
if (`rep'==1) {
mat MR`posed'=(mr`posed'_`rep')
}
else {
mat MR`posed'=(MR`posed' \ mr`posed'_`rep')
}
}
}
-------------- code ends-------------------

*
* 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/
--
Pablo A. Mitnik
University of Wisconsin-Madison (http://www.wisc.edu/ )
Department of Sociology ( http://www.ssc.wisc.edu/soc/)
Center on Wisconsin Strategy (http://www.cows.org/ )
1180 Observatory Drive
Room 7114A
Madison, WI 53706
TEL (608) 2621839
E-mail: pmitnik@ssc.wisc.edu
*
* 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