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 rescale A variable by rangeHello statalist members, i want to rescale my contious variables(x,y) by range(maximum-minimum) beca…
Counting the number of ID type for each country in the dataHi, My Panel data has 260 Panel IDs(firms) over a number of time period and another variable names …
extract yearDear All, How can I extract year (Stata format) from the following variable? Code: * Example genera…
clustering and concentration Stata code Hi everyone, I am in the process of writing one of my dissertation chapters. Using US Census and A…
Textbox position in bar graphs I am trying to change the position of subtitles in bar graphs. I've created a MWE from Stata's data…
Subscribe to:
Post Comments (Atom)
0 Response to can one use MATA within an ML program
Post a Comment