Hi,
I am running maximum likelihood estimation with moptimize where I passed my independent variables to the evaluator through moptimize_init_eq_indepvars().
I would like to add an extra covariate to those already passed such that this new covariate is defined inside the evaluator.
My code would look like:
mata
y = mydepvar
X=(myfirstindvar,mysecondindvar)
function mle (transmorphic M, real vector b, real vector lnf)
{
real colvector y, xb,sigma,z
y = moptimize_util_depvar(M, 1)
xb = moptimize_util_xb(M, b, 1)
sigma = moptimize_util_xb(M, b, 2)
z=xb[.,1]:*xb[.,2]
xb=(xb,z)
lnf = ln(normalden(y-xb, 0, sigma))
}
M = moptimize_init()
moptimize_init_evaluator(M, &mle())
moptimize_init_depvar(M, 1, y)
moptimize_init_eq_indepvars(M, 1,X)
moptimize_init_eq_indepvars(M, 2,"")
moptimize(M)
end
In this example, I tried to define the new covariate as the element by element product of the two independent variables:
z=xb[.,1]:*xb[.,2]
but it does not work. It seems to me that the evaluator considers moptimize_util_xb as a unique matrix that cannot be manipulated by columns. In particular,
a) it does not seem possible to extract a specific column like xb[.,number of wanted column]. The evaluator considers the second index inside xb as the number of equation and not as column index.
b) it does not seem possible to add a new column like xb=(xb,z).
Any help will be greatly appreciated.
Thanks,
Simone
I am running maximum likelihood estimation with moptimize where I passed my independent variables to the evaluator through moptimize_init_eq_indepvars().
I would like to add an extra covariate to those already passed such that this new covariate is defined inside the evaluator.
My code would look like:
mata
y = mydepvar
X=(myfirstindvar,mysecondindvar)
function mle (transmorphic M, real vector b, real vector lnf)
{
real colvector y, xb,sigma,z
y = moptimize_util_depvar(M, 1)
xb = moptimize_util_xb(M, b, 1)
sigma = moptimize_util_xb(M, b, 2)
z=xb[.,1]:*xb[.,2]
xb=(xb,z)
lnf = ln(normalden(y-xb, 0, sigma))
}
M = moptimize_init()
moptimize_init_evaluator(M, &mle())
moptimize_init_depvar(M, 1, y)
moptimize_init_eq_indepvars(M, 1,X)
moptimize_init_eq_indepvars(M, 2,"")
moptimize(M)
end
In this example, I tried to define the new covariate as the element by element product of the two independent variables:
z=xb[.,1]:*xb[.,2]
but it does not work. It seems to me that the evaluator considers moptimize_util_xb as a unique matrix that cannot be manipulated by columns. In particular,
a) it does not seem possible to extract a specific column like xb[.,number of wanted column]. The evaluator considers the second index inside xb as the number of equation and not as column index.
b) it does not seem possible to add a new column like xb=(xb,z).
Any help will be greatly appreciated.
Thanks,
Simone
Comment