Announcement

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

  • Error when estimating ML log-normal

    Hello!

    I have the following ML program:
    Code:
    capture program drop lfln
    program lfln
      version 12.1
      args lnf xb sigma
      local y "$ML_y1"
      quietly replace `lnf' = ln(normalden(ln((`y'-`xb'))/`sigma')) - ln(`sigma')
    end
    which is basically the same of a normal distribution, but with the y-xb in logs. As far as I know, the log-normal can be represented as the normal of the log of a variable, and so to me that transformation makes sense.

    The program does not work when estimating a simple regression. "ml check" cannot find feasible initial values. It does work when I remove the ln in y-xb, providing the same result as with regress.

    What is the problem?


  • #2
    Quick though, shouldn't it be the natural log of the dependent variable? not the natural log of the difference from the mean? That is
    Code:
    (ln(`y')-`xb'))
    I would actually do the log transformation outside of the likelihood function and keep the normal density in the likelihood function. The reason is that it gives you more flexibility to take care of critical values like if you have a lot of zeros in your dependent variable.
    Alfonso Sanchez-Penalver

    Comment


    • #3
      But the distribution assumption is of the error, and thus the log should be of y-xb, which is the error. That is why applying ML with normal uses normden(y,xb,sigma). Maybe I'm wrong, but that is my knowledge of MLE.

      Comment


      • #4
        Consider the model

        y = a*v1^b1*e

        Taking the natural log

        ln(y) = ln(a) + b1ln(v1) + ln(e)

        The error is e, so when taking the natural log of the explained variable you're expressing everything in terms of natural logs. The maximum likelihood estimation xb is estimating ln(a) + b1ln(v1).

        Another way to see it. Consider the model

        ln(y) = b0 + b1 x + u.

        Taking exponential on both sides

        y = exp(b0)exp(x^b1)exp(u)

        so clearly u is the natural log of the original error exp(u). Remember that the error is what is not explained by the mean equation, so its distribution comes from the explained variable. So when you assume that the error is lognormally distributed is because you're estimating an exponential model.
        Last edited by Alfonso Sánchez-Peñalver; 11 Sep 2016, 20:12.
        Alfonso Sanchez-Penalver

        Comment


        • #5
          I would add to Alfonso's good advices that In a log normal model ln(Y) follows a normal distribution, so you can retransform your model such that you have a normal regression model with ln(Y) as the dependent variable. Consequently the residual is ln(Y)-xb and reg ln(Y) X would give the correct estimates.
          Besides sigma should always be positive, therefore you should estimate ln(sigma) instead of sigma. Note also that there is a lnnormalden() function, which computes the log of the normal density.


          Code:
          capture program drop lfln
          program lfln
            version 12.1
            args lnf xb sigma
            quietly replace `lnf' = lnnormalden(ln($ML_y1)-`xb')/exp(`lnsigma') - `lnsigma'
          en

          Comment


          • #6
            I see my mistake. The distribution comes from Y, and it is inherited by the error term. And thanks for the lnnormalden function! I see now the whole list of functions available, so no need to write down the likelihood function myself.

            In the end, the model does not run because the support of the log-normal is positive, Any other which allows negative and positive support works. Thank you both.


            Comment


            • #7
              Yes, negatives and zeroes are a problem. Why do you want to log-transform it? Is the explained variable highly skewed to the right?
              Alfonso Sanchez-Penalver

              Comment

              Working...
              X