Bookmark and Share

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

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

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

From   daniel klein <>
Subject   Re: st: Too many macros, but I create 1!
Date   Thu, 6 Dec 2012 09:45:42 +0100


first, I find it hard to imagine where you are going with this code. I
also do not understand (a) why you have this loop, and (b) why you
write a Stata program, when you only use Mata code.

Let me rewrite the code

m : 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 have a program that drops into mata, generates a row vector, converts it to
strings and then sends to stata as a macro. The macro it generates is about
400,000 characters long, with about 62,000 individual entries, well within the
limits of stata-12 mp 8 core edition. Here is some test code that shows what
is going on and mimics the attributes of my data.

program test_case, rclass
    mata {
        indexes = 50000
        for (i=1; i<=61611; i++) {
            indexes = indexes, i+indexes[1]
        indexes = strofreal(indexes)
        indexes = invtokens(indexes)
        st_local("indexes", indexes)
    return local indexes `indexes'

And when I run it:

. test_case
too many macros
*   For searches and help try:

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