Announcement

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

  • log likelihood = -<lnf> when using MLE

    Hi, respectful masters.

    I am a junior learner in econometrics. When I writing MLE program to do some basic work, something went wrong. Details and dataset are as follows:

    StataI version is 17.0.

    Code:
    program ml1
    args lnf xb sigma local y "$ML_y1"
    quietly replace `lnf' = ln(normalden(`y', `xb', `sigma'))
    end
    ml model lf ml1 (xb: y = pop income) (sigma:) ml maximize
    After running, Stata showed as follows:

    "log likelihood = -<inf> (could not be evaluated)
    could not find feasible values
    r(491);
    "
    My dataset is as follows:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(y pop income) byte _MLtua1
    107919  65044 13240 1
    118866 101376 22554 1
     98579 124989 16916 1
    122015  55249 20967 1
    152827  73775 19576 1
     91259  48484 15039 1
    123550 138809 21857 1
    160931  50244 26435 1
     98496 104300 24024 1
    108052  37852 14987 1
    144788  66921 30902 1
    164571 166332 31573 1
    105564  61951 19001 1
    102568 100441 20058 1
    103342  39462 16194 1
    127030 139900 21384 1
    166755 171740 18800 1
    125343 149894 15289 1
    121886  57386 16702 1
    134594 185105 19093 1
    152937 114520 26502 1
    109622  52933 18760 1
    149884 203500 33242 1
     98388  39334 14988 1
    140791  95120 18505 1
    101260  49200 16839 1
    139517 113566 28915 1
    115236 194125 19033 1
    136749 233844 19200 1
    105067  83416 22833 1
    136872 183953 14409 1
    117146  60457 20307 1
    163538  65065 20111 1
    end
    It's my first time to post in forum. I am afraid that there may be some improper or uncomfortable saying due to my lack of experience. If so, please forgive and correct me.

    Best Regards.

  • #2
    Originally posted by EnJie Huang View Post
    After running, Stata showed as follows:

    "log likelihood = -<inf> (could not be evaluated)
    could not find feasible values
    r(491);
    "
    Although the following is ostensibly equivalent to your evaluator program it works while yours doesn't.
    Code:
    program define ml1
        version 18.0
        args lnf xb sigma
    
        quietly replace `lnf' = lnnormalden($ML_y1, `xb', `sigma')
    
    end
    Also, if you divide all of your variables by 10000, then yours works, too.

    Comment


    • #3
      That is a neat property! Im guessing the reason why it works is because lnnormalden() is more accurate than ln(normalden()).
      Although that being said, there are other things to consider:
      1. Unless otherwise specified, -ml- uses a vector of zeroes for all parameters that need to be estimated. Which is a problem for `sigma` because it cannot be zero.

      With your code, this should work

      Code:
      matrix binit= 10000
      matrix colname binit = sigma:_cons
       ml model lf ml1 (xb: y = pop income) (sigma:), init(binit)
      ml maximize
      2. Because `sigma' cannot be negative or zero, its often better to program it differently:

      Code:
       program ml3
      args lnf xb lnsigma
      local y $ML_y1
      quietly replace `lnf' = ln(normalden(`y', `xb', exp(`lnsigma')))
      end
      Thus you estimate lnsigma in the model, instead of sigma.
      If you want to recover sigma, you could use nlcom

      nlcom exp(_b[lnsigma:_cons])

      and the results would be identical.

      HTH

      Comment


      • #4
        Thanks both of you!

        Now I understand. When using ln(normalden(...)), the intermidiate value may weaken the robustness of calculation and generate error. If using lnnormalden(...) , the final value can be calculated directly.

        The method of exp('lnsigma') is also useful as it makes sure that "sigma" must keep positive. My teacher also told me this method yeaterday.

        Comment

        Working...
        X