2
votes

Take this code

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

This outputs

    (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  

Ideally, I'd like it to display the value labels, as is done in the console's regression output:

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

I don't need any of the other stats at the moment; I'm strictly including that last piece of output to show what I mean with the value labels. Searching through the documentation for outreg2 tells me how to display variable labels, but not value labels.

Also posted on Statalist.

2
Have you considered switching to estout?dimitriy
@DimitriyV.Masterov Does estout support doing this automatically? I've seen Statalist posts that describe writing code to do this manually, but since regress already does this automatically, I'm hoping to find a solution that does the same.Michael A

2 Answers

3
votes

As @Dimitriy points out, you can use estout, from SSC. An example:

sysuse auto, clear

reg price mpg c.mpg#i.foreign

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

You can add other statistics, stars and more. After installation (ssc install estout), read patiently help estout.

0
votes

If you decode your variables and use xi, it will do the trick. Of course this solution assumes that you recode your variables, but if you want to stick with outreg2 is an easy solution.

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

I used the example you asked in Statalist as it was your latest question.