Hi, I have a Mata function that creates a column vector (called yd below), passes it to Stata as a tempvar, and then calls a Stata package using said tempvar. (If you're curious, this is for instrumental variable quantile regression, as suggested by Chernozhukov and Hansen (2008) "Instrumental variable quantile regression: A robust inference approach" J. of Econometrics.)
I get the following error: "st_store(): 3200 conformability error", which I understand means that Mata is passing a vector of the incorrect size.
However, I can get this code snippet to run just fine outside of the Mata function:
It seems the error has to do with the selectvar within st_store() because I can get the entire routine to work if I first "keep if selectvar==1". For example, this works:
Any advice on what I may be doing incorrectly? I didn't want to overload with information. I can post the entire code if needed.
Code:
mata: ok=st_local("touse")
void objFun(M,todo,b,crit,s,H)
{
real scalar tau
real matrix y,x,d,z /* structure elements */
string scalar dep,instr,reg,ok,quant
struct ivqregInfo scalar G
real matrix yd,beta,var
y=moptimize_util_depvar(M,1)
G=moptimize_util_userinfo(M,1)
// new Y
yd=y :- G.d*b'
// pass to Stata
(void) st_addvar("double", newY=st_tempname())
st_store(.,newY,ok, yd)
stata("qui qreg "+newY+" "+G.instr+" "+G.reg+" if "+G.ok+", q("+G.quant+") ")
beta=st_matrix("e(b)")[1,1]
var=st_matrix("e(V)")[1,1]
crit=beta^2/var
}
end
However, I can get this code snippet to run just fine outside of the Mata function:
Code:
mata:
yd=y :- d*100
(void) st_addvar("double", newY=st_tempname())
st_store(.,newY,ok, yd)
stata("mean "+newY+" ")
end
Code:
keep if sex==1
mata: moptimize(M)
mata: moptimize_result_coefs(M)


Comment