Stata:仅存储部分 FE 回归输出用于绘图

Stata: Storing only part of a FE regression output for graphing

我是运行一个有两个固定效应类别(国家和年份,是经济宏观数据)的回归。由于我用的是xtreg,一个是autohid,另一个是变量:

xtreg fiveyearyg taxratio i.year if taxratiocut == 1,  i(wbcode1) fe cluster(wbcode1)
estimates store yi

我有 运行 个,我想绘制每个 taxratio 的系数图。但是当我存储数据时,它存储了 taxratio 系数和 year 固定效应的 50+ 系数。

经过大量搜索,我找不到任何方法来存储(或调用)回归输出的一部分,即我关心的一个系数(带有 SE)。有谁知道这样做的方法吗?

这里是你如何做到的:

webuse grunfeld,clear
qui xtreg mvalue invest i.year,fe cluster(company)

//e(b)存储系数矩阵,e(V)存储方差-协方差矩阵。有关详细信息,请键入:ereturn list 在 运行 模型

之后

//假设您只想提取投资系数

mat coef_matrix=e(b)
scalar coef_invest=coef_matrix[1,1]
dis coef_invest 
1.7178414

//提取投资系数的se

mat var_matrix=e(V)
mat diag_var_matrix=vecdiag(var_matrix) //diagonal elements are variances and the standard errors are square roots of these variances
matmap diag_var_matrix se_matrix , m(sqrt(@))) //you need to install matmap using ssc install matmap, you will get error if variance is negative
scalar se_invest=se_matrix[1,1] 
dis se_invest
.14082153

访问系数就像调用_b[varname]一样简单;类似地对应的标准误差:_se[varname]

一个例子:

webuse grunfeld, clear

qui xtreg mvalue invest i.year,fe cluster(company)

// coef for invest
display _b[invest]

// std error for invest
display _se[invest]

// displayed results in matrix
matrix list r(table)

对于多方程模型,使用 [eqno]_b[varname],其中前面的括号包含方程编号。

可以在 [U] 13.5 Accessing coefficients and standard errors 中找到更多详细信息。

从 Stata 12 开始,估计命令还将结果存储在 r() [而不仅仅是 e()] 中。请注意,我列出了 r(table),其中包含估计命令 xtreg.

显示的大部分结果

您对绘制系数很感兴趣,因此您应该阅读用户编写的命令 coefplot。 运行 ssc install coefplot 下载并 help coefplot 开始。它有很多选项。

编辑

仅绘制 invest 的系数(忽略 year 的系数)、使用 coefplot 并基于条件回归的完整示例是:

clear
set more off

webuse grunfeld

xtreg mvalue invest i.year if time <= 10,fe cluster(company)
estimates store before10

xtreg mvalue invest i.year if time > 10,fe cluster(company)
estimates store after10 

coefplot before10 after10, keep(invest)