有没有人可以简单地通过程序 mymargin 并检查任何不一致和可能的扩展/改进,...程序应该估计由 if 和 in 选择的样本中任何变量的边际效应应该建立在保存的结果的基础上以前的 logit 回归。
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