Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[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 <levy.cyrus@gmail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index