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   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: Too many macros, but I create 1!
Date   Thu, 6 Dec 2012 09:45:42 +0100

James,

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.

Best
Daniel
-- 
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]
        }
        cols(indexes)
        indexes = strofreal(indexes)
        indexes = invtokens(indexes)
        strlen(indexes)
        st_local("indexes", indexes)
    }
    return local indexes `indexes'
end

And when I run it:


. test_case
  61612
  381283
too many macros
r(920);
*
*   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