Search code examples
formattingformatoutputdecimalstata

Change decimal places of columns instead of rows in esttab


I know I can use the b() option in the community-contributed command esttab to control the number of decimal points displayed in the rows (i.e. the regressors):

estimates clear
eststo clear
sysuse auto, clear

eststo w1: regress price mpg trunk length
eststo w2: regress turn mpg trunk length
eststo w3: regress displacement mpg trunk length

esttab, b(1 3 5)

All of the decimal points in the first row (mpg) have one decimal point. The second and third rows have three and five decimal points.

However, instead of controlling the decimal points by row, I want to control the number of decimal points by column (model).

Is there a way to do this?

For example, I want all of the regressors in the first column to have one decimal point, all of the regressors in the second column to have three decimal points, and all of the regressors in the third column to have five decimal points.


Solution

  • You cannot do this directly but a workaround is to use a matrix.

    A simple example is the following:

    matrix A = ( -173.70800, -0.06556, -1.77658 \    ///
                 -0.85469, -0.05926, 0.06587 \       ///
                  21.40414, 0.16548, 3.06799 \       ///
                  5853.99300, 10.76202, -342.34697 )
    
    matrix rownames A = mpg trunk length _cons  
    
    esttab matrix(A, fmt(1 3 5)), gaps mlabel(none) ///
    collabels("price" "turn" "displacement")
    
    ---------------------------------------------------
                        price         turn displacement
    ---------------------------------------------------
    mpg                -173.7       -0.066     -1.77658
    
    trunk                -0.9       -0.059      0.06587
    
    length               21.4        0.165      3.06799
    
    _cons              5854.0       10.762   -342.34697
    ---------------------------------------------------