Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with estimating a non-linear model with (ml) maximum likelihood

    Dear STATALISTERS,

    I have a non-linear model that I am estimating using ml in STATA. My model converges, but I get a negative standard deviation (sigma) value. I have copied my code below.
    1) Is the negative sigma an indication of something fundamentally wrong with my model?
    2) Can a restriction be imposed to get positive sigma? How would you go about doing this?

    I will really appreciate your advice!

    warm regards,
    Sam


    cap program drop mynonlin_lf7
    program mynonlin_lf7
    version 14.2
    args todo b lnfj
    tempvar xb alpha theta kr a1 a2 a3 a4 a5 beta g1 g2 g3 g4 sigma hc hw hi yr d1 d2 d3 d4 d5 d6 d7 d10 d11
    qui gen double `alpha' = `b'[1,1]
    qui gen double `theta' = `b'[1,2]
    qui gen double `kr' = `b'[1,3]
    qui gen double `a1' = `b'[1,4]
    qui gen double `a2' = `b'[1,5]
    qui gen double `a3' = `b'[1,6]
    qui gen double `a4' = `b'[1,7]
    qui gen double `beta' = `b'[1,8]
    qui gen double `g1' = `b'[1,9]
    qui gen double `g2' = `b'[1,10]
    qui gen double `g3' = `b'[1,11]
    qui gen double `g4' = `b'[1,12]
    qui gen double `sigma' = `b'[1,13]
    qui gen double `hc' = `b'[1,14]
    qui gen double `hw' = `b'[1,15]
    qui gen double `hi' = `b'[1,16]
    qui gen double `yr' = `b'[1,17]
    qui gen double `a5' = `b'[1,18]
    qui gen double `d1' = `b'[1,19]
    qui gen double `d2' = `b'[1,20]
    qui gen double `d3' = `b'[1,21]
    qui gen double `d4' = `b'[1,22]
    qui gen double `d5' = `b'[1,23]
    qui gen double `d6' = `b'[1,24]
    qui gen double `d7' = `b'[1,25]
    qui gen double `d10' = `b'[1,26]
    qui gen double `d11' = `b'[1,27]

    qui gen double `xb' = `alpha'*`theta'*(prrn+ (-1)*2.5*invlogit(`kr')*prrn-`a1'*wrl-`a2'*wrk-`a3'*wro-`a4'*wimpr-`a5'*inventoryr) +/*
    */ (1-`alpha')*`beta'* (`g1'*wfl+`g2'*wfk+`g3'*wfi+`g4'*infection) +`hc'*chafra+`hw'*wilma+`hi'*irma +`yr'*tn +`d1'*m1 +`d2'*m2+`d3'*m3 +`d4'*m4 +`d5'*m5 +`d6'*m6 +`d7'*m7 +`d10'*m10 +`d11'*m11

    qui replace `lnfj'= -ln(`sigma')+ ln(normalden((pfrn-`xb')/`sigma'))
    end

    ml model gf0 mynonlin_lf7 /alpha /theta /kr /a1 /a2 /a3 /a4 /a5 /beta /g1 /g2 /g3 /g4 /sigma /hc /hw /hi /yr /d1 /d2 /d3 /d4 /d5 /d6 /d7 /d10 /d11 , vce(robust) technique (bfgs)

    ml init /alpha =0.5 /kr =0.5
    ml maximize , difficult
Working...
X