Announcement

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

  • MLE and log likelihood function

    Here, Y = {y1, y2, ..., y10} = {10, 9, 21, 4, 14, 11, 22, 9, 6, 4}. Using the (log-)likelihood function, how I can demonstrate the maximum likelihood estimation in STATA ?

  • #2
    I did as follows, but I am getting error

    clear
    set more off
    matrix define Y = (10\9\21\4\14\11\22\9\6\4)
    matrix list Y
    svmat Y, names(y)
    rename y1 y

    capture program drop binomial
    program define binomial
    args llk theta
    quietly replace `llk' = ( y*ln(`theta') ) + ( (10-y)*ln(1-`theta') )
    end

    ml model lf binomial (y=)
    ml search
    ml max
    ml graph

    Comment


    • #3
      The binomial distribution models the number of successes y out of n trials. Your y vector has entries between 4 and 22, but in the log-likelihood you specify n as 10. Clearly the data are not consistent with the model. If you change 10 to something like 25 the code will run and give the correct estimate of 0.44. You could also define a variable n to hold the binomial denominators, specify both y and n in your model statement, and use the macros $ML_y1 and $ML_y2 to refer to them when you evaluate the log-likelihood.

      Comment

      Working...
      X