benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

how to modify the lables of the equations? #45

Closed fredericky123 closed 2 years ago

fredericky123 commented 2 years ago

I want to replace the labels of the equations to be 1, 2, and 3... how to do this?

sysuse auto,clear

eststo clear

estpost corr price mpg rep78 trunk weight,matrix

esttab using "corr1.rtf", replace cells("b(fmt(3) star)") nonumbers noobs nomtitle not nogaps unstack label eqlabels(,none) compress 

image

I also want to supress the correlations 1 (the correlations of the variable itself), can we?

NilsEnevoldsen commented 2 years ago
  1. You should avoid the cells() option with esttab when possible. esttab is a wrapper for estout, and will construct the appropriate estout, cells() call for you. In fact, you can add the option noisily to see the exact estout command that esttab creates. If you add the esttab option b(3) with noisily, you will see that you get estout , cells(b(fmt(3) star)) automatically. You can use cells() if you want, but you will be overwriting some of the smarts that esttab provides.
  2. You want to label equations as "1 2 3 4 5", but you have specified eqlabels(,none). Specify eqlabels(1 2 3 4 5) instead.
  3. Suppressing the self-correlations is really a job for corr rather than estout, but that doesn't appear to be an option for corr.
benjann commented 2 years ago

Like Nils indicated, the equation labels can be set as follows:

. sysuse auto, clear
. estpost corr price mpg rep78 trunk weight,matrix
. esttab ., b(3) nonumbers noobs nomtitle not nogaps unstack label compress eqlab(1 2 3 4 5)

---------------------------------------------------------------------------------
                         1            2            3            4            5   
---------------------------------------------------------------------------------
Price                1.000                                                       
Mileage (mpg)       -0.469***     1.000                                          
Repair reco~1978     0.007        0.402***     1.000                             
Trunk spa.. ft.)     0.314**     -0.582***    -0.157        1.000                
Weight (lbs.)        0.539***    -0.807***    -0.400***     0.672***     1.000   
---------------------------------------------------------------------------------
* p<0.05, ** p<0.01, *** p<0.001

To get rid of the correlations with itself you can use the drop() option:

. esttab ., b(3) nonumbers noobs nomtitle not nogaps unstack label compress eqlab(1 2 3 4) drop(price:price mpg:mpg trunk:trunk weight:weight)

--------------------------------------------------------------------
                         1            2            3            4   
--------------------------------------------------------------------
Mileage (mpg)       -0.469***                                       
Repair reco~1978     0.007        0.402***     1.000                
Trunk spa.. ft.)     0.314**     -0.582***    -0.157                
Weight (lbs.)        0.539***    -0.807***    -0.400***     0.672***
--------------------------------------------------------------------
* p<0.05, ** p<0.01, *** p<0.001

But probably you will want to label the equations differently in this case...

fredericky123 commented 2 years ago

Thanks @benjann ! If esttab can have an option to drop all correlations with itslef, that will be great; for the reason that usually we have a lot of control variables. listing all variables in "drop(price:price mpg:mpg trunk:trunk weight:weight)" seems to be redundant

benjann commented 2 years ago

I am reluctant to add such an option because it is very specific. My suggestion would be to use code such as the following:

. local xvars price mpg rep78 trunk weight
. sysuse auto, clear
. estpost corr `xvars', matrix
. local drop
. foreach x of local xvars {
       local drop `drop' `x':`x'
  }
. esttab ., b(3) nonumbers noobs nomtitle not nogaps unstack label compress eqlab(1 2 3 4) drop(`drop')

--------------------------------------------------------------------
                         1            2            3            4   
--------------------------------------------------------------------
Mileage (mpg)       -0.469***                                       
Repair reco~1978     0.007        0.402***                          
Trunk spa.. ft.)     0.314**     -0.582***    -0.157                
Weight (lbs.)        0.539***    -0.807***    -0.400***     0.672***
--------------------------------------------------------------------
* p<0.05, ** p<0.01, *** p<0.001

Or define a little program

capt program drop dropdiag
program dropdiag, rclass
    local varlist: coln e(b)
    local varlist: list uniq varlist
    foreach x in `varlist' {
        local drop `drop' `x':`x'
    }
    return local drop `"`drop'"'
end

and use it as follows:

. sysuse auto, clear
. estpost corr price mpg rep78 trunk weight, matrix
. dropdiag
. esttab ., b(3) nonumbers noobs nomtitle not nogaps unstack label compress eqlab(1 2 3 4) drop(`r(drop)')

--------------------------------------------------------------------
                         1            2            3            4   
--------------------------------------------------------------------
Mileage (mpg)       -0.469***                                       
Repair reco~1978     0.007        0.402***                          
Trunk spa.. ft.)     0.314**     -0.582***    -0.157                
Weight (lbs.)        0.539***    -0.807***    -0.400***     0.672***
--------------------------------------------------------------------
* p<0.05, ** p<0.01, *** p<0.001
fredericky123 commented 2 years ago

Thanks so much, the local function is elegant enough!