1
votes

I'm trying to create a table showing the difference in means of two groups but I'm struggling to get exactly the right columns. I'm specifically trying to recreate a table that includes a column indicating N. I'm really confused how I would go about doing this. Here's the code for the bulk of the kind of table I'm talking about:

sysuse auto, clear

eststo all: quietly estpost summarize ///
    price mpg weight headroom trunk
eststo domestic: quietly estpost summarize ///
    price mpg weight headroom trunk if foreign == 0
eststo foreign: quietly estpost summarize ///
    price mpg weight headroom trunk if foreign == 1
eststo diff: quietly estpost ttest ///
    price mpg weight headroom trunk, by(foreign) unequal

esttab all domestic foreign diff, ///
cells("mean(pattern(1 1 1 0) fmt(2)) b(star pattern(0 0 0 1) fmt(2))" "sd(pattern(1 1 1 0) par fmt(2)) t(pattern(0 0 0 1) par fmt(2))") ///
label

In this scenario, I want a column N that just lists 74 in each row. In this shortened example, it doesn't make much sense but I'm using multiple data sources with the same variables and I want to stack the difference in means tables together.output

1
The difficulty is that your example doesn't seem to be an example of what you are trying to do.Arthur Morris

1 Answers

0
votes

You can reference the number of observations in each subsample (in this case by(foreign)) using N_1 and N_2 as follows:

 sysuse auto, clear

estpost ttest price mpg weight headroom trunk, by(foreign)

esttab . , ///
cell(( N_2(fmt(%12.0fc)) mu_2(fmt(%12.3fc)) ///
       N_1(fmt(%12.0fc)) mu_1(fmt(%12.3fc)) ///
       b(fmt(%12.3fc)) t(fmt(%12.2fc)) )) ///
noobs label collabels(Count Mean Count Mean Diff T-Stat )