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)
0 Response to st_store() and stata() when using moptimize(): IV qreg
Post a Comment