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]

st: problem 0 likelihood ml

From   Olivier Francois <>
To   "" <>
Subject   st: problem 0 likelihood ml
Date   Fri, 16 Nov 2012 14:45:27 +0000


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.

Since it wasn't working I went back to something simpler to make sure I was getting the commands right... A simple probit. I tried with my data but it wasn't working and so tried with some artificial data.

Here is what I code and problems:

//creating the data
set more off
set seed 12345
set obs 1000
matrix C = I(4)
drawnorm z v e x, corr(C)
replace z = sqrt(2)*z
scalar a0 = 2 
scalar a1 = -1
gen D = (a0 + a1*z > v)
gen Y = 0.5 - 0.5*x + e

//Probit model
apture program drop myprobit
program myprobit
    version 11.2
    args lnf xgam

    quietly {

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

    else if $ML_y1 == 1 {
            replace `lnf' = ln(normal(`xgam'))

//first model tried
ml model lf myprobit (xgam: D = z), vce(robust) technique(nr bhhh dfp bfgs)
ml check

/*I get the following error:
       opt__eval_cycle():  3301  subscript invalid
            opt__eval():     -  function returned error
    _optimize_evaluate():     -  function returned error
       _mopt__evaluate():     -  function returned error
     mopt__check_test1():     -  function returned error
      _moptimize_check():     -  function returned error
            Mopt_check():     -  function returned error
                 <istmt>:     -  function returned error

//second model tried
ml model lf myprobit (xgam: D = z), vce(robust) technique(nr)
ml check

//This time, no subscript invalid error... ml check passes all the tests. Does anybody know why? 
//Please feel free to refer to online material, I couldn't find anything by myself.

//Here I get another problem, however, with ml search
ml search

//initial:       log pseudolikelihood =          0
//rescale:       log pseudolikelihood =          0

//I get a value of 0. Sometimes the intital value is fine, but it goes to 0 when ml search does rescale sq (couldn't find what it is either). For example, with another data draw I get:
//initial:       log pseudolikelihood = -10.211373
//rescale:       log pseudolikelihood = -10.211373
//rescale eq:    log pseudolikelihood =          0
// I get it also using my own data. I don't understand why. 
//The direct stata probit command works fine.

Thanks for any help, 


*   For searches and help try:

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