3

Could anyone help me figure out what's the real problem here? I'm creating a table with some data exported from Stata, but I can't seem to get the input command to work properly. If I paste the code from the input file, then everything works properly. The code

\documentclass{article}
\usepackage{booktabs}
\newcommand{\sym}[1]{\rlap{$#1$}} % for symbols in Table
\begin{document}
  \begin{table*}\centering
    \begin{tabular}{@{}cccccccc@{}}\toprule
      & \multicolumn{3}{c}{A} & \phantom{abc}& \multicolumn{3}{c}{B}\\ \cmidrule{2-4} \cmidrule{6-8}
      & 1 & 2 & 3 && 1 & 2 & 3\\
      \midrule
      C     &       0.60  &       0.951 &       0.245         & &       1.151         &       1.563         &       0.586         \\
                  &     (0.262)         &     (0.364)         &     (0.310)         & &     (0.620)         &     (0.905)         &     (0.696)         \\
      \midrule
      \(N\)       &      919629         &      468093         &      451536         & &      186271         &       94771         &       91500         \\

      \bottomrule
    \end{tabular}
  \end{table*}
\end{document}

generates the following pretty table.

Pretty table

But if I use the Stata-generated file ("minimal_data") as is

\midrule
C     &       0.606  &       0.951 &       0.245         & &       1.151         &       1.563         &       0.586         \\
            &     (0.262)         &     (0.364)         &     (0.310)         & &     (0.620)         &     (0.905)         &     (0.696)         \\
\midrule
\(N\)       &      919629         &      468093         &      451536         & &      186271         &       94771         &       91500         \\

together with

\documentclass{article}
\usepackage{booktabs}
\newcommand{\sym}[1]{\rlap{$#1$}} % for symbols in Table
\begin{document}
  \begin{table*}\centering
    \begin{tabular}{@{}cccccccc@{}}\toprule
      & \multicolumn{3}{c}{A} & \phantom{abc}& \multicolumn{3}{c}{B}\\ \cmidrule{2-4} \cmidrule{6-8}
      & 1 & 2 & 3 && 1 & 2 & 3\\
      \input{minimal_data}
      \bottomrule
    \end{tabular}
  \end{table*}
\end{document}

then I encounter all kinds of errors.

5
  • 2
    use \@@input minimal_data and put \makeatletter before the tabular Mar 22, 2018 at 20:50
  • 2
    latex's \input is not expandadable so starts the first cell, so you can not have \midrule as the first thing in the file. The \@@input form with no braces is the tex primitive Mar 22, 2018 at 20:52
  • You could also put the entire tabular environment in the "minimal_data" file.
    – onewhaleid
    Mar 22, 2018 at 20:52
  • @onewhaleid At one point I might do that but I would need some better Stata skills then :)
    – Fredrik P
    Mar 23, 2018 at 8:42
  • If you stored the data in a Stata matrix, your table could easily be reproduced with Stata's frmttable command. The only drawback is that it doesn't work with booktabs-style rules. Perhaps one could hack the command though.
    – Turtle
    Apr 25, 2018 at 15:23

0

You must log in to answer this question.

Browse other questions tagged .