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: using MATA FOOBAR with LOOPs


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: using MATA FOOBAR with LOOPs
Date   Sun, 8 Dec 2013 18:50:47 +0000

Your code does not define any -O- before you call Mata. So, Mata
doesn't know what you are referring to. You can't refer in advance to
what doesn't yet exist.

What I think you want to do is pass a string to be used as the name of
the thing you want to create. That would be need to shown as such e.g.
"O" and your Mata would need to expect a string scalar as argument.

That said, your Mata code so far just creates a matrix in Mata. That
does nothing in terms of anything in Stata. It appears that you have
Stata objects and Mata objects, but they are not at all the same.

You could back up and describe the precise problem you want to solve.
It is not at all clear that you need Mata to do it.

It's also a stretch at best and impossible at worst, for Mata to
understand Stata's local macros.

As above, there is no "MATA". It is "Mata".

Nick
[email protected]


On 8 December 2013 18:31, Jason Park <[email protected]> wrote:
> Dear users,
>
> Thanks to one of the previous threads
> (http://www.stata.com/statalist/archive/2011-01/msg00393.html), I've
> come to understand that, in a do file, mata should be moved outside of
> a loop to before the loop so that the loop can call it.
> However, the thread only shows the case where input is a scalar.
> Instead, I want the name of a matrix that mata returns as a result,
> say O, to be the parameter of the mata function. As shown below, the
> mata function I want my loops to call is a matrix presentation of some
> detailed calculation of the outputs of VAR results.
>
> * beginning of the do file
> clear all
> mata
> void foobar(O) {
> L = ("aa"\"bb")
> M = J(2, 1, .)
> M[1,1] = `aa'
> M[2,1] = `bb'
> O = L,M
> }
> end
>
> foreach case in "date<=10" "date>10&date<=20" "date>20" {
> ma drop aa
> ma drop bb
> local aa = 0
> local bb = 0
>  forvalues i = 1/10
>  var a b if id == `i' & `case', lags(1/2)
>  ma drop B
>  ma B = e(b)
>  local aa = `aa' + B[1,1]
>  local bb = `bb'+ B[1,6]
>  mata foobar(O)
> }
> * end of the do file
>
> This code returns:
> <istmt>:  3499  O not found
> r(3499);
>
> Could anyone provide some tips?
>
> Thanks in advance,
> J
> *
> *   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/
*
*   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