Search code examples
stata

Rename columns in esttab


Consider the following toy example using the community-contributed command esttab:

sysuse auto, clear
estpost tabstat  mpg price, statistics(count mean) columns(statistics) listwise 
esttab . , title("summary stats") cells("count(fmt(%5.0f)) mean(fmt(%5.0f))")

summary stats
--------------------------------------
                      (1)             

                    count         mean
--------------------------------------
mpg                    74           21
price                  74         6165
--------------------------------------

How can I change the column name from count to N?


Solution

  • Use the collabels() option:

    sysuse auto, clear
    
    estpost tabstat  mpg price, statistics(count mean) columns(statistics) listwise 
    
    esttab . , title("summary stats") collabels("N" "Mean") ///
               cells("count(fmt(%5.0f)) mean(fmt(%5.0f))")
    
    summary stats
    --------------------------------------
                          (1)             
    
                            N         Mean
    --------------------------------------
    mpg                    74           21
    price                  74         6165
    --------------------------------------
    N                      74             
    --------------------------------------