Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Problems in maximising a likelihood function

Subject   st: Problems in maximising a likelihood function
Date   Tue, 13 Jun 2006 12:01:35 -0400

Hi Statalisters,

I am facing problems while trying to do a maximum likelihood estimation. I have written out the likelihood estimator; then I have used "ml check". The "ml check" shows that my likelihood evaluator has passed all tests. Then when I issue the "ml max" command, I get the following error message: 

initial:       log likelihood =  31058.016
rescale:       log likelihood =  31058.016
rescale eq:    log likelihood =  34639.752
(setting optimization to BHHH)
could not calculate numerical derivatives
missing values encountered

First thing that worries me is that the log likelihood is positive; is that a sign that my program has some problem? And second, the maximisation is interrupted before completion because it could not calculate numerical derivatives (missing values encountered). I re-checked my dataset; there are no missing values for the variables that I am using. Probably the error message means something else.

I have tried (1) switching between techniques BHHH and NR; (2) ml max, difficult. I still get the same error message (though the log likelihood values where the execution of the program stops are different in each case).

Below I give the do-file that has my likelihood evaluator program and also a "ml model ..." command (as suggested in the book by Gould, Pitbaldo and Sribney: page 165); any suggestions are welcome. 

If someone can detect some error immediately, that will be great. But, if someone needs to run the program, I can send a small subset of my dataset for the purpose. Thanks in advance.

Deepankar Basu


capture program drop gender_lf
program gender_lf
   version 8.1
   set mem 100m
   #delimit ;
   args lnf theta1 theta2 theta3 
        theta5 theta6 theta7 theta8 theta9 
        theta10 theta11 theta12 theta13 theta14;

   tempvar q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14
           x x1 x2 x3 x4 x5 x6 x7;
   #delimit cr

   quietly {
      gen double `q1' = 1/(1+exp(`theta5'))   
      gen double `q2' = exp(`theta5')/(1+exp(`theta5'))   

      gen double `q3' = 1/(1+exp(`theta6')+exp(`theta7'))   
      gen double `q4' = exp(`theta6')/(1+exp(`theta6')+exp(`theta7'))   
      gen double `q5' = exp(`theta7')/(1+exp(`theta6')+exp(`theta7'))   

      gen double `q6' = 1/(1+exp(`theta8')+exp(`theta9')+exp(`theta10'))   
      gen double `q7' = exp(`theta8')/(1+exp(`theta8')+exp(`theta9')+exp(`theta10'))   
      gen double `q8' = exp(`theta9')/(1+exp(`theta8')+exp(`theta9')+exp(`theta10'))   
      gen double `q9' = exp(`theta10')/(1+exp(`theta8')+exp(`theta9')+exp(`theta10'))   

      gen double `q10' = 1/(1+exp(`theta11')+exp(`theta12')+exp(`theta13')+ exp(`theta14'))   
      gen double `q11' = exp(`theta11')/(1+exp(`theta11')+exp(`theta12')+exp(`theta13')+ exp(`theta14'))   
      gen double `q12' = exp(`theta12')/(1+exp(`theta11')+exp(`theta12')+exp(`theta13')+ exp(`theta14'))   
      gen double `q13' = exp(`theta13')/(1+exp(`theta11')+exp(`theta12')+exp(`theta13')+ exp(`theta14'))   
      gen double `q14' = exp(`theta14')/(1+exp(`theta11')+exp(`theta12')+exp(`theta13')+ exp(`theta14'))   
      gen double `x1' = 2^(-$ML_y1)
      gen double `x2' = exp(lnfact($ML_y1))
      gen double `x3' = exp(`theta1')
      gen double `x4' = exp($ML_y1*`theta1')
      gen double `x5' = norm(-`theta3')
      gen double `x6' = exp(`theta2')
      gen double `x7' = exp($ML_y1*`theta2')
      #delimit ;
      gen double  `x' = `x1'*(1/`x2')*exp(-`x3')*`x4'*`x5' + (1-`x5')*exp(-`x6')*`x7' + 
                         $ML_y2 + ($ML_y3*`q1' + $ML_y4*`q2') + 
                         ($ML_y5*`q3' + $ML_y6*`q4'+ $ML_y7*`q5') + 
                         ($ML_y8*`q6' + $ML_y9*`q7'+ $ML_y10*`q8'+$ML_y11*`q9') + 
                         ($ML_y12*`q10' + $ML_y13*`q11' + $ML_y14*`q12'+ $ML_y15*`q13'+$ML_y16*`q14');
      #delimit cr

   quietly replace `lnf' = ln(`x')

use india1.dta

#delimit ;
ml model lf gender_lf (one: dfsize p21 p31 p32 = v012 v025, nocons) 
(two: p41 p42 p43 p51 p52 p53 p54 = v012 v025) 
(three: p61 p62 p63 p64 p65 = v012 v025 v130, nocons) 
(four:) (five:) (six:) (sev:) (eight:) (nine:) (ten:) (eleven:) (twelve:) (thirteen:), tech(bhhh nr);  

#delimit cr


*   For searches and help try:

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