In addition to providing built-in commands to fit many standard maximum likelihood models, such as logistic, Cox, Poisson, etc., Stata can maximize user-specified likelihood functions. To demonstrate, say Stata could not fit logistic regression models. The logistic likelihood function is
f(y, Xb) = 1/(1+exp(-Xb)) if y = 1 = exp(-Xb)/(1+exp(-Xb)) if y = 0
We might first write a program in Stata to calculate the log of the likelihood function given y ($ML_y1 in the code below) and Xb:
That done, we can fit a logistic-regression model of dependent variable foreign on mpg and displ by typing
You will be surprised when you see the output:
foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] | |
mpg | -.1685869 .0919175 -1.83 0.067 -.3487418 .011568 | |
weight | -.0039067 .0010116 -3.86 0.000 -.0058894 -.001924 | |
_cons | 13.70837 4.518709 3.03 0.002 4.851859 22.56487 | |
Stata automatically generated this neatly formatted output, complete with significance levels and confidence intervals.
The following features are worth noting:
Stata’s likelihood-maximization procedures have been designed for both quick-and-dirty work and writing prepackaged estimation routines that obtain results quickly and robustly. For instance, Stata fits negative binomial regressions (a variation on Poisson regression) and Heckman selection models. We wrote those routines using Stata's ml command, although most users are not aware of that. They think that negative binomial and Heckman selection are just two more things Stata can do.
If you are serious about maximizing likelihood functions, you will want to obtain the text Maximum Likelihood Estimation with Stata, Fourth Edition by William Gould, Jeffrey Pitblado, and Brian Poi (2010). The first chapter provides a general overview of maximum likelihood estimation theory and numerical optimization methods, with an emphasis on the practical applications of each for applied work. The middle chapters detail, step by step, the use of Stata to maximize user-written likelihood functions. The final chapters explain, for those interested, how to add new estimation commands to Stata.