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]
st: using MATA FOOBAR with LOOPs
From
Jason Park <[email protected]>
To
[email protected]
Subject
st: using MATA FOOBAR with LOOPs
Date
Mon, 9 Dec 2013 02:31:16 +0800
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/