有没有人可以简单地浏览程序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
答案 0 :(得分:1)
如果仅仅是因为您按指定顺序有五个指定预测变量的连线假设,这将从我那里得到一个失败的等级:
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])
此外,summarize
命令将消除任何先前命令留下的任何r(stats)
。
无论Stack Overflow的一般政策是什么,我都会亲自帮助完成一门课程作业。大约一周前查看您之前的帖子。