Statalist


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

Re: st: Re: Method lf evaluator code for heckman model


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: st: Re: Method lf evaluator code for heckman model
Date   Tue, 19 May 2009 12:32:28 +0200

Hi David,

Haven't checked your code, but this one works:

---------------------------------------------------
clear
set obs 1000
drawnorm e1 e2, cov(1,0.5\0.5,1)
drawnorm x1 x2 z1 z2
g obs=1+z1+z2+e1>0
g y=1+x1+x2+e2


cap prog drop myheck
program define myheck
args lnf xb zg lnsig athrho
tempvar sigma rho nsig
qui gen double `sigma'=exp(`lnsig')
qui gen double `rho'=tanh(`athrho')
qui gen double `nsig'=sqrt(1-(`rho')^2)
qui replace `lnf'=ln(normalden($ML_y1-`xb',0,`sigma')*normal((`zg'+(`rho'/`sigma')*($ML_y1-`xb'))/`nsig')) if $ML_y2==1
qui replace `lnf'=ln(normal(-`zg')) if $ML_y2==0
end

ml model lf myheck (y obs = x1 x2) (z1 z2) (lnsig:) (athrho:)
ml max, diff

replace y=. if obs==0
heckman y x1 x2, select(z1 z2)
------------------------------------------------------------------------------




Vincent, David wrote:
I would be most grateful if someone could advise me how to code method lf for evaluating the log-likelihood function for the Heckman model. I need to compute the MLE's for a range of sample selection type models (options not available in STATA) and being new to programming, wanted to start off with this well known model. The latent variable specifications are:

yi*=x1i'b1+e1   (coded $ML_y1)
ti*=x2i'b2+e2   (coded $ML_y2)

And the code I have written is:


program dv2mle_lf
args lnf theta1 theta2 sd2 rho
tempvar A B C D quietly {
      gen double `A'=ln(1-normal(`theta1'))
      gen double `B'=`theta1'-`rho'*(1/`sd2')*($ML_y2-`theta2')
      gen double `C'=sqrt(1-`rho'^2)
      gen double `D'=ln(normalden(($ML_y2-`theta2')/`sd2'))
      replace `lnf'=(1-$ML_y1)*`A'+$ML_y1*ln(normal(`B'/`C'))-$ML_y1*ln(`sd2')+$ML_y1*`D'
}
end


When I type:   ml model lf dv2mle_lf (theta1: y t = x1 x2 x3) (x1 x2)  () ()   STATA reports that the log likelihood = infinity and cannot be evaluated. Any help would be gratefully appreciated!

Many thanks,
David.




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index