Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: problem 0 likelihood ml


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

Hi,

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
clear
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'))
    }
    }
end


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

Olivier






*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index