# error in table output

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
\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"

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
%\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

-
That's the lonely # in the "Source" line. You probably need to fill the source field in Stata. –  egreg Jun 7 '12 at 22:38
@egreg: Thanks, I had guessed so. I get the output now but doesn't seem to be what I need. Shall have a look at it again. Cheers –  Abhimanyu Arora Jun 7 '12 at 22:39
@egreg I was about to say the same thing :-). Post your comment as an answer as it has resolved the problem. –  azetina Jun 7 '12 at 22:43
@AbhimanyuArora The errors comes because you did not end the first tabular and center commands. Check your code. –  azetina Jun 7 '12 at 22:58
@AbhimanyuArora Note that you are asking several questions in one post. Sometimes it is best to isolate specific questions as other members may aid in their expertise. –  azetina Jun 7 '12 at 23:07

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.

-
Grazie @egreg ,I simply added a % for now, regenerated the code for the table but get a different error (pdflatex> ! missing \cr inserted), shall edit the question –  Abhimanyu Arora Jun 7 '12 at 22:51
@AbhimanyuArora Somehow your last code has now duplicate lines; remove those lines: \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] \end{tabularx} \normalsize \end{center} –  Gonzalo Medina Jun 7 '12 at 23:00
@GonzaloMedina: Thanks very much indeed –  Abhimanyu Arora Jun 7 '12 at 23:13