Stata latex summary tables: a hack

The Stata package “eststo” has a nice set of commands to create summary statistics tables. These commands can create “fragments” that you can dynamically add to tables in a main tex document. Unfortunately, the output of the following example starts with an ‘hline’ and doesn’t play well with latex:

eststo clear
eststo: estpost tabstat var1 var2 var3, listwise statistics(mean sd) columns(statistics)

Saving to a tex file:

esttab using "../writing/tables/summary.tex", main(mean) aux(sd) nostar unstack nonote nomtitle nonumber replace label fragment

creates a tex file that starts with ‘hline.’ When combined with a tabular environment with the ‘input’ command (here input{tables/summary.tex}) you will get a “Misplaced noalign” error. I found a partial solution online with some changes.

1. Add makeatletter followed by newcommand*ExpandableInput[1]{@@input#1 } to your header

2.  Make sure the header also has makeatother as well

3.  Replace the input command with ExpandableInput{tables/summary.tex}

4.  If you want to end the table with more ‘hline”s, put a line break after the above command ‘\’

“Simple” as that….