Stata Code Fragment
Using ml commands to maximize a user specified likelihood function

* This code produces an ordered logit model for a y variable with 3 levels.

* First write what Stata calls the evaluator 
program myologit

version 9
args lnf xb a1 a2
* The contribution to the likelihood at each level of y        
quietly    replace `lnf' = ln(1/(1+exp(-`a1' + `xb')))                          if $ML_y1 == 1
quietly    replace `lnf' = ln(1/(1+exp(-`a2'+ `xb')) - 1/(1+exp(-`a1' + `xb'))) if $ML_y1 == 2
quietly    replace `lnf' = ln(1 - 1/(1+exp(-`a2'+ `xb')))                       if $ML_y1 == 3

end

use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear

* specify the method (lf) and the name of your evaluator (myologit)
* followed by the equation(s) in parantheses and then the cutpoints.
ml model lf myologit (xb: ses = female math write, nocons ) /a1 /a2
ml check
ml search
ml maximize 

* You can check a simplified version of your model against the results
* from Stata, before writing a program to run a more complicated model.
ologit ses female math write

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.