[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: How to start writing your own estimation command

From   "P. Wilner" <>
Subject   st: Re: How to start writing your own estimation command
Date   Fri, 2 Nov 2007 14:48:59 -0400

On 11/2/07, Eva Poen <> wrote:
> Dear all
> In the near future I will have to write my own estimation command for
> the first time. It will be a mixed model, much like an ordered probit
> where the cut-offs are known, with some extra parameters. I will need
> the Huber-White-Sandwich variance estimator, and I want to estimate it
> both with a two-step procedure and by maximum likelihood. I own a copy
> of Stata 9 and have access to Stata 10 if necessary.
> I'd be grateful for some guidance on where to start. Is -ml- the way
> to go, or is it better to learn mata and use the optimization
> functions that are listed on
> ? Will the maximum likelihood estimation book by Gould, Pitblado, and
> Sribney help in either case? Is there some other resource out there
> that tells you how to do it in mata and -ml-, and what the differences
> are? I should add that I have no previous experience of mata, but I
> did both NC151 and NC152.
> Thanks,
> Eva
I have written a couple of estimation commands not out to the public
yet. Three friends have accompanied me in my journey to writing those
ML command. I am presenting them to you.

1) net search maximum likelihood
This line of command will show you a remarkable number ML routines
published in the SJ or are on SSC. You may be surprised to find one
that will do the job you want to do. If you find some routines you
like because they can potentially meet your needs, then install them.

2) viewsource
viewsource is the command that will allow to see the secret behind
these routines you have installed. Nick has an article on viewsource
by the way. Note this, every ML routine comes in at least two ado
   a) estcmd.ado, which is the file the user sees
   b) estcmd_ll.ado (file name may vary), which is the ML evaluator
called by estcmd.ado

You need to viewsource both of these files. When you viewsource
estcmd.ado, look for the "ml model" statement that will indicate the
name of ML evaluator. It is often put in local macro, because it is a
secret (just kidding) or for programming efficiency. But if you go
back a few lines up you will see the name of the ML evaluator when the
local macro was first declared.

viewsource is what makes Stata differ from the "others". You can use
them but you can never see inside of their black box. You know those I
am referring to!

3) Maximum Likelihood Estimation Using Stata by Gould et al.
As Maarten stressed, this book will equip you with sufficient
background to help you understand the thought process behind ML
routines. In other words, you will understand the codes in these
routines and know how to modify them to meet your needs.

A final thought: writers of these the ML routines often give tips and
tricks they use to get their program work in certain ways. For
example, Zurab Sajaia explained how he got rho to satisfy -1<=rho<1
and cutoffs to be ordered ascendingly for his bioprobit command. Get
these SJ articles if you are not a subscriber.

Hope this help
P. Wilner Jeanty, Post-doctoral researcher
Dept. of Agricultural, Environmental, and Development Economics
The Ohio State University
2120 Fyffe Road
Columbus, Ohio 43210
(614) 292-6382 (Office)
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index