在coefplot中分配不同的标签

时间:2018-11-03 21:46:17

标签: stata

我已经执行了以下代码段:

foreach yr in 2000 2001 2002 2003 2004 2005 2006 {
    eststo: ivregress 2sls y (var=z) c [aw=w] if yr==`yr'
    estimate store r`yr'
}

coefplot r2000 r2001 r2002 r2003 r2004 r2005 r2006 , vertical keep(var)

这产生了下图:

enter image description here

但是,我想将x-axis中的标签更改为20002001,...,2006

如您所见,我使用的是 community-contributed 命令coefplot,但是这些系数来自单独的回归分析,而20002001不是变量名称。

有什么办法可以解决这个问题?

1 个答案:

答案 0 :(得分:1)

使用Stata的auto玩具数据集:

sysuse auto, clear
recode foreign (0 = 1) (1 = 2)

forvalues i = 1 / 2 {
    eststo: regress mpg price if foreign == `i'
    estimate store r`i'
}

以下是技巧:

coefplot (r1 \ r2), vertical keep(price) aseq swapnames

enter image description here

或带有自定义标签:

coefplot (r1, aseq(Foreign 1) \ r2, aseq(Foreign 2)), vertical keep(price) swapnames

enter image description here