Statalist The Stata Listserver


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

st: CAnnot generate feasible values in ML Estimation


From   DEEPANKAR BASU <basu.15@osu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: CAnnot generate feasible values in ML Estimation
Date   Sun, 16 Jul 2006 11:59:41 -0400

Hi Statalist,

I have been working with a likelihood function for sometime. It was working fine till I realised a small error in its construction. When I corrected my likelihood evaluator program and ran it again, the -ml  check- gives an error indicating that it cannot generate feasible values. I cannot figure out why. I give the details below.

My likelihood function meets the 'linear form restriction' (in Stata terminology); hence I can use the -lf- method. Thus, my evaluator calculates the loglikelihood for each observation and then sums them up.

The loglikelihood for each observation is of the following form: ln(a+b), where `a' and `b' are complicated expressions involving covariates. 

The problem which I wanted to correct was the following: for some observations `a' should be zero (in the likelihood function), while for other observations, it should remain `a'. To do so, I created an indicator variable (called `test') with the required characteristic and multiplied it to `a' in my likelihood evaluator. Once I did so and ran the program again, the -ml check- shows an error that feasible values cannot be generated. Any ideas about what could be going wrong?

I give both versions of my program: Version 1 and Version 2. Version 1 is the earlier version with the incorrect likelihood which works; Version 2 is the one with the corrected likelihood function which does not work!

Thanks in advance.

Deepankar 


---------Version 1-------------------------

clear
capture program drop gender66_lf
program gender66_lf
   version 8.1
     
   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 x1 x2 x3 x4 x5 x6

     
   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' = `x1'*`x2'     
      gen double `x4' = ((exp(`theta1'))^($ML_y1))/exp(exp(`theta1'))
      gen double `x5' = norm(-`theta3')
      gen double `x6' = ((exp(`theta1'+`theta2'))^($ML_y1))/exp(exp(`theta1'+`theta2'))
      

   }
      #delimit ;
      quietly replace `lnf' = ln( ((1/`x3')*`x4'*`x5') + ((1-`x5')*`x6'*( $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
   
end

set mem 100m
use india66.dta  /* Contains observations with N=2,3,4,5,6; # observations = 47365 */


#delimit ;
ml model lf gender66_lf (fsize: dfsize p21 p31 p32 = age edu rur work middle poor hindu muslim scaste stribe obc, nocons) (alpha:) 
(target: p41 p42 p43 p51 p52 p53 p54 p61 p62 p63 p64 p65 = age edu rur work middle poor hindu muslim scaste stribe obc) 
(four:) (five:) (six:) (seven:) (eight:) (nine:) (ten:) (eleven:) (twelve:) (thirteen:), tech(bhhh nr);  

#delimit cr

ml check

ml search

ml max, difficult


-------------------End-------------------------- 


----------------Version 2-----------------------

clear
capture program drop gender66_lf
program gender66_lf
   version 8.1
     
   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 x1 x2 x3 x4 x5 x6

     
   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' = `x1'*`x2'     
      gen double `x4' = ((exp(`theta1'))^($ML_y1))/exp(exp(`theta1'))
      gen double `x5' = norm(-`theta3')
      gen double `x6' = ((exp(`theta1'+`theta2'))^($ML_y1))/exp(exp(`theta1'+`theta2'))
      

   }
      #delimit ;
      quietly replace `lnf' = ln( ($ML_y17*(1/`x3')*`x4'*`x5') + ((1-`x5')*`x6'*( $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
   
end

set mem 100m
use india66.dta  /* Contains observations with N=2,3,4,5,6; # observations = 47365 */


#delimit ;
ml model lf gender66_lf (fsize: dfsize p21 p31 p32 = age edu rur work middle poor hindu muslim scaste stribe obc, nocons) (alpha:) 
(target: p41 p42 p43 p51 p52 p53 p54 p61 p62 p63 p64 p65 test = age edu rur work middle poor hindu muslim scaste stribe obc) 
(four:) (five:) (six:) (seven:) (eight:) (nine:) (ten:) (eleven:) (twelve:) (thirteen:), tech(bhhh nr);  

#delimit cr

ml check

ml search

ml max, difficult


--------------End------------------------------

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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