【问题标题】:How to get multiple coefficients on same graph如何在同一张图上获得多个系数
【发布时间】:2016-01-28 01:13:15
【问题描述】:

在 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)

当我只想要一个图时,这会产生三个单独的图。我需要做什么才能做到这一点?我想要的是有一个带有来自mpgt1)、truckt2)和weightt3)的系数的图都绘制在同一个图上。最好知道如何在标记这些系数 mpg, truck, weightt1, t2, t3 之间切换。

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

【问题讨论】:

    标签: plot graphics stata coefficients


    【解决方案1】:

    注意: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)
    

    除了通常的help,还请查看命令作者 Ben Jann 的 this document

    【讨论】:

    • 超级!有没有办法将系数标记为t1t2t3,而不是Mileage (mpg) 等?
    • 是的。检查coeflabels()asequation 选项。
    • 谢谢!我发现这种组合可以解决问题:asequation swapnames noeqlabels.
    猜你喜欢
    • 1970-01-01
    • 2023-01-12
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 2023-01-31
    • 1970-01-01
    相关资源
    最近更新 更多