Announcement

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

  • How to do a EM for my mixture model

    Dear statalist:
    I want to do a mixture model of two ols whose coffients are constrained to be same.I have written a maximum likelihood estimation to this problem but it only worked when varaibles are limited.Althouth fmm released by stata can solve it,my research need to program by myself.I wonder if you can tell me how to do Expectation-Maximization algorithm for my model.
    the code is as following:

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    webuse womenwk, clear
    
    
    capture program drop fmmreg
    program fmmreg
    qui {
       args lnf xb1 lns1 xb2 lns2 lp 
       tempvar f1 f2
       gen double `f1'=normalden($ML_y1,`xb1',exp(`lns1'))
       gen double `f2'=normalden($ML_y1,`xb2',exp(`lns2'))
       tempvar p
       gen double `p'=exp(`lp')/(1+exp(`lp'))
       replace `lnf'=ln(`p'*`f1'+(1-`p')*`f2') 
    }
    end
    
    
    constraint 1 [xb1]age=[xb2]age
    constraint 2 [xb1]education=[xb2]education
    constraint 3 [xb1]married=[xb2]married
    constraint 4 [xb1]child=[xb2]child
    
    ml model lf fmmreg (xb1:wage=age education married children ) (lns1:) (xb2:wage=age education married children ) (lns2:) (lp:),constraints(1/4)
    ml max
    end
    ------------------ copy up to and including the previous line ------------------
Working...
X