Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: how to calculate variance covariance matrix in ml program


From   Cyrus Levy <[email protected]>
To   [email protected]
Subject   st: how to calculate variance covariance matrix in ml program
Date   Sun, 17 Feb 2013 08:20:15 -0600

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index