I need to calculate numerical derivatives in mata. The function of the parameters is however stored in a local macro in Stata. I don't know how to pass this local to the evaluator.
The following code outlines what I would like to do. Not surprisingly, this code won't work because the line code v = a is illegal. However, I hope it's clear what I'm trying to do. I also tried to use user-defined arguments for the evaluator with no luck.
Thank you in advance.
The following code outlines what I would like to do. Not surprisingly, this code won't work because the line code v = a is illegal. However, I hope it's clear what I'm trying to do. I also tried to use user-defined arguments for the evaluator with no luck.
Code:
local fun "b[1]^2/b[2]"
clear mata
mata:
a = st_local("fun")
a
void myeval(b, v)
{
v = a // This should evaluate to v = b[1]^2/b[2] somehow
}
D = deriv_init()
deriv_init_evaluator(D, &myeval())
deriv_init_params(D, (0.5, 0.6))
G = deriv(D, 1)
G
end

Comment