Esttab’s website provides a way of outputting results from ttest but there is no option to include the means of each group separately, only the difference between them.

Using a combination of estpost and estadd I have come up with a way of also including the means of each group in the table.

You can actually use this system to include any other summary statistic you may want in the table.

See the code below.

* use Stata’s dataset auto

sysuse auto

* the goal here is to build a table with two-sample mean-comparison tests for price, mpg and headroom by foreign;

* if you just want differences to be displayed in the table run:

estpost ttest price mpg headroom trunk, by(foreign) esttab , noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) /// collabels("Diff." "Std. Error" "Obs.")

* if you instead also want the means of each group to be displayed, you need some extra steps:

* save summarize results for foreign==1 to an e-list using estpost

estpost sum price mpg headroom trunk if foreign==1

* save the matrix that stores the means e(mean) as matrix meanf1

matrix meanf1=e(mean) matrix list meanf1

* save summarize results for foreign==0 to an e-list using estpost

estpost sum price mpg headroom trunk if foreign==0

* save the matrix that stores the means e(mean) as matrix meanf0

matrix meanf0=e(mean) matrix list meanf0

* save ttest results to an e-list using estpost

estpost ttest price mpg headroom trunk, by(foreign)

* add the two matrices containing the means to ttest’s e-list

estadd matrix meanf1 estadd matrix meanf0

* now e-list contains the matrices e(meanf1) and e(meanf0) and you can add them in the cells option of esttab

esttab , noobs cells("meanf1(fmt(4)) meanf0(fmt(4)) b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.1 ** .05 *** 0.01) /// collabels("Mean(Foreign=1)" "Mean(Foreign=0)" "Diff." "Std. Error" "Obs.")

Here’s the output.