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

Re: st: Limit of numlist

From   Nick Winter <>
Subject   Re: st: Limit of numlist
Date   Thu, 06 Oct 2005 10:39:24 -0400

This doesn't speak to the numlist limit question, but your code could simply use -forvalues- rather than -foreach ... numlist-.

There is no reason to have Stata create and store the numlist, rather than simply iterate through the values from 1 to N.

Your code could be:

forvalues i = 1/`l' {

Or even better,

forvalues i = 1/`=_N' {

That is, you can skip the -count- and just have Stata evaluate the macro expression `=_N'.

--Nick WInter

At 09:56 AM 10/6/2005, you wrote:

I am trying to writre formatted text output from a Stata data file and
wrote a program based on the examples in the Stat manual and the UCLA
Web site (

Some of the code is shown below.  I am getting an error "invalid
numlist has too many elements  r(123)".  I have 17,915 observations.
If I limit my dataset to a smaller number of observations (using drop
or keep) to, say 1,000, or hardwire a smaller number, the program
sucessfully writes out the data.

After searching the documentation I cannot find a limit to the number
stored in numlist.  Is there such a limit?  If so, can it be


*** Stata Code Follows ***
  quietly count;
  local l = r(N);
  foreach i of numlist 1/`l'{;
    file write temp
     _col(1)  %5.0f  (frm_id1[`i'])
     _col(8)  %5.0f  (co_id1[`i'])
     _col(14) %9.1f  (est_rnd_amt_fund[`i'])

*   For searches and help try:
Nicholas J. G. Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government e
Cornell University w
308 White Hall
Ithaca, NY 14853-4601

* For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index