Stata中一个边缘图中的几个边距的图表

MER*_*ose 1 plot margins stata

我想margins在一个边缘图中绘制由命令产生的边距,但是来自不同的margins估计.重要限制:这些系数在相同的最小值和最大值内,因此具有可比性.我怎么做?

这是一个代码示例:

webuse nhanes2, clear

tnbreg psu weight hdresult iron, iterate(5) // I am using this regression type so I stick with it here
Run Code Online (Sandbox Code Playgroud)

我知道我可以将所有边距响应图放在一个图中

margins, dydx(*)
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter)
Run Code Online (Sandbox Code Playgroud)

但实际上我分别margins为每个回归量运行三个命令,因为我想比较回归量变化时的效果.因此代码是

foreach var in weight hdresult iron {
  * Procedure to get the numbers for margins right
  quietly summarize `var '
  local max = r(max)
  local step = round(r(max)/6)

  quietly margins, at(`cvar'=(1(`step')`max'))
  marginsplot, title("") ytitle("")
}
Run Code Online (Sandbox Code Playgroud)

这给了我三个单独的文件.但我当然希望所有的线都在一个图中,用不同的颜色.

有什么建议怎么做?

Rob*_*rer 5

使用combomarginsplot(和帮助文件):

sysuse auto, clear

oprobit rep78 i.foreign mpg price weight
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file1, replace)

oprobit rep78 i.foreign mpg
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file2, replace)

oprobit rep78 i.foreign mpg gear
margins foreign, at(mpg=(10(5)50)) predict(outcome(3)) saving(file3, replace)

combomarginsplot file1 file2 file3, ///
    labels("Full model" "Restricted model" "Gear Model") noci
Run Code Online (Sandbox Code Playgroud)

combomarginsplot是Nicholas Winter用户编写的命令.您可以安装它运行

ssc install combomarginsplot
Run Code Online (Sandbox Code Playgroud)