Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Locals and Mata Script execution


From   Bruno Boynard <bboynard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Locals and Mata Script execution
Date   Mon, 3 Sep 2012 14:12:11 -0300

Really Thanks Nick,

It works just fine. I was having headaches with this for some time.

Bruno

2012/9/3 Nick Cox <njcoxstata@gmail.com>:
> Also
>
> http://www.stata.com/statalist/archive/2011-01/msg00876.html
>
> In other words, your -st_matrix()- call each time round a loop can be
> something like
>
> st_matrix("stub" + strofreal(i), whatever)
>
> On Mon, Sep 3, 2012 at 5:29 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> Don't try to do this. It's probably not impossible, but it is a small
>> nightmare. Have a look at
>>
>> SJ-11-2 pr0052  . . . . Stata tip 100: Mata and the case of the missing macros
>>         . . . . . . . . . . . . . . . . . . . . . . . . W. Gould and N. J. Cox
>>         Q2/11   SJ 11(2):323--324                                (no commands)
>>         tip showing how to do the equivalent of Stata's macro
>>         substitution in Mata
>>
>> Nick
>>
>> On Mon, Sep 3, 2012 at 5:07 PM, Bruno Boynard <bboynard@gmail.com> wrote:
>>> I'm having trouble using Stata locals to run MATA scripts. I tried to
>>> use the same code in different versions of Stata.
>>>
>>> The issue is that I want to create a series of numbered matrix like
>>> M1, M2, ... Mn. For that, I'm creating a counter in a loop and using
>>> this counter for numbering the matrix. Finally I'm using a Stata local
>>> in order to execute a MATA script.
>>>
>>> Below is the final code (I've tried rewriting the code in different
>>> ways but always with problems):
>>>
>>> mata
>>>
>>> s_total=10000
>>> cR=55*s_total
>>> lX=trunc(s_total/8000)+1
>>> lZ=trunc(cR/8000)+1
>>> i
>>> for(i=1;i<=lX;i++) {
>>>     c=i
>>>     st_matrix("c",c)
>>>     stata("local x=c[1,1]")
>>>     stata("local M J(8000,5,0)")
>>>     stata("local Z M`x'=`M'")
>>>     `Z'
>>> }
>>>
>>> end
>>>
>>> The main objective here is that I'd like to transfer a big Matrix (lX
>>> lines in this point of the code and lZ in another) generated in Mata
>>> to Stata database. To do that, I will split this Matrix in many others
>>> and than export using a st_matrix in each one. I'm not using a st_view
>>> because I'm generating matrix in MATA using different data bases and
>>> the result is completely different from the original databases.
>>>
>>> Thanks in advance,
>>>
>>> Bruno
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/statalist/faq
>>> *   http://www.ats.ucla.edu/stat/stata/
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index