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, 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 <>
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.
>     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


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 L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index