5

我正在使用coefplotStata 中的包来绘制系数如何根据所采用的模型而变化。特别是,我想看看兴趣系数如何随时间变化。我将其垂直绘制,因此 x 轴可以显示每个系数所指的年份。但是,我无法相应地标记 x 轴(而不是显示我感兴趣的变量的名称x1,它应该说明 1、2 和 3。我还想通过使用选项省略图例,legend(off)但是不起作用。

这是我正在使用的代码:

reg y x1 x2 if year==1;
estimates store t1;

reg y x1 x2 if year==2;
estimates store t2;

reg y x1 x2 if year==3;
estimates store t3;

coefplot t1 t2 t3, drop(x2) vertical yline(0);

任何建议将不胜感激。

4

1 回答 1

5

一个使用两个类别(而不是时间)的荒谬示例可以很容易地适应:

clear
set more off

sysuse auto

reg price weight rep78 if foreign
estimates store foreign

reg price weight rep78 if !foreign
estimates store not_foreign

matrix at = (1 / 2)

coefplot foreign || not_foreign, drop(rep78 _cons) vertical bycoefs

您可以使用local. 然后喂给coefplot. 准确地说,我的意思是类似于示例语法:

year1 || year2 || ... || yearn

最终命令看起来像:

coefplot `allyears', drop(<some_stuff>) vertical bycoefs

一个涉及时间的完整示例:

clear
set more off

use http://www.stata-press.com/data/r12/nlswork.dta

forvalues i = 70/73 {
    regress ln_w grade age if year == `i'
    estimates store year`i'
    local allyears `allyears' year`i' ||
    local labels `labels' `i'
}

// check
display "`allyears'"
display `"`labels'"'

coefplot `allyears', keep(grade) vertical bycoefs bylabels(`labels')

如果coefplot结果不够灵活,您可以随时尝试使用statsbygraph命令 ( help graph)。

于 2015-10-11T21:17:21.957 回答