plot - 如何在同一张图上获得多个系数

标签 plot graphics stata coefficients

在 Stata 中,我使用 coefplot 包尝试在多重回归中绘制一个系数(换句话说,将有多个系数,但每个系数都来自不同的回归)同样的情节。

这里是当系数在每个回归中具有相同名称时完成此操作的代码(与 Plotting same coefficient over time 相关):

ssc install coefplot
sysuse auto, clear
estimates clear
regress price mpg if foreign==0
est sto t1
regress price mpg if foreign==1
est sto t2
regress price mpg if rep78==5
est sto t3
coefplot t1 || t2 || t3, drop(_cons) vertical bycoefs yline(0)

这一切都很好。但是,当每个回归的系数与不同的变量相关时,我怎样才能完成同样的事情呢?例如:

estimates clear
regress price mpg if foreign==0
est sto t1
regress price trunk if foreign==1
est sto t2
regress price weight if rep78==5
est sto t3
coefplot t1 || t2 || t3, drop(_cons) vertical bycoefs yline(0)

当我只想要一个图时,这会产生三个独立的图。我需要做什么才能实现这个目标?我想要的是有一个图,其系数来自 mpg (t1)、truck (t2 >) 和 weight (t3) 都绘制在同一个图上。如果还知道如何在标记这些系数 mpg、truck、weightt1、t2、t3 之间进行切换,那就太好了。

一种解决方案是使用矩阵,但如果可能的话,我想避免走这条路。

最佳答案

注意:coefplot是用户编写的命令。

下面的例子:

sysuse auto, clear

estimates clear

regress price mpg if foreign==0
est sto t1

regress price trunk if foreign==1
est sto t2

regress price weight if rep78==5
est sto t3

coefplot (t1\t2\t3), drop(_cons) xline(0)

除了通常的帮助之外,还可以查看this document作者:Ben Jann,该命令的作者。

关于plot - 如何在同一张图上获得多个系数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35051209/

相关文章:

java - 我遇到过的最奇怪的错误

c# - 在窗体区域外绘图时如何重绘

stata - 使不平衡的面板与缺失的观察结果保持平衡

matlab - Matlab 中的 3D 堆积条

matlab - 使单击 MATLAB 绘图标记绘制子图

r - 如何使用彩色置信区间带绘制回归原始比例的回归图?

r - 只是 ggplot2 中的地毯(情节)?备择方案?

c - 绘制实心圆的快速算法?

stata - 在Stata中按组标准化变量

stata - .ado 文件中的 Mata