Dear All,

I have a black-box data generation routine, which depends on three parameters A,B,C.
I generate the data with this procedure for particular values A*, B*, and C*.
I then try to recover these parameters with Stata's optimizer starting from some A0, B0, and C0 and minimizing the sum of squared differences between the data points generated at each iteration and my benchmark.

After a lot of iterations Stata stops with:
Code:
numerical derivatives are approximate
flat or discontinuous region encountered
cannot compute an improvement -- flat region encountered
r(430);
On inspection of last candidate values A1, B1, C1 I see they are close enough to my original A*, B*, C*.

I want Stata not to fail, but return the last best values of parameters of what it considers to be the best guess for A,B, and C.

As I understand I should be using _optimize() in this case. The manual says literally:
optimize() returns an error code. If it is 0, optimization went well and you can obtain the parameter vector by using optimize_result_params(). If optimization did not go well, you can use the error code to diagnose what went wrong and take the appropriate action.
Can I be assured that if optimization didn't go well, I can obtain not just the error code from _optimize(), but also the last best candidate from optimize_result_params() ?? (it doesn't follow from the above description, I want to make sure that it doesn't return me some other combination that it tried around the last best, or something entirely different).

PS: of course I have tried varying the techniques and steps, with no obvious effect (in fact the default seemed to have worked the best).

Thank you, Sergiy Radyakin