2013-08-05 103 views
1

ADO文件使用最大似然的,我想了解在Stata使用最大似然(我目前使用book第三版古爾德等人爲此)。特別是,我專注於用戶程序craggit。命令的細節可以在Stata article中找到。當使用view source craggit.ado時,我可以看到ado文件中的所有代碼。在ADO文件[下面詳細說明],我看到ml使用lf方法,但不通在文件中我看到的最大似然命令(probittruncreg在文章中指定)。請讓我知道我是否缺少一些東西。在塔塔

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 

回答

2

的數似然函數計算文件craggit_ll.ado的,這樣就看你需要輸入viewsource craggit_ll.ado

後面在一個單獨的文件中存儲的對數似然評估程序的邏輯是在craggit.ado文件中定義的,除了非常第一個所有的程序,是本地存儲在該文件中的命令,所以ml不會能夠看到它。通過將其存儲在單獨的文件中,craggit_ll命令將變爲全局,並且ml將能夠使用它。

+0

非常感謝澄清。 – Metrics