【问题标题】:Stata - Marginal effectsStata - 边际效应
【发布时间】:2013-01-07 19:41:41
【问题描述】:

有没有人可以简单地通过程序 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

【问题讨论】:

    标签: margins stata


    【解决方案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 的一般政策如何,我都会亲自帮助完成看似是课程作业的任务。请参阅您大约一周前的上一篇文章。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2020-05-07
      • 1970-01-01
      • 2011-08-13
      • 2014-11-08
      相关资源
      最近更新 更多