[Tex/LaTex] error in table output

errorstables

I am using stata, a statistical software. It has a program called -tabout-, that generates output (basically tables containing descriptive statistics incl means of variables etc) code for TeX.

Currently for the table I need I obtain the following code

\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {10cm} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
\toprule
 & \multicolumn{3}{c}{orgevent} \\
spontevent&0&1&Total \\
\cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-6}
&Relative&Relative&Relative \\
\midrule
0 (97\%)&0.016\%&0.011\%&0.016\% \\
1 (2\%)&0.044\%&&0.044\% \\
Total (100\%)&0.017\%&0.011\%&0.017\% \\
\bottomrule
\addlinespace[.75ex]
\scriptsize{\emph{Source: }#}
\end{tabularx}
\normalsize
\end{center} 

But my LaTeX compiler points to an error in the line

 \end{tabularx}

The error reported is

"pdflatex> ! You can't use the 'macro parameter character #' in
restricted mode"

Please help understand what's going on and how can I see the table?

After regenerating the code from stata, again error bit of a different kind

\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {10cm} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
\toprule
 & \multicolumn{3}{c}{orgevent} \\
spontevent&0&1&Total \\
\cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-6}
&Relative&Relative&Relative \\
\midrule
0&0.016\%&0.011\%&0.016\% \\
1&0.044\%&&0.044\% \\
Total&0.017\%&0.011\%&0.017\% \\
\begin{center}
\footnotesize
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
\begin{tabularx} {10cm} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
\toprule
 & \multicolumn{3}{c}{orgevent} \\
spontevent&0&1&Total \\
\cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-6}
&Relative&Relative&Relative \\
\midrule
0 (97\%)&0.016\%&0.011\%&0.016\% \\
1 (2\%)&0.044\%&&0.044\% \\
Total (100\%)&0.017\%&0.011\%&0.017\% \\
\bottomrule
\addlinespace[.75ex]
%\scriptsize{\emph{Source: }#}
\end{tabularx}
\normalsize
\end{center}

Are there any TeXperts who have some experience with stata as well? As you can see, the code seems to be repeated twice

Best Answer

It's the lonely # in the "Source" line. You probably need to fill the source field in Stata or find a way to not produce the line.

However, I'd input that source line as

\multicolumn{17}{@{}l}{\scriptsize\emph{Source}: ...}

so as not to enlarge the first column. Alternatively,

\makebox[0pt][l]{\scriptsize\emph{Source}: ...}

which doesn't need to know the number of columns to span.

By the way, single characters like # $ & ˜ _ ˆ % { } all have special meanings and require a \ before them to use them as printing character.