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]

Re: st: ML Programming


From   "Jonas" <[email protected]>
To   [email protected]
Subject   Re: st: ML Programming
Date   14 Jun 2013 13:05:33 +0200

Hi,
I have some additions.
For the Variables in the final ml model command, Hc gives the chosen
Hour category out of 12 possible categories.
What I finally want is to specify my log likelihood function, that the
chosen category is in the numerator and the sum of all other possible
choices is in the denominator.

.ml report gives following code after I run ml. search:
. ml report

Current coefficient vector:
         eq1:     eq2:     eq3:     eq4:     eq5:     eq6:     eq7:
eq7:     eq7:     eq7:     eq7:     eq7:
       _cons    _cons    _cons    _cons    _cons    _cons    feduc
meduc     mage     fage  datanum   nchild
r1      -.5      -.5      -.5      -.5      -.5      -.5        0
0        0        0        0        0

         eq7:     eq8:     eq8:     eq8:     eq8:     eq8:     eq9:
eq9:     eq9:     eq9:     eq9:  lnsig1:
       _cons     fage    feduc  datanum   nchild    _cons     mage
meduc  datanum   nchild    _cons    _cons
r1      -.5        0        0        0        0      -.5        0
0        0        0      -.5      -.5

      lnsig2:  lnsig3:
       _cons    _cons
r1      -.5      -.5

It seems that the program is not finding any values for my explanatory
variables. I already checked for negative or missing values.
Stata report always:
initial:       log likelihood =     -<inf>  (could not be evaluated)


On 13.06.2013 15:46, Jonas Krüger wrote:
Hi everyone.
I have some problems getting my ML estimation running. I want to
estimate a multinomial labor supply model. My program passes the first
two test with .ml check but fails to find initial values, I cant figure
out why so far.

. ml search
initial:       log likelihood =     -<inf>  (could not be evaluated)


The code (The variable didep shows the actual observed choice, strata
identifies the household and for each household I have 12 observation.
One for each possible hour category plus the net income.)
sort strata Hc
program ML
    args todo b lnf
    tempvar beta1 beta2 beta3 alpha1 numer sum denom utility
    tempname random1 random2 random3 alpha2 alpha3 alpha4 alpha5 alpha6 L1
L2 sigma1 lnsig1 l11 sigma2 lnsig2 l22 sigma3 lnsig3 l33
    mleval `alpha1' = `b', eq(1)
    mleval `alpha2' = `b', eq(2) scalar
    mleval `alpha3' = `b', eq(3) scalar
    mleval `alpha4' = `b', eq(4) scalar
    mleval `alpha5' = `b', eq(5) scalar
    mleval `alpha6' = `b', eq(6) scalar
    mleval `beta1' = `b', eq(7)
    mleval `beta2' = `b', eq(8)
    mleval `beta3' = `b', eq(9)
    mleval `lnsig1' = `b', scalar eq(10)
     mleval `lnsig2' = `b', scalar eq(11)
    mleval `lnsig3' = `b', scalar eq(12)
    qui gen double `L1'=0
    qui gen double `L2'=0
    qui gen double `numer'=0
    qui gen double `sum'=0
    qui gen double `denom'=0
    qui gen double `random1'=0
    qui gen double `random2'=0
    qui gen double `random3'=0
    qui gen double `utility'=0
    scalar `sigma1'=(exp(`lnsig1'))^2
    scalar `sigma2'=(exp(`lnsig2'))^2
    scalar `sigma3'=(exp(`lnsig3'))^2
    matrix f=(`sigma1' , 0 , 0 \ 0 , `sigma2' , 0 \ 0 , 0 , `sigma3')
    capture matrix U=cholesky(f)
    if _rc != 0 {
di "Warning: cannot do Cholesky factorization of rho matrix"
}
    scalar `l11'=U[1,1]
    scalar `l22'=U[2,2]
    scalar `l33'=U[3,3]
    forvalues r=1/50{
        qui replace `random1'=random1_`r'*`l11'
        qui replace `random2'=random2_`r'*`l22'
        qui replace `random3'=random3_`r'*`l33'

        *------------------------------------------------------------------------------------------------*
        qui by strata: replace
`utility'=`alpha1'*ysq+`alpha2'*hfsq+`alpha3'*hmsq+`alpha4'*hfhm+`alpha5'*yhf+`alpha6'*yhm+(`beta1'+`random1')*y+(`beta2'+`random2')*fh+(`beta3'+`random3')*hm
        qui replace  `sum'=exp(`utility'),
        qui by strata: replace  `numer'=`sum' if didep==1
        qui by strata: replace  `denom'=sum(`numer')
        qui replace  `L1'=(`numer'/`denom')
        replace `L2'=`L2'+`L1'
        *-----------------------------------------------------------------------------------------------------*
    } //forvalues r=1/50


    mlsum `lnf'=ln(`L2'/50) if didep==1
    if (`todo'==0 | `lnf'>=.) exit

end
ml model d0 ML ( Hc =) (Hc =) (Hc = ) (Hc = ) (Hc = ) (Hc =)(Hc= feduc
meduc mage fage datanum nchild) (Hc =  fage feduc datanum nchild) (Hc =
mage  meduc datanum nchild) /lnsig1 /lnsig2 /lnsig3





Thanks in advance
*
*   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/


*
*   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