Table formatting¶
Style guides¶
-
-
Columns must be in vertical (or portrait) orientation.
-
Tables must be no more than 9 columns wide including row headings.
-
Number your tables consecutively with Arabic numerals.
-
Use only horizontal lines and additional blank space to show space distinction.
-
Do not use asterisks to denote significance of estimation results. Report the standard errors in parentheses.
-
Place source note, if any, after other notes related to the table.
-
Include full citations of sources in the references.
-
-
Number: The table number (e.g., Table 1) appears above the table title and body in bold font. Number tables in the order in which they are mentioned in your paper.
Table borders: Limit the use of borders or lines in a table to those needed for clarity. In general, use a border at the top and bottom of the table, beneath column headings (including decked heads), and above column spanners. You may also use a border to separate a row containing totals or other summary information from other rows in the table. Do not use vertical borders to separate data, and do not use borders around every cell in a table. Use spacing between columns and rows and strict alignment to clarify relations among the elements in a table.
Table formatting with R¶
Table generator¶
modelsummary¶
-
Model Summaries โ modelsummary: Data and Model Summaries in R
-
modelsummary โ modelsummary: Data and Model Summaries in R
Community guides:
stargazer¶
Template:
stargazer(
model_1, model_2,
# dep.var.labels = "DEPENDENT_VARIABLE_NAME",
# column.labels = c("COLUMN_1", "COLUMN_2"),
# covariate.labels = "COVARIATE",
# add.lines = list(
# c("XXX FE", "Yes", "Yes"),
# c("Mean DV", xxx, xxx)
# ),
# keep.stat = c("n", "rsq"),
# omit.stat = c(),
# table.layout = "t"
# omit.table.layout = "n",
header = FALSE,
style = "aer",
type = "latex"
float = FALSE,
) |> writeLines(
"../output/tables/xxx.tex"
)
Documentation:
Tutorials:
- RPubs - Stargazer Tutorial
- A Hands on R tutorial - Using Stargazer to make publication-quality tables
- Stargazer
Table layout characters:
-
stargazer_table_layout_characters function - RDocumentation
"-" single horizontal line "=" double horizontal line "-!" mandatory single horizontal line "=!" mandatory double horizontal line "l" dependent variable caption "d" dependent variable labels "m" model label "c" column labels "#" model numbers "b" object names "t" coefficient table "o" omitted coefficient indicators "a" additional lines "n" notes "s" model statistics
Statistics:
-
stargazer_stat_code_list function - RDocumentation
"all" all statistics "adj.rsq" adjusted R-squared "aic" Akaike Information Criterion "bic" Bayesian Information Criterion "chi2" chi-squared "f" F statistic "ll" log-likelihood "logrank" score (logrank) test "lr" likelihood ratio (LR) test "max.rsq" maximum R-squared "n" number of observations "null.dev" null deviance "Mills" Inverse Mills Ratio "res.dev" residual deviance "rho" rho "rsq" R-squared "scale" scale "theta" theta "ser" standard error of the regression (i.e., residual standard error) "sigma2" sigma squared "ubre" Un-Biased Risk Estimator "wald" Wald test
Bugs:
-
Issue with stargazer package after update to R 4.2.0 : r/rstats
-
Quick fix for stargazer <= 5.2.3 is.na() issue with long model names in R >= 4.2
tinytable¶
textreg¶
TBD
knitr::kable()¶
TBD
xtable¶
TBD
gt¶
Table formatter¶
kableExtra¶
Table formatting with Stata¶
estout¶
#delimit ;
esttab
<model_list>
using "../output/TABLE-NAME.tex",
mgroups("GROUP-1" "GROUP-2", pattern(1 0 ... 1 0 ...) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span}))
mtitles("MODEL-1" "MODEL-2" ...)
keep(
<var_1>
<var_2>
...
)
varlabels(
1.is_ca#1.post "CA $\times$ Post"
1.is_ca#1.post#1.mshs "CA $\times$ Post $\times$ MSHS"
1.is_ca#1.post#1.ms "CA $\times$ Post $\times$ MS"
)
stats(
<stat> ... mean_dep N_fmt r2,
labels("STAT-LABEL" ... "Mean dep. var." "Observations" "$ R^{2} $")
fmt(0 ... 3 0 3)
)
label
se nostar
b(3) se(3)
transform(@*1 1)
booktabs
nonotes
replace;
#delimit cr
outreg2¶
tabout¶
Exporting scalars¶
output_file <- "../output/scalars.tex"
con <- file(output_file, "w")
cat("% Generated by SCRIPT_NAME\n\n", file = con)
export_scalar_to_latex_macro <- function(name) {
value = get(name)
value = format(value, big.mark = ",", scientific = FALSE)
cat(sprintf("\\newcommand{\\%s}{%s}\n", name, value), file = con)
}
variables <- c(
# list your variables here
)
lapply(variables, export_scalar_to_latex_macro)
close(con)