Reputation: 15458
I am trying to understand the use of maximum likelihood in Stata (for which I am currently using the third edition of the book by Gould et al.). In particular, I am focussing on user program craggit
. The detail of command can be found in Stata article. When using the view source craggit.ado
, I can see all codes in the ado file. In the ado file [details below], I see the ml
using the lf
method, but nowhere in the file do I see the maximum likelihood commands (probit
and truncreg
as specified in the article). Please let me know whether I am missing something.
program craggit
version 9.2
if replay() {
if ("`e(cmd)'" != "craggit") error 301
Replay `0'
}
else {
//Checking data structure
syntax varlist [fweight pweight] [if] [in], SECond(varlist) [ ///
Level(cilevel) CLuster(varname) HETero(varlist) * ///
]
gettoken lhs1 rhs1 : varlist
gettoken lhs2 rhs2 : second
marksample touse
quietly sum `lhs1' if `touse'
local minval1 = r(min)
quietly sum `lhs2' if `touse'
local minval2 = r(min)
if `minval1'<0 | `minval2'<0 {
di "{error:A dependant variable is not truncated at 0: {help craggit} is
> not appropriate}"
}
else Estimate `0'
}
end
program Estimate, eclass sortpreserve
di ""
di "{text:Estimating Cragg's tobit alternative}"
di "{text:Assumes conditional independence}"
syntax varlist [fweight pweight] [if] [in], SECond(varlist) [ ///
Level(cilevel) CLuster(varname) HETero(varlist) * ///
]
mlopts mlopts, `options'
gettoken lhs1 rhs1 : varlist
gettoken lhs2 rhs2 : second
if "`cluster'" != "" {
local clopt cluster(`cluster')
}
//mark the estimation subsample
marksample touse
//perform estimation using ml
ml model lf craggit_ll ///
(Tier1: `lhs1' = `rhs1') ///
(Tier2: `lhs2' = `rhs2') ///
(sigma: `hetero') ///
[`weight'`exp'] if `touse', `clopt' `mlopts' ///
maximize
ereturn local cmd craggit
Replay, `level'
end
program Replay
syntax [, Level(cilevel) *]
ml display, level(`level')
end
Upvotes: 1
Views: 643
Reputation: 2694
The log likelihood function is computed in the file craggit_ll.ado
, so to see that you need to type viewsource craggit_ll.ado
.
The logic behind storing the log likelihood evaluator program in a separate file is that all programs that are defined in the craggit.ado
file, except the very first one, are local to the commands stored in that file, so ml
would not be able to see it. By storing it in a separate file, the craggit_ll
command will become global, and ml
wil be able to use it.
Upvotes: 2