Dear Statalist,
I am writing an estimation command and would like to modify the error message that is issued by optimize() when the numerical derivative could not be calculated. In specific, I would like to add a recommendation for the user how to solve the error.
I've tried to solve my problem by using _optimize(), which is supposed return nonzero values in case of error and not to abort. If there is an error, I could print the error text and a recommendation for the user. However, _optimize() aborts when it "could not calculate numerical derivatives -- discontinuous region with missing values encountered".
A minimal working example is:
Why does _optimize() abort? What am I doing wrong?
I'm using Stata 14 with Windows 7.
Thank you very much for your help!
Christoph
I am writing an estimation command and would like to modify the error message that is issued by optimize() when the numerical derivative could not be calculated. In specific, I would like to add a recommendation for the user how to solve the error.
I've tried to solve my problem by using _optimize(), which is supposed return nonzero values in case of error and not to abort. If there is an error, I could print the error text and a recommendation for the user. However, _optimize() aborts when it "could not calculate numerical derivatives -- discontinuous region with missing values encountered".
A minimal working example is:
Code:
mata:
mata clear
void myFunction(real scalar todo, real scalar p, score, g, H) {
score = 2
}
S = optimize_init()
optimize_init_params(S, 0)
optimize_init_evaluator(S, &myFunction())
_optimize(S)
if (ec = optimize_result_errorcode(S)) {
errprintf("{p}\n")
errprintf("%s\n", optimize_result_errortext(S))
errprintf("\n Print some recommendation")
errprintf("{p_end}\n")
exit(optimize_result_returncode(S))
/*NOTREACHED*/
}
result = optimize_result_params(S)
printf("Result is: %5.2f", result)
end
I'm using Stata 14 with Windows 7.
Thank you very much for your help!
Christoph

Comment