I am writing a document for which I need to insert tables produced by the statistical progam Stata. More specifically I am using Stata package outreg2. Here is an example of the type of a table that I am trying to insert:
\begin{tabular}{lcc} \hline
& (1) & (2) \\
VARIABLES & mpg & mpg \\ \hline
& & \\
foreign & -1.967 & -1.655 \\
& (1.181) & (1.082) \\
weight & -0.00420** & -0.00647*** \\
& (0.00202) & (0.000700) \\
headroom & -0.0592 & -0.219 \\
& (0.645) & (0.542) \\
trunk & -0.0122 & \\
& (0.159) & \\
length & -0.0631 & \\
& (0.0644) & \\
turn & -0.165 & \\
& (0.198) & \\
displacement & 0.000792 & \\
& (0.0103) & \\
Constant & 53.14*** & 41.99*** \\
& (7.584) & (2.312) \\
& & \\
Observations & 74 & 74 \\
R-squared & 0.677 & 0.663 \\ \hline
\multicolumn{3}{c}{ Standard errors in parentheses} \\
\multicolumn{3}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
You can replicate the table in Stata by:
sysuse auto,clear
regress mpg foreign weight headroom trunk length turn displacement
outreg2 using myfile, replace tex(frag)
regress mpg foreign weight headroom
outreg2 using myfile, tex(frag)
I made a new tex command for inserting the table:
\newcommand{\stataTable}[3]{
\begin{table}
\begin{threeparttable}
\caption{#2}
\noindent\adjustbox{max width=\textwidth}{%
\input{#1}}
\begin{tablenotes}
\small
\item #3
\end{tablenotes}
\end{threeparttable}
\end{table}
}
It takes the input file, caption and an endnote as arguments. Now I try to add the table in the document by:
\stataTable{myfile.tex}{OLS estimates.}{\lipsum}
I do this with threeparttable package, because I need to add notes in the end of the table.
Unfortunately this does not work, and I get the error Missing \endgroup inserted.... I understand that a missing curly bracket is a possible reason, but I just can't figure out where that could be.
However, I can make this work with an alternative command that does not adjust the table width:
\newcommand{\stataTable}[3]{
\begin{table}
\begin{threeparttable}
\caption{#2}
\input{#1}
\begin{tablenotes}
\small
\item #3
\end{tablenotes}
\end{threeparttable}
\end{table}
}
So it seems that by trying to adjust the width of the table, I am breaking the function somehow. I have also tried an alternative way (\mytabularwrap) to adjust the width presented here:
Shrink table to fit on a page, or keep it as it is
That did not work either. Nevertheless, the table width needs to be adjusted to the text width.
Any ideas how to fix this?