This repository contains not only write_mats.ado
, but also a few examples in stata and latex showing how I tipically use this utility. This utility is not a substitute for tools like estout/esttab, but I find it useful in my workflow and for whenever I need to create a non-standard table.
For example, often we need to create a table when only one coefficient from a particular regression is of interest, and we want to combine estimated effects from multiple outcomes as rows and specifications as columns, such as this.
Alternatively, we might want to add the results of tests in a specific a column, and selected coefficients from a dynamic specification in others like here
All these tables can be created with standard stata tools, but they require some workarounds. I personally like to work with write_mats
as it offers a few advantages
-
Separating the estimation and table creation process: Using this approach requires saving regression estimates on the disk as
.ster
files. Especially when working on large dataset, this has been a game-changer for me, as it allowed me to add coefficients or modify the layout of the table without having to re-run all regressions. -
Structured workflow: I personally dislike if code outputs also the
\begin{tabular}
part of the latex table, headings, and other unnecessary stuff. Some journals might require you to change it manually, and anyway I much prefer usingtabularx
if given a choice. Moreover, even for drafts, I like to have my tables looking nice, but I definitely do not want to spend time on them every time I change my specifications a tiny bit, or when I want to add an outcome variable. I want stata to spit out files that latex can read without any manual tinkering.- Bonus: Having a structured workflow makes it way easier to go back to the code of a paper after months of waiting for referee reports...
This type of workflow consists of essentially three separate steps.
- Run regressions and save them
- Turn regressions into matrixes and feed these matrixes to write_mats.ado
- Prepare the skeleton of tables in latex, and point the file to the location where you are saving the final tables
Other than myados/write_mats.ado
, in this repository I uploaded a few files and examples you might find useful if you want to replicate (part of) this workflow. Specifically:
run_regressions.do: This file simulates a very simple dataset, runs some OLS and IV regressions on it, and saves the regression results into the estimates/sim folder
write_tables.do: This file loads and compiles the regression results into matrixed, calls write_mats
and exports the tables in .tex
format. In the repo you can also find some estimates that Jeppe Druedahl and I use in our joint paper, Long-Run Saving Dynamics: Evidence from Unexpected Inheritances (a cool paper, check it out!). Note that you can run this file on the same stata session as the first one - it does not load, create or use any variable in memory.
compile_tables.tex: This file creates the skeleton of a latex document, which points at the .tex files exported by write_tables.do
.
Want to see the advantage of this workflow? Try re-running all three files one after the other. I did not specify a seed in run_regressions.do
, so you'll get different results every time. A little like when you figure out a few months from your PhD defense that you made a typo in your data building and now a fifth of your sample is gone (ehrm). Yet, all it's needed to update the tables in your paper is a sequence of two CTRL+R and a CTRL+B - or however you compile .tex files :-)