I am trying to write a customize likelihood function, where I want to numerically integrate using MATA within the ML framework. Is it possible to pass the arguments of the ML function as limits into the numerical integration command within STATA. here's what I have in mind : Right now I'm getting the error that the MATA function is either already defined OR that it doesn't exist when I try to drop it.
capture program drop ML_program
program define ML_program
* specifiy the arguments for the program
args lnf alpha m
* declare temporary variables
tempvar choice p1 p2 z1 z2 ce_x omega n_star result r
**tempvar tmp alpha m mu
quietly {
/*
** define parameters
generate double `alpha' = exp(`alphat')
generate double `m' = exp(`mt')
generate double `mu' = exp(`mut')
*/
** initialize the data
generate int `choice' = $ML_y1
generate double `p1' = $ML_y2
generate double `p2' = $ML_y3
generate double `z1' = $ML_y4
generate double `z2' = $ML_y5
generate double `ce_x' = $ML_y6
generate double `omega' = $ML_y7
generate double `n_star' = $ML_y8
}
cap mata: mata drop f_outer()
cap mata: mata drop f_inner()
mata:
mata drop f_outer()
mata drop f_inner()
real rowvector f_outer(real rowvector x, real rowvector y)
{
return( exp(-(x:+exp(-x)) :- (y:+exp(-y))) )
}
real rowvector f_inner(real rowvector y)
{
for(i=1; i<=cols(y);i++) {
if (i==1) f=integrate(&f_outer(), `omega', . , 40, y[i])
else f = f, integrate(&f_outer(), `omega', . , 40, y[i])
}
return(f)
}
st_local("`result''", strofreal(integrate(&f_inner(), `alpha', .)))
disp `result'
* evaluate the likelihood
replace `lnf' = `result' if `choice' ==1
replace `lnf' = 1-`result' if `choice' ==0
end
Fix ML_program.
- mata drop f_outer()
f_outer() not found
Related Posts with can one use MATA within an ML program
How to check if variables in varlist are registered as regular or imputedI'm trying to write a loop that iterates through every single variable in a varlist and performs dif…
Create a table with sectoral share valuesDear all, I am currently working with a dataset that contains information on quarterly gross value …
Calculating Standard Deviation of the ResidualsHi all, I ran an ECM and after this, I want to inspect the Standard Deviation of the Residuals plot …
how to run a DEA meta frontière in stata?I want to implement a meta boundary model to take into account the specificity of each group in the …
Endogeneity in non-structural modelingHello Stata users, Can you pleas tell me how we can adress endogeniety in non-structural modeling? …
Subscribe to:
Post Comments (Atom)
0 Response to can one use MATA within an ML program
Post a Comment