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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: problem 0 likelihood ml


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: problem 0 likelihood ml
Date   Fri, 16 Nov 2012 16:08:27 +0100

On Fri, Nov 16, 2012 at 3:45 PM, Olivier Francois wrote:
> I needed to create my own likelihood function and have been running into problems. I have been trying to use program and the ml commands, but there is something I must not do correctly.
<snip>
>     if $ML_y1 == 0 {
>         replace `lnf' = ln(normal(-`xgam'))
>     }
>
>     else if $ML_y1 == 1 {
>             replace `lnf' = ln(normal(`xgam'))
>     }

The way you have used -if- means that it takes a scalar, in this case
the first observation of the dependent variable, and checks whether it
is 0 or 1, and applies the likelihood computation for all observations
based on that test, compare -help if- with -help ifcmd-. What you want
is to tell Stata to check for each observation whether the dependent
variable is 0 or 1 and choose the appropriate log likelihood function
accordingly. You can do that as folows:

replace `lnf' = ln(normal(-`xgam')) if $ML_y1 == 0
replace `lnf' = ln(normal( `xgam')) if $ML_y1 == 1

alternatively:

replace `lnf' = $ML_y1*ln(normal(`xgam') + (1-$ML_y1)*ln(normal(-`xgam'))

The latter will allow you to estimate a probit and a fractional probit.

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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