*! version 3.3 2022-05-05

help for table1_mc

Title

table1_mc -- Create "Table 1" of baseline characteristics for a manuscript

Syntax

table1_mc [if] [in] [weight], vars(var_spec) [options]

var_spec = varname vartype [%fmt1 [%fmt2]] [ \ varname vartype [%fmt1 [%fmt2]] \ ...]

where vartype is one of:

contn - continuous, normally distributed (mean and SD will be reported)
contln - continuous, log normally distributed (geometric mean and GSD reported)
conts - continuous, neither log normally or normally distributed (median and IQR reported)
cat - categorical, groups compared using Pearson's chi-square test
cate - categorical, groups compared using Fisher's exact test
bin - binary (0/1), groups compared using Pearson's chi-square test
bine - binary (0/1), groups compared using Fisher's exact test

fweights are allowed; see weight

#Columns/Rows
by(varname) group observations by varname, which must be either (i) string, or (ii) numeric and contain only non-negative integers, whether or not a value label is attached

total(before|after) include a total column before/after presenting by group

onecol report categorical variable levels underneath variable name instead of in separate column

missing for categorical variables (cat and cate) treat missing values as another category

test include column describing the significance test used

statistic include column describing the value of the test statistic

pairwise123 report pairwise comparisons (unadjusted for multiple comparisons) between first 3 groups

Contents of Cells
format(%fmt) default display format for continuous variables

percformat(%fmt) default display format for percentages for categorical/binary variables

nformat(%fmt) display format for n and N; default is nformat(%12.0fc)

iqrmiddle("string") allows for e.g. median (Q1, Q3) using iqrmiddle(", ") rather than median (Q1-Q3)

sdleft("string") allows for e.g. mean±sd using sdleft("±") rather than mean (SD)

sdright("string") allows for e.g. mean±sd using sdright("") rather than mean (SD)

gsdleft("string") allows for presentation other than: geometric_mean (×/geometric_SD)

gsdright("string") allows for presentation other than: geometric_mean (×/geometric_SD)

percsign("string") default is percsign("%"); consider percsign("")

nospacelowpercent report e.g. (3%) instead of the default ( 3%), [the default can look nice if output is right/left justified]

extraspace helps alignment of p-values and ( 3%) in .docx file if non-monospaced datafont (e.g. Calibri - the default) used with the accompanying command table1_mc_dta2docx

percent report % rather than n (%) for categorical/binary vars

percent_n report % (n) rather than n (%) for categorical/binary vars

slashN report n/N instead of n for categorical/binary vars

catrowperc report row percentages rather than column percentages for categorical vars (but not binary vars)

pdp(#) max number of decimal places in p-value when p-value < 0.10; default is pdp(3)

highpdp(#) max number of decimal places in p-value when p-value ≥ 0.10; default is highpdp(2)

gurmeet equivalent to specifying: percformat(%5.1f) percent_n percsign("") iqrmiddle(",") sdleft(" [±") sdright("]") gsdleft(" [×/") gsdright("]") onecol extraspace

Output
saving(filename [, export_excel_options]) save table to Excel file

clear replace the dataset in memory with the table

Description

table1_mc generates a "Table 1" of characteristics for a manuscript. Such a table generally
includes a collection of baseline characteristics which may be either continuous or categorical. The
observations are often grouped, with a "p-value" column on the right comparing the characteristics
between groups.

The vars option is required and contains a list of the variable(s) to be included as
rows in the table. Each variable must also have a type specified (contn, contln, conts, cat,
cate, bin or bine - see above). If the observations are grouped using by(), a
significance test is performed to compare each characteristic between groups. contln and contn variables
are compared using ANOVA (with and without log transformation of positive values respectively)
[equivalent to an independent t-test when 2 groups],
conts variables are compared using the Wilcoxon rank-sum (2 groups)
or Kruskal-Wallis (>2 groups) test, cat and bin variables are compared using Pearson's
chi-square test, and cate and bine variables are compared using Fisher's exact test.
Specifying the test option adds a column to the table describing the test used.
And specifying the statistic option adds a column to the table describing the value of the test statistic.
pairwise123 reports p-values from applying those same tests between 2 groups.

The display format of each variable in the table depends on the variable type. For a continuous
variable the default display format is the same as that variable's current display format. You can
change the table's default display format of summary statistics for continuous variables using the format() option.
After each variable's type you may
optionally specify a display format to override the table's default by specifying %fmt1.
Specification of %fmt2 also, will affect the display format of IQR/SD/geometric SD.
For categorical/binary variables the default is to
display the column percentage using either 0 or 1 decimal place depending on the total frequency. You
can change this default using the percformat() option.

The default times-divide symbol for the geometric SD (Kirkwood 1979)
is very similar to that proposed by Limpert & Stahel (2011).

The underlying results table can be (i) saved to an Excel file using the saving() option, and/or
(ii) kept in memory, replacing the original dataset, using the clear option.
If (ii), the table can -with Stata 15.1 or later- be saved into a .docx file
using the command table1_mc_dta2docx.

Remarks

Stata 18 introduced the dtable command, and Stata 17 introduced a massively revised and expanded table command.
Both offer much flexibility, though table1_mc is much easier to use and read about.

table1_mc is an extension and modification of Phil Clayton's table1 command.

Other user written commands that do similar things include:

baselinetable ... very nice, but no p-values. Can use any statistics from summarise, can't report geometric mean and geometric SD.

tabout ... http://tabout.net.au/docs/home.php

sumtable ... two stats in two (not one) columns, generally not as flexible, no p-values

partchart ... quite similar but strangely doesn't seem to express IQR as (Q1-Q3), reporting instead the difference between the two quartiles

tabxml ... survey data frequencies and/or % for categorical variables, means and SE / CI for continuous variables. To avoid matsum error message: . net install sg100, from(http://www.stata.com/stb/stb47)

basetable ... "can be used for survey analysis". Nice, can do 95% CIs for each group.
Can save in various styles e.g. Latex. Stata Journal 2022; 22: 416-429.

See also http://blog.stata.com/2017/04/06/creating-excel-tables-with-putexcel-part-3-writing-custom-reports-for-arbitrary-variables/

While table1_mc does not report an effect size (e.g. differences in means, medians or proportions) & associated 95% CI for a variable when there are 2 (or more) groups, users might consider calculating and reporting these also.

Examples

. sysuse auto, clear

. generate much_headroom = (headroom>=3)

. table1_mc, by(foreign) vars(weight contn %5.0f \ price contln %5.0f %4.2f \ mpg conts %5.0f \ rep78 cate \ much_headroom bin) onecol nospace

To save a resulting table as an .xlsx file

. cd "H:\" (or whichever directory you want to save to)

. `"table1_mc, by(foreign) vars(weight contn %5.0f \ price contln %5.0f %4.2f \ mpg conts %5.0f \ rep78 cate \ much_headroom bin) onecol test statistic saving("example Table 1.xlsx", replace)"'

To save a resulting table in a .docx file [Stata 15.1 required]

Use the clear option of table1_mc together with the command table1_mc_dta2docx:

. sysuse auto, clear

. preserve

. table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate) onecol extraspace test statistic clear

Note the use of the clear option above, which overwrites the data in memory with the summary table
hence the use of preserve and restore

. cd "H:\" (or whichever directory you want to save to)

. `"table1_mc_dta2docx using "example Table 1.docx", replace landscape"'

. restore

References

Kirkwood TBL. Geometric means and measures of dispersion. Biometrics 1979; 35: 908–909.

Limpert E, Stahel WA. Problems with Using the Normal Distribution – and Ways to Improve Quality and Efficiency of Data Analysis. PLoS ONE. 2011;6(7):e21403. doi:10.1371/journal.pone.0021403.

table1 - Phil Clayton, ANZDATA Registry, Australia.

Author

Mark Chatfield, The University of Queensland, Australia.

m.chatfield@uq.edu.au