benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
70 stars 17 forks source link

esttab doesn't output in tex the correct number of columns from a matrix #10

Closed bquistorff closed 8 years ago

bquistorff commented 8 years ago

When outputting a matrix, -esttab- produces incorrect latex code. For example,

. mat x = (1,2)`
. esttab matrix(x), tex
\begin{tabular}{l*{1}{c}}
\hline\hline
            &           x&            \\
            &          c1&          c2\\
\hline
r1          &           1&           2\\
\hline\hline
\end{tabular}

The top line should have a 2 instead of 1.

benjann commented 8 years ago

Hi, -esttab- is not smart enough to figure out how to set the column definitions in LaTeX if you tabulate a matrix. The problem can be addressed by providing appropriate column definitions using the -alignment()- option. Example:

. matrix x = (1,2)

. esttab matrix(x), tex align(cc)

\begin{tabular}{l*{1}{cc}}
\hline\hline
            &           x&            \\
            &          c1&          c2\\
\hline
r1          &           1&           2\\
\hline\hline
\end{tabular}

Of course you can also type, e.g. -align(rr)- or -align(lc)- or whatever you like. Furthermore, to automate, you could use code such as the following.

. matrix x = (1,2)

. esttab matrix(x), tex align(`=colsof(x)*"c"')

\begin{tabular}{l*{1}{cc}}
\hline\hline
            &           x&            \\
            &          c1&          c2\\
\hline
r1          &           1&           2\\
\hline\hline
\end{tabular}

I will look into making -esttab- smarter so that -align()- only has to be used if you don't want "c" column definitions, but it might take a while until I get to this. ben

benjann commented 8 years ago

The newest estout update, which will be available from SSC in some days, fixes this problem.