如何使用outreg2在其输出中显示值标签?

时间:2015-04-16 15:54:46

标签: stata

拿这个代码

sysuse auto, clear
reg price mpg c.mpg#i.foreign
outreg2 using "example.txt", stats(coef) replace

此输出

    (1)
VARIABLES    price

price    
mpg    -329.0***
0b.foreign#co.mpg    0
1.foreign#c.mpg    78.33**
Constant    12,596***

Observations    74
R-squared    0.289
Standard errors in parentheses    
*** p<0.01, ** p<0.05, * p<0.1  

理想情况下,我希望显示值标签,就像在控制台的回归输出中所做的那样:

-------------------------------------------------------------------------------
        price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
          mpg |  -329.0368   61.46843    -5.35   0.000    -451.6014   -206.4723
              |
foreign#c.mpg |
     Foreign  |   78.32918   29.78726     2.63   0.010     18.93508    137.7233
              |
        _cons |   12595.97   1235.936    10.19   0.000     10131.58    15060.35
-------------------------------------------------------------------------------

我现在不需要任何其他统计数据;我严格包括最后一段输出,以显示我对值标签的含义。搜索outreg2的文档告诉我如何显示变量标签,而不是 value 标签。

另外posted on Statalist

2 个答案:

答案 0 :(得分:3)

正如@Dimitriy所指出的,你可以使用来自SSC的estout。一个例子:

sysuse auto, clear

reg price mpg c.mpg#i.foreign

estimates store m1, title(Model 1)
estout m1, label

您可以添加其他统计信息,星标等。安装完成后(ssc install estout),耐心阅读help estout

答案 1 :(得分:0)

如果您解码变量并使用xi,它就可以解决问题。当然,这个解决方案假定您重新编码变量,但如果您想坚持使用outreg2则是一个简单的解决方案。

sysuse auto, clear
set seed 1234
gen maxspeed = round(uniform()*3)+1
label define speed 1 "Light" 2 "Ridiculous" 3 "Ludicrous" 4 "Plaid"
label values maxspeed speed
decode maxspeed, gen(maxspeed_str)
decode foreign, gen(foreign_str)
xi: reg price mpg weight i.foreign_str*i.maxspeed_str

outreg2 using test, see text label

我使用了你在Statalist中提到的例子,因为这是你最新的问题。

相关问题