The following program works well but I will introduce some other
variables and modify myprog. How can I calculate the variance covariance
matrix of epsilon in myprog so that I can use that matrix in mlsum.
capture program drop myprog
program myprog
version 11
args todo b lnf
tempvar xb lnsigv2 lnsigu2
mleval `xb' = `b', eq(1)
mleval `lnsigv2' = `b', eq(2)
mleval `lnsigu2' = `b', eq(3)
tempvar sigs2 epsilon lambda
quietly gen double `sigs2' = exp(`lnsigv2') + exp(`lnsigu2')
quietly gen double `epsilon' = $ML_y1 - `xb'
quietly gen double `lambda' = sqrt( exp(`lnsigu2')/exp(`lnsigv2') )
mlsum `lnf' = 0.5 * ln(2/_pi) - ln(sqrt(`sigs2')) /*
*/ + ln(normal(-(`epsilon'*`lambda') /
sqrt(`sigs2'))) - `epsilon'^2 / (2*`sigs2')
end
ml model d0 myprog (main: y = x1 x2) (lnsig2u: s1) (lnsig2v: s2)
ml max
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/