Move N= in Stata 18’s dtable

By default, the dtable command places the sample size in its own row:

. sysuse auto, clear
(1978 automobile data)

. dtable mpg, by(foreign)

----------------------------------------------------------
                               Car origin
                 Domestic        Foreign         Total
----------------------------------------------------------
N                 52 (70.3%)     22 (29.7%)    74 (100.0%)
Mileage (mpg) 19.827 (4.743) 24.773 (6.611) 21.297 (5.786)
----------------------------------------------------------

We can use the following two additional options to relocate it:


. dtable mpg, by(foreign) ///
>             sample(, statistics(freq) place(seplabels)) ///
>             sformat("(N=%s)" frequency)

----------------------------------------------------------
                               Car origin
                 Domestic        Foreign         Total
                  (N=52)         (N=22)         (N=74)
----------------------------------------------------------
Mileage (mpg) 19.827 (4.743) 24.773 (6.611) 21.297 (5.786)
----------------------------------------------------------

The sample() option chooses which sample-level characteristics to report with statistics(freq), and the place() suboption choses their location:

The sformat() option formats a particular type of reported results (in this case, “frequency”) with a given string.

Home | Back to blog