Announcement

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

  • Implement Multinomial Logit Model using ml command

    Already Solved

    I would like to implement multinomial logit model using maximum likelihood command to generate the same result as mlogit.
    Pr(y=1) = exp(beta1*x)/(1+beta1*x+beta2*x)
    Pr(y=1) = exp(beta2*x)/(1+beta1*x+beta2*x)
    Pr(y=1) = 1/(1+beta1*x+beta2*x)

    The following code did not work (not generating anything), but I have no idea how to fix it.
    Code:
    program define mymlogit
        args lnf Xb1 Xb2
        quietly replace `lnf' = -`Xb1' - ln(1+exp(-`Xb1')+exp(-`Xb2')) if $ML_y1==1
        quietly replace `lnf' = -`Xb2' - ln(1+exp(-`Xb1')+exp(-`Xb2')) if $ML_y1==2
        quietly replace `lnf' = -ln(1+exp(-`Xb1')+exp(-`Xb2')) if $ML_y1==3
    end
    
    ml model lf mymlogit (y= x1 x2)
    Last edited by Qize Chen; 30 Jan 2019, 09:42. Reason: solved

  • #2
    Hi Qize
    Couple of points on your question.
    1. why? Since that model is already implemented in stata, why are you trying to do it by hand?.
    2. the program itself its fine, but you are calling it incorrectly. First, you need two arguments, not only one
    Code:
    ml model lf mymlogit (xb1:y= x1 x2) (xb2:= x1 x2)
    Im including here the "names" xb1 and xb2 so you can track it with your own code. But they can be completely different names. If you were to say, args lnf xb1 xb2 xb3 xb4, you would also need to "add" those when calling the ML maximizer
    Code:
    ml model lf mymlogit (xb1:y= x1 x2) (xb2:= x1 x2) (xb3:= x1 x2) (xb4:= x1 x2)
    3. just typing "ml model lf mylogit ..." only sets up the process, to actually estimate it you need to either add the option ", maximize", or use an additional line that says "ml maximize"

    In other words, you need to set up the ML program (done), set the ML estimator known what you will do (ml model lf myprogram ....), and finally ask for it to be maximized.

    HTH
    Fernando

    Comment

    Working...
    X