I am trying to use the mata optimize function to solve some non-linear equations.
I would like to do this many times with different values for the parameters of the nonlinear equation.
mata code that works and provides a solution for a single run of a simplified version of my problem is:
mata:
void myeval(todo, t, y, g, H)
{
y= -(2-t)^2
}
S = optimize_init()
optimize_init_evaluator(S, &myeval())
optimize_init_params(S, 0)
x = optimize(S)
x
end
I would like to run this multiple times using a forvalues (or other looping) statement such as
forvalues i = 2(2)40 {
.
.
.
}
I know from previous statalist posts (and from trying it) that I cannot simply embed the mata code in the forvalues loop.
I would like advice on how to run the optimize command many times with different parameters for the non-linear equation. Also, I would (of course) like to recover the optimized value for t and `i'. where t. maximizes y= -(`i'-t)^2
Thanks
I would like to do this many times with different values for the parameters of the nonlinear equation.
mata code that works and provides a solution for a single run of a simplified version of my problem is:
mata:
void myeval(todo, t, y, g, H)
{
y= -(2-t)^2
}
S = optimize_init()
optimize_init_evaluator(S, &myeval())
optimize_init_params(S, 0)
x = optimize(S)
x
end
I would like to run this multiple times using a forvalues (or other looping) statement such as
forvalues i = 2(2)40 {
.
.
.
}
I know from previous statalist posts (and from trying it) that I cannot simply embed the mata code in the forvalues loop.
I would like advice on how to run the optimize command many times with different parameters for the non-linear equation. Also, I would (of course) like to recover the optimized value for t and `i'. where t. maximizes y= -(`i'-t)^2
Thanks
Comment