This question is in continuation of this, but since it can be answered without knowledge of my previous question, I thought posting a new question was the way to do it (I'm sorry if this is not the case). In the previous question I was told that putting Mata code at the end of my .ado-file would make the local var2
usable within the Stata code. A minimal example is the following:
program define hello
args var1
local sum_var=`var1'+`var2'
disp `sum_var'
end
mata
void cens_func(todo, x, y, g, H)
{
y = (x-1)^2
}
S = optimize_init()
optimize_init_evaluator(S, &cens_func())
optimize_init_which(S, "min")
optimize_init_params(S, 2)
temp=optimize(S)
st_local("var2",strofreal(temp))
end
which unfortunately does not run. I am getting an invalid syntax error. Running this in a .do-file with the Mata code first, causes no errors. What am I missing here? Thanks in advance.