Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Too many macros, but I create 1!


From   "William Gould, StataCorp LP" <[email protected]>
To   [email protected]
Subject   Re: st: Too many macros, but I create 1!
Date   Thu, 06 Dec 2012 10:08:21 -0600

James Sams <[email protected]> tried to create long macros -- about
400,000 characters long -- using a combination of Mata and Stata and
ran into difficulty.

James is using Stata MP/8 12.

Daniel Klein <[email protected]> replied, solving part of the 
problem (I think).  He wrote: 

> Let me rewrite the code
>
>       . mata: st_global("indexes", ///
>               invtokens(strofreal(indexes = J(1, 1, (50000..111611)))))
>
> (you could add a -st_rcclear()-)
> 
> Here the problem does not occur (though the contents are truncated
> at 165000+ characters, as I am running Stata IC). I suspect your
> problem has something to do with the maximum length of characters
> allowed in a (local) macro. Others might shed more light on the
> topic.

I can help. 

The current maximum length of macros can be obtained from c(macrolen):

	. display c(macrolen)
	165200

I am running Stata/SE, but I would have seen the same result had I been 
running Stata/IC or Stata/MP.

However, in Stata/SE and STata/MP, maxvar is setable, and the maximum 
macro length is a function of maxvar.

For instance, if I were to type 

	. set maxvar 12116 

	. display c(macrolen)
	400028

Setting maxvar to 12116 would allow James to create macros containing 
up to 400,028 characters. 

For Stata/SE and Stata/SE, macrolen is given by the formula 

	macrolen = 33*maxvar + 200

For Stata/SE and Stata/MP, maxvar defaults to 5,000 and, using -set maxvar-, 
you can set it to any number in the range 2,048 to 32,767:

	macrolen = 33* 2,048 + 200 =    67,784   (minimum)
	           33* 5,000 + 200 =   165,200   (default)
                   33*32,767 + 200 = 1,081,511   (maximum)


The reason macrolen is linked to maxvr is that macros are commonly used 
to hold Stata variable names, and thus need to be able to hold all the 
variable names that could appear in the dataset.  Variable names are 
32 characters long, they will have space between them, and then some 
extra was added. 

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index