Reputation: 631
I'm currently writing a little Stata program in an .ado file. Within this .ado file I want to use Mata in order to use the optimize() functions. When I type end
in order to exit MATA, the .ado file reads this as the end of the program (I think). How do I go about this? I'm really new to both Stata and Mata and especially the use of both of them simultaneously. Here's an example of my code:
program define test
args epv prev0 prev1 sample_size bin_prev rep
local prevdiff=`prev1'-`prev0'
local t=-log(1-`prev0')
local eventprob=`epv'/`sample_size'
local lambda_c=0.5
local lambda_0=1
local lambda_1=-log(1-`prev0'-`prevdiff')/`t'
mata
mata clear
void cens_func(todo, x, y, g, H)
{
y = "some function of x and the locals"
}
S = optimize_init()
optimize_init_evaluator(S, &cens_func())
optimize_init_which(S, "min")
optimize_init_params(S, 1)
temp=optimize(S)
st_local("lambda_c",strofreal(temp))
end
some Stata code here
end
Thanks in advance.
Upvotes: 3
Views: 1527
Reputation: 37208
You should put the Mata code in a separate block at the end.
Schematically,
program
end
mata:
end
Also, don't use the program name test
, which is the name of an official command.
Also, see
http://www.stata.com/support/faqs/resources/statalist-faq/#spell
for correct spellings Stata, Mata.
Upvotes: 3