Search code examples
formatstatatabular

Formatting Table Using esttab


I am able to create most of what I want: two oneway tabulations (reporting cumulative percentages) side-by-side in the same table. This is well and good, but I need some help with the formatting. A toy example:

sysuse auto, clear
eststo clear
eststo a: estpost tabulate rep78 if foreign==0
eststo b: estpost tabulate rep78 if foreign==1
esttab, cells("cumpct(fmt(2))") ///
    varlabels("a" "b")      ///
    nonumber nomtitle noobs ///
    collabels("a" "b")

This produces the following:

--------------------------------------
                        a            a
--------------------------------------
1                    4.17             
2                   20.83             
3                   77.08        14.29
4                   95.83        57.14
5                  100.00       100.00
Total                                 
--------------------------------------

How can I:

  1. Get rid of the total line and
  2. Make the column labels different names? I would like the second column to be called b, not a. I played around with different variations of the contents inside collabels (a b, "a b", ""a" "b""), but nothing seems to work.

Solution

  • Either one of these should do the trick:

    sysuse auto, clear
    eststo clear
    qui eststo a: estpost tabulate rep78 if foreign==0
    qui eststo b: estpost tabulate rep78 if foreign==1
    esttab, cells("cumpct(fmt(2))") ///
        nonumber mtitles("a" "b") nodepvars noobs drop(Total) collabels(none)
    
    eststo clear
    qui eststo a, title("a"): estpost tabulate rep78 if foreign==0
    qui eststo b, title("b"): estpost tabulate rep78 if foreign==1
    esttab, cells("cumpct(fmt(2))") ///
        nonumber mtitles nodepvars noobs drop(Total) collabels(none)
    

    I prefer the second syntax, since I like to name models near where I estimate them.

    Both will produce something that looks like:

    --------------------------------------
                            a            b
    --------------------------------------
    1                    4.17             
    2                   20.83             
    3                   77.08        14.29
    4                   95.83        57.14
    5                  100.00       100.00
    --------------------------------------