在 Stata 中进行回归后,我尝试仅绘制交互项的系数。
我无法使用社区贡献的命令coefplot
.
这是一个可重现的示例和我尝试的解决方案:
sysuse auto, clear
reg price foreign i.turn foreign#i.turn
*this plots all coefficients:
coefplot,
*this drops _cons and foreign but not i.turn
coefplot, drop(i.turn _cons foreign )
*variations with keep also do not work
coefplot, keep(foreign#i.turn )
还有其他方法吗?
我已经交叉发布了这个问题集权主义者 https://www.statalist.org/forums/new-content/51.
您只需要指定交互:
sysuse auto, clear
reg price foreign i.turn foreign#i.turn, coeflegend noheader
local coefinter 1.foreign#33.turn 1.foreign#34.turn 1.foreign#35.turn ///
1.foreign#36.turn 1.foreign#37.turn
coefplot, keep(`coefinter')
EDIT:
您还可以获取所有非零系数,如下所示:
sysuse auto, clear
reg price foreign i.turn i.foreign#i.turn, coeflegend noheader
matrix A = e(b)
local namecol "`: colnames A'"
tokenize `namecol'
forvalues i = 1 / `=colsof(matrix(A))' {
local mv = A[1,`i']
if `mv' != 0 & strmatch("``i''" , "*#*") {
local coefinter `coefinter' ``i''
}
}
coefplot, keep(`coefinter')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)