LaTeX Tables
Generate publication-ready LaTeX tables that come out of code (esttab, modelsummary, pyfixest.etable, stargazer) and \input{} cleanly into the paper. The default style follows DIME's "full replicability" tier: no manual editing between code and PDF.
Operating Principles
- Tables are produced, never typed. DIME identifies four levels of replicability: full, good, basic, and none. "None" (copy-paste from a console window) is unacceptable for any output that leaves the analyst. Default to full: code writes a
.tex file that the paper \input{}s directly.
- One source of truth per table. Every numeric cell, star, sample size, and footnote comes from the same script that ran the regression. Never edit the
.tex file by hand — re-run the script and rebuild the paper.
booktabs styling. Three horizontal rules (\toprule, \midrule, \bottomrule), no vertical lines, consistent decimal alignment via siunitx S columns when precision matters.
- Notes via
threeparttable. Significance levels, standard-error type, sample restrictions, and clustering belong in a single notes block at the bottom — not in the caption.
- Cross-reference with
\Cref{}. \label{tab:main} + \Cref{tab:main} reads "Table 2" in body text and behaves correctly at sentence start.
Decision Policy
This skill follows the repo-wide Agent Policy.
ASK before proceeding (blocking):
- Source language of the regression (Stata / R / Python) — determines the canonical table package.
- Table type (regression / summary stats / balance / multi-panel / DiD-estimator comparison).
- Standard-error type and cluster level (these belong in the table notes).
- Output target (LaTeX
.tex, Word .rtf, Excel .xlsx).
DEFAULT + flag (use this default; tell the user how to override):
esttab (Stata), modelsummary or fixest::etable (R), pyfixest.etable or stargazer (Python).
booktabs styling: \toprule, \midrule, \bottomrule; no vertical lines.
- Three-star convention
* 0.10 ** 0.05 *** 0.01; pin once per paper.
threeparttable for the notes block.
- Output path
paper/tabs/<name>.tex; the paper \input{}s it.
- Within-R² (
r2_within) reported instead of overall R² for FE models.
DOCUMENT and proceed (write into the decisions log of the table-generating script):
- The estimating equation, sample, cluster level, and FE included for each column.
- Variable label mapping (
coef_map / coeflabels).
- Any subsample restriction shown in a column.
PROCEED items: tables produced by code (never copy-paste); generated .tex never hand-edited; rebuild path runs the table script before LaTeX.
Pre-flight Checklist
Before generating code, confirm with the user — and write the answers in the script header:
- Source language. Stata, R, or Python? (Each has its own canonical table package.)
- Table type. Regression (multi-spec), summary statistics, balance / difference-in-means, descriptive cross-tabs, or model-comparison panel?
- Sample. Single or stratified? If panel, which fixed effects are on/off across columns?
- Standard errors. Cluster-robust at which level? Wild-bootstrap p-values?
- Stars and notes. Conventional
*** ** * cutoffs (1/5/10), or journal-specific (some require none)?
- Output path. Almost always
paper/tabs/{name}.tex; the paper \input{}s that file.
- Compile target.
\begin{table} floating environment in body, or naked tabular snippet to be included from a parent macro?
Decision Tree (which table package to use)
Source = Stata
└── esttab (from estout) is canonical.
eststo store; esttab using "tabs/x.tex", booktabs label se ...
Source = R
├── fixest models (most common in 2024-26): use fixest::etable
└── Mixed model classes: use modelsummary (works across lm, glm,
PanelOLS, fixest, brms, ...). modelsummary writes .tex via
`output = "tabs/x.tex"`.
Source = Python
├── pyfixest models: use pyfixest.etable
├── linearmodels models: use compare(...) + manual to_latex(), or
pass models through stargazer
└── statsmodels OLS / GLM: use stargazer (Python port).
Output for Word
└── Same packages with .rtf or .docx output (esttab supports rtf;
modelsummary supports docx via flextable).
Output Path Convention
paper/
├── paper.tex
├── tabs/ # all .tex tables; never hand-edited
│ ├── table_main.tex
│ ├── table_balance.tex
│ ├── table_summary.tex
│ └── table_robustness.tex
├── figs/
└── code/
├── stata/
│ └── make_tables.do
└── r/
└── make_tables.R
Body text:
\Cref{tab:main} reports our preferred specification.
\input{tabs/table_main.tex}
The .tex file should produce the entire \begin{table} ... \end{table} environment so you only have one \input{} per table in the paper.
Common Pitfalls
- Hand-editing the
.tex file after generation. The next run will overwrite or diverge from the published numbers.
- Mixing significance-star conventions across tables (
* at 0.05 in one, at 0.10 in another).
- Using
\hline everywhere; readers expect three-line booktabs tables.
- Vertical lines in regression tables — never necessary, always ugly.
- Putting key information in the caption (e.g. "Standard errors clustered by firm") instead of in the notes block, where it can be longer and less awkward.
- Using
_ in variable labels without \_ escaping; LaTeX silently interprets them as subscripts.
- Including raw column names like
treat_post instead of human-readable labels.
- Numbers with inconsistent decimal precision across columns.
- Missing N row at the bottom of regression tables; reviewers will ask.
- Not exporting at all — running the regression in interactive mode and screenshotting the result. (This is "no replicability" in DIME's framework.)
Additional Resources
reference.md — extended patterns: balance tables, summary stats, panel tables, threeparttable notes, siunitx S-column alignment, multi-panel tables, journal-specific deviations.
examples/ — runnable scripts that produce real .tex files:
examples/make_tables_esttab.do — Stata regression + summary + balance via esttab
examples/make_tables_modelsummary.R — R via modelsummary + fixest::etable
examples/make_tables_pyfixest.py — Python via pyfixest.etable
examples/make_tables_stargazer.py — Python statsmodels via stargazer
examples/table_main_template.tex — minimal copy-paste-able tabular for "good replicability" cases
examples/table_balance_template.tex — DIME-style balance table layout
Requirements
- LaTeX: TeX Live 2022+ or MacTeX 2022+; packages
booktabs, threeparttable, siunitx, caption, cleveref.
- Stata:
ssc install estout (provides esttab, eststo, estadd, estpost).
- R:
install.packages(c("modelsummary", "fixest", "kableExtra")).
- Python:
pip install stargazer pyfixest pandas.
References
DIME
Style
1---2name: latex-tables3description: Generates publication-ready LaTeX tables produced by code (Stata `esttab`/`outreg2`, R `modelsummary`/`fixest::etable`, Python `stargazer`/`pyfixest.etable`) and writes them directly to the paper's `tabs/` folder. Defaults to DIME's "full replicability" standard (no copy-paste from any console), `booktabs` styling, three-line tables, threeparttable notes, sensible significance stars, and `\Cref{}`-friendly labels. Aligned with DIME Analytics' [Exporting Analysis](https://dimewiki.worldbank.org/Exporting_Analysis) and [Submit Table checklist](https://dimewiki.worldbank.org/Checklist:_Submit_Table). Use when the user asks for regression tables, summary statistics, balance tables, descriptive statistics, mean-comparison tables, multi-spec tables, or any code-to-LaTeX-table workflow.4---56# LaTeX Tables78Generate publication-ready LaTeX tables that come out of code (`esttab`, `modelsummary`, `pyfixest.etable`, `stargazer`) and `\input{}` cleanly into the paper. The default style follows DIME's "full replicability" tier: no manual editing between code and PDF.910## Operating Principles11121. **Tables are produced, never typed.** DIME identifies four [levels of replicability](https://dimewiki.worldbank.org/Exporting_Analysis): full, good, basic, and none. "None" (copy-paste from a console window) is unacceptable for any output that leaves the analyst. Default to **full**: code writes a `.tex` file that the paper `\input{}`s directly.132. **One source of truth per table.** Every numeric cell, star, sample size, and footnote comes from the same script that ran the regression. Never edit the `.tex` file by hand — re-run the script and rebuild the paper.143. **`booktabs` styling.** Three horizontal rules (`\toprule`, `\midrule`, `\bottomrule`), no vertical lines, consistent decimal alignment via `siunitx` `S` columns when precision matters.154. **Notes via `threeparttable`.** Significance levels, standard-error type, sample restrictions, and clustering belong in a single notes block at the bottom — not in the caption.165. **Cross-reference with `\Cref{}`.** `\label{tab:main}` + `\Cref{tab:main}` reads "Table 2" in body text and behaves correctly at sentence start.1718## Decision Policy1920This skill follows the repo-wide [Agent Policy](../../AGENT_POLICY.md).2122**ASK before proceeding** (blocking):23241. Source language of the regression (Stata / R / Python) — determines the canonical table package.252. Table type (regression / summary stats / balance / multi-panel / DiD-estimator comparison).263. Standard-error type and cluster level (these belong in the table notes).274. Output target (LaTeX `.tex`, Word `.rtf`, Excel `.xlsx`).2829**DEFAULT + flag** (use this default; tell the user how to override):3031- `esttab` (Stata), `modelsummary` or `fixest::etable` (R), `pyfixest.etable` or `stargazer` (Python).32- `booktabs` styling: `\toprule`, `\midrule`, `\bottomrule`; no vertical lines.33- Three-star convention `* 0.10 ** 0.05 *** 0.01`; pin once per paper.34- `threeparttable` for the notes block.35- Output path `paper/tabs/<name>.tex`; the paper `\input{}`s it.36- Within-R² (`r2_within`) reported instead of overall R² for FE models.3738**DOCUMENT and proceed** (write into the decisions log of the table-generating script):3940- The estimating equation, sample, cluster level, and FE included for each column.41- Variable label mapping (`coef_map` / `coeflabels`).42- Any subsample restriction shown in a column.4344`PROCEED` items: tables produced by code (never copy-paste); generated `.tex` never hand-edited; rebuild path runs the table script before LaTeX.4546## Pre-flight Checklist4748Before generating code, confirm with the user — and write the answers in the script header:4950- **Source language.** Stata, R, or Python? (Each has its own canonical table package.)51- **Table type.** Regression (multi-spec), summary statistics, balance / difference-in-means, descriptive cross-tabs, or model-comparison panel?52- **Sample.** Single or stratified? If panel, which fixed effects are on/off across columns?53- **Standard errors.** Cluster-robust at which level? Wild-bootstrap p-values?54- **Stars and notes.** Conventional `*** ** *` cutoffs (1/5/10), or journal-specific (some require none)?55- **Output path.** Almost always `paper/tabs/{name}.tex`; the paper `\input{}`s that file.56- **Compile target.** `\begin{table}` floating environment in body, or naked `tabular` snippet to be included from a parent macro?5758## Decision Tree (which table package to use)5960```61Source = Stata62└── esttab (from estout) is canonical.63 eststo store; esttab using "tabs/x.tex", booktabs label se ...6465Source = R66├── fixest models (most common in 2024-26): use fixest::etable67└── Mixed model classes: use modelsummary (works across lm, glm,68 PanelOLS, fixest, brms, ...). modelsummary writes .tex via69 `output = "tabs/x.tex"`.7071Source = Python72├── pyfixest models: use pyfixest.etable73├── linearmodels models: use compare(...) + manual to_latex(), or74 pass models through stargazer75└── statsmodels OLS / GLM: use stargazer (Python port).7677Output for Word78└── Same packages with .rtf or .docx output (esttab supports rtf;79 modelsummary supports docx via flextable).80```8182## Output Path Convention8384```85paper/86├── paper.tex87├── tabs/ # all .tex tables; never hand-edited88│ ├── table_main.tex89│ ├── table_balance.tex90│ ├── table_summary.tex91│ └── table_robustness.tex92├── figs/93└── code/94 ├── stata/95 │ └── make_tables.do96 └── r/97 └── make_tables.R98```99100Body text:101102```latex103\Cref{tab:main} reports our preferred specification.104\input{tabs/table_main.tex}105```106107The `.tex` file should produce the entire `\begin{table} ... \end{table}` environment so you only have one `\input{}` per table in the paper.108109## Common Pitfalls110111- Hand-editing the `.tex` file after generation. The next run will overwrite or diverge from the published numbers.112- Mixing significance-star conventions across tables (`*` at 0.05 in one, at 0.10 in another).113- Using `\hline` everywhere; readers expect three-line `booktabs` tables.114- Vertical lines in regression tables — never necessary, always ugly.115- Putting key information in the caption (e.g. "Standard errors clustered by firm") instead of in the notes block, where it can be longer and less awkward.116- Using `_` in variable labels without `\_` escaping; LaTeX silently interprets them as subscripts.117- Including raw column names like `treat_post` instead of human-readable labels.118- Numbers with inconsistent decimal precision across columns.119- Missing N row at the bottom of regression tables; reviewers will ask.120- Not exporting at all — running the regression in interactive mode and screenshotting the result. (This is "no replicability" in DIME's framework.)121122## Additional Resources123124- `reference.md` — extended patterns: balance tables, summary stats, panel tables, threeparttable notes, siunitx S-column alignment, multi-panel tables, journal-specific deviations.125- `examples/` — runnable scripts that produce real `.tex` files:126 - `examples/make_tables_esttab.do` — Stata regression + summary + balance via `esttab`127 - `examples/make_tables_modelsummary.R` — R via `modelsummary` + `fixest::etable`128 - `examples/make_tables_pyfixest.py` — Python via `pyfixest.etable`129 - `examples/make_tables_stargazer.py` — Python `statsmodels` via `stargazer`130 - `examples/table_main_template.tex` — minimal copy-paste-able tabular for "good replicability" cases131 - `examples/table_balance_template.tex` — DIME-style balance table layout132133## Requirements134135- LaTeX: TeX Live 2022+ or MacTeX 2022+; packages `booktabs`, `threeparttable`, `siunitx`, `caption`, `cleveref`.136- Stata: `ssc install estout` (provides `esttab`, `eststo`, `estadd`, `estpost`).137- R: `install.packages(c("modelsummary", "fixest", "kableExtra"))`.138- Python: `pip install stargazer pyfixest pandas`.139140## References141142### DIME143144- DIME Analytics, [Exporting Analysis](https://dimewiki.worldbank.org/Exporting_Analysis) — four levels of replicability.145- DIME Analytics, [Checklist: Submit Table](https://dimewiki.worldbank.org/Checklist:_Submit_Table).146- DIME Analytics, [Stata Coding Practices](https://dimewiki.worldbank.org/Stata_Coding_Practices) — `estout` family.147148### Style149150- AEA, [Manuscript Style Guide](https://www.aeaweb.org/journals/aer/submissions/accepted-articles/styleguide).151- Jansen & Persson, *Nice and fast tables in Stata for LaTeX and Excel* — https://osf.io/78nuc/.152- Lukas Püttmann, [`esttab` cheat sheet](https://lukaspuettmann.com/esttab/).153- `booktabs` documentation — https://ctan.org/pkg/booktabs.154- `siunitx` — https://ctan.org/pkg/siunitx (S columns for decimal alignment).