-1
是否有人可以簡單地通過程序mymargin並檢查是否存在任何不一致以及可能的擴展/改進,...程序應該估計樣本中由if和in選擇的任何變量的邊際效應應該建立在以前的logit迴歸中保存的結果上。Stata - 邊際效應
capture program drop mymargin
program mymargin, rclass
version 10.1
syntax varlist(max=1 numeric) [if] [in] [, atmean]
marksample touse
quietly count if `touse' == 1
if `r(N)' == 0 {
error 301
}
local res me mme
tempname `res'
quietly summarize `varlist' if `touse'==1, detail
scalar `me' = // TBU
display as txt "Marginal effect of" `var' ": " `me'
if "`atmean'" == "atmean" {
matrix r = r(stats)
scalar `me' = normalden(_b[sex]*r[2,1]+_b[ageinyears]*r[3,1] +_b[meduc]*r[4,1] +_b[hhinc]*r[5,1] +_b[area]*r[6,1] + _b[_cons])
}
display as txt "Mean marginal effect of" `var' ": " `me'
foreach r of local res {
return scalar `r' = ``r''
}
return scalar N = r(N) // return the number of observations
return local var `varlist' // return the name of the variable
return // TBU, return the (mean) marginal effect
end
mymargin hhinc
return list
display me
display mme