1

我试图了解在 Stata 中使用最大似然(我目前正在使用 Gould 等人的第三版)。特别是,我专注于用户程序craggit。命令的详细信息可以在 Stata文章中找到。使用时view source craggit.ado,我可以看到ado文件中的所有代码。在 ado 文件 [详情如下] 中,我看到了ml使用该lf方法,但在文件中没有看到最大似然命令(probit以及truncreg文章中指定的)。请让我知道我是否遗漏了什么。

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
4

1 回答 1

2

对数似然函数是在文件中计算的craggit_ll.ado,因此您需要键入viewsource craggit_ll.ado.

将对数似然评估程序存储在单独文件中的逻辑是,文件中定义的所有程序craggit.ado(除了第一个程序)都是存储在该文件中的命令的本地程序,因此ml无法看到它。通过将其存储在单独的文件中,该craggit_ll命令将成为全局的,并且ml能够使用它。

于 2013-08-05T14:36:47.443 回答