4

So I wasn't happy with how esttab was formatting my regression tables from the statistical program Stata. So I instead I decided to attempt to build my own skeleton table, which had better formatting, but could easily be adjusted for different types of regression tables (e.g. fewer variables or fewer regressions etc). For a first attempt, it is quite good I think, but I have an alignment problem, which I am unsure how to fix.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-symbols = {()}}
\begin{document}
\begin{table}[H]
\caption{Regression Results}
\label{table:RegressionResults}
\begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
*{6}{S[table-format=2.3, table-align-text-post=false]}
}
\toprule
{\bfseries Variable} & {\bfseries All} & {\bfseries Commerce} & {\bfseries B.Bus.Sci} &     {\bfseries BCom} & {\bfseries EBE} & {\bfseries Science} \\
\midrule
Gender & 1.953*** & 1.711*** & 1.626*** & 1.617*** & 1.005 & 1.793*** \\ 
 & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\ 
Age & 1.010 & 0.920 & 0.761*** & 1.288** & 1.066 & 1.072 \\ 
 & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\ 
Coloured & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\ 
 & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\ 
Indian/Asian & 0.670** & 0.488** & 1.021 & 0.337*** & 0.565* & 0.947 \\ 
 & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\ 
White & 5.123*** & 2.953*** & 3.510*** & 2.679** & 4.748*** & 12.548*** \\ 
 & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\ 
Financial Aid & 0.678*** & 0.397*** & 0.420*** & 0.400*** & 0.754* & 0.706** \\ 
 & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\ 
Academic Development & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574*** \\ 
 & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\ 
English Home Language & 1.401** & 1.716** & 1.472 & 2.265** & 1.739* & 1.293 \\ 
 & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\ 
Quintile 1 & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\ 
 & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\ 
Quintile 2 & 1.291 & 1.161 & 0.966 & 1.653 & 1.846* & 0.968 \\ 
 & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\ 
Quintile 4 & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\ 
 & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\ 
Quintile 5 & 1.760*** & 1.351 & 1.412 & 1.616 & 1.845** & 1.527* \\ 
 & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\ 
Independent & 1.663*** & 1.203 & 1.312 & 1.626 & 1.789** & 1.335 \\ 
 & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\ 
Western Cape & 1.145 & 1.275* & 1.144 & 1.661** & 1.073 & 0.950 \\ 
 & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\ 
High School GPA & 1.119*** & 1.119*** & 1.156*** & 1.111*** & 1.148*** & 1.134*** \\ 
 & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\ 
Mathematics & 1.007** & 1.012** & 1.005 & 1.048*** & 1.054*** & 1.022*** \\ 
 & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\ 
English & 1.013*** & 1.012 & 1.006 & 1.038*** & 1.007 & 1.003 \\ 
 & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\ 
Science & 0.698*** & 1.053 & 1.352* & 1.239 &  & 1.252 \\ 
 & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\ 
Residence & 1.117 & 1.401** & 1.240 & 1.061 & 1.019 & 0.937 \\ 
\midrule
Observations & {36 333} & {20 409}  &{7 408}    & {13 001}  & {9 169}&  {6 755} \\
Pseudo \(R^{2}\) & {0.397} & {0.451} & {0.420} & {0.574} & {0.419} & {0.431} \\
\bottomrule
{\footnotesize Standard errors in parentheses}\\
{\footnotesize * \(p<0.05\), ** \(p<0.01\), *** \(p<0.001\)}\\
\end{tabular*}
\end{table}
\end{document}

enter image description here

  • any reason to use ** and *** rather than and ? that would save some space and make things look much more uniform. – greyshade Aug 14 '14 at 11:49
  • Well I think esttab uses *s to indicate significance levels (I'm using esttab to copy the output to Excel, them simply copy & pasting the values into Latex) – The Statistician Magician Aug 14 '14 at 12:08
  • ok, so basically its just carried over from somewhere else and it's not important they're asterisks - I would consider running a simple search/replace to fix these to daggers and gain space and uniformity in the layout. – greyshade Aug 14 '14 at 12:14
  • Indeed. Would use less space. What would I use for the the one star though? Is there a triple dagger? – The Statistician Magician Aug 14 '14 at 12:17
  • 1
    I think it's called \textdaggerdbl - I might be mistaken, but I know for sure it does exist somewhere under some name. Edit: it is indeed called that - see here, p 3. – greyshade Aug 14 '14 at 13:24
4

You are padding too much data in the table. Anyway, here is an attempt.

\documentclass{article}
\usepackage{booktabs,multirow}
\usepackage{siunitx}
\sisetup{detect-mode,
        group-digits    = false,
        input-symbols   = ( ) }

\newcommand{\level}[1]{%
\multirow{2}{*}{%
  \begin{tabular}{@{}>{\raggedright\arraybackslash}p{0.2\textwidth}@{}}
  \strut#1\strut
  \end{tabular}%
  }
  }

\begin{document}
\begin{table}[htb]
\caption{Regression Results}
\label{table:RegressionResults}
\centering
\begin{tabular}{
l
*{6}{S[table-format=2.5, table-align-text-post=false]}
}
\toprule
{\bfseries\small Variable} & {\bfseries\small All} & {\bfseries\small Commerce} & {\bfseries\small B.Bus.Sci} &     {\bfseries\small BCom} & {\bfseries\small EBE} & {\bfseries\small Science} \\
\midrule
\level{Gender} & 1.953*** & 1.711*** & 1.626*** & 1.617*** & 1.005 & 1.793*** \\
 & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\
\level{Age} & 1.010 & 0.920 & 0.761*** & 1.288** & 1.066 & 1.072 \\
 & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\
\level{Coloured} & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\
 & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\
\level{Indian/Asian} & 0.670** & 0.488** & 1.021 & 0.337*** & 0.565* & 0.947 \\
 & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\
\level{White} & 5.123*** & 2.953*** & 3.510*** & 2.679** & 4.748*** & 12.548*** \\
 & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\
\level{Financial Aid} & 0.678*** & 0.397*** & 0.420*** & 0.400*** & 0.754* & 0.706** \\
 & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\
\level{Academic Development} & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574*** \\
 & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\
\level{English Home Language} & 1.401** & 1.716** & 1.472 & 2.265** & 1.739* & 1.293 \\
 & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\
\level{Quintile 1} & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\
 & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\
\level{Quintile 2} & 1.291 & 1.161 & 0.966 & 1.653 & 1.846* & 0.968 \\
 & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\
\level{Quintile 4} & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\
 & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\
\level{Quintile 5} & 1.760*** & 1.351 & 1.412 & 1.616 & 1.845** & 1.527* \\
 & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\
\level{Independent} & 1.663*** & 1.203 & 1.312 & 1.626 & 1.789** & 1.335 \\
 & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\
\level{Western Cape} & 1.145 & 1.275* & 1.144 & 1.661** & 1.073 & 0.950 \\
 & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\
\level{High School GPA} & 1.119*** & 1.119*** & 1.156*** & 1.111*** & 1.148*** & 1.134*** \\
 & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\
\level{Mathematics} & 1.007** & 1.012** & 1.005 & 1.048*** & 1.054*** & 1.022*** \\
 & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\
\level{English} & 1.013*** & 1.012 & 1.006 & 1.038*** & 1.007 & 1.003 \\
 & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\
\level{Science} & 0.698*** & 1.053 & 1.352* & 1.239 &  & 1.252 \\
 & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\
Residence & 1.117 & 1.401** & 1.240 & 1.061 & 1.019 & 0.937 \\
\midrule
Observations & {36 333} & {20 409}  &{7 408}    & {13 001}  & {9 169}&  {6 755} \\
Pseudo \(R^{2}\) & {0.397} & {0.451} & {0.420} & {0.574} & {0.419} & {0.431} \\
\bottomrule
\multicolumn{7}{l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{7}{l}{\footnotesize * \(p<0.05\), ** \(p<0.01\), *** \(p<0.001\)}\\
\end{tabular}
\end{table}
\end{document}

enter image description here

  • I would recommend making those rows where the variable name get's broken across lines into \multirows - which would eliminate the empty lines in the table (and possibly allow some more space saving on the variable column). – greyshade Aug 14 '14 at 11:45
  • why is there so much space before the closing parentheses? is this a consequence of using siunitx? – barbara beeton Aug 14 '14 at 15:19
  • Good spot - I didn't even notice it until you mentioned it. Does anybody else have an idea about this? – The Statistician Magician Aug 14 '14 at 17:34
  • @barbarabeeton It was due to the grouping of digits by siunitx. It can be removed by the option group-digits = false, in \sisetup. Thanks for noting. – user11232 Aug 15 '14 at 13:30
  • @Chris Please ping for clarifications if any as I couldn't explain the changes I have made (they were ... many small ones). – user11232 Aug 15 '14 at 13:32
2

Here's a solution that uses the dcolumn package and its d column type instead of the siunitx package and its S column type. The main advantage I see to using the dcolumn package is that it simplifies setting the single, double and triple asterisks in superscript position; doing so is not only stylistically pleasant but also serves to economize on much-needed space in this table.

Separately, I would not boldface the words in the header row. IMNSHO, using boldface in this setting borders on being vulgar, and it certainly doesn't add to the readability or intelligibility of the table.

With these proposed changes and a reduction of the intercolumn whitespace parameter \tabcolsep from 6.0 to 1.5 pt, you can get the table to fit into the width of the textblock without having to reduce the font size.

By the way, a row with standard errors seems to be missing near the bottom of the table.

enter image description here

\documentclass{article}
\usepackage{booktabs,dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\setlength\tabcolsep{1.5pt} % default value: 6pt
\caption{Regression Results}
\label{table:RegressionResults}
\begin{tabular*}{\textwidth}{%
   @{} l @{\extracolsep{\fill}} *{5}{d{2.5}} d{2.6} @{}}
\toprule
Variable & \mc{All} & \mc{Comm.} & \mc{B.Bus.Sci} & \mc{BCom} & \mc{EBE} & \mc{Science} \\
\midrule
Gender & 1.953^{***} & 1.711^{***} & 1.626^{***} & 1.617^{***} & 1.005 & 1.793^{***} \\
       & (0.137) & (0.194) & (0.269) & (0.269) & (0.162) & (0.253) \\
Age & 1.010 & 0.920 & 0.761^{***} & 1.288^{**} & 1.066 & 1.072 \\
    & (0.039) & (0.065) & (0.071) & (0.160) & (0.080) & (0.075) \\
Coloured & 1.099 & 1.122 & 1.482 & 0.774 & 1.048 & 1.276 \\
         & (0.186) & (0.327) & (0.600) & (0.340) & (0.354) & (0.461) \\
Indian/Asian & 0.670^{**} & 0.488^{**} & 1.021 & 0.337^{***} & 0.565^{*} & 0.947 \\
             & (0.114) & (0.137) & (0.443) & (0.137) & (0.187) & (0.384) \\
White & 5.123^{***} & 2.953^{***} & 3.510^{***} & 2.679^{**} & 4.748^{***} & 12.548^{***} \\
      & (0.841) & (0.817) & (1.361) & (1.112) & (1.465) & (4.620) \\
Financial Aid & 0.678^{***} & 0.397^{***} & 0.420^{***} & 0.400^{***} & 0.754^{*} & 0.706^{**} \\
              & (0.056) & (0.054) & (0.077) & (0.081) & (0.129) & (0.118) \\
Academic Develop. & 0.911 & 0.930 & 1.116 & 0.783 & 0.897 & 0.574^{***} \\
                  & (0.083) & (0.132) & (0.211) & (0.175) & (0.184) & (0.124) \\
English Home Lang. & 1.401^{**} & 1.716^{**} & 1.472 & 2.265^{**} & 1.739^{*} & 1.293 \\
                   & (0.208) & (0.433) & (0.512) & (0.864) & (0.493) & (0.418) \\
Quintile 1 & 1.016 & 1.051 & 1.250 & 0.516 & 0.794 & 1.469 \\
           & (0.244) & (0.456) & (0.610) & (0.783) & (0.375) & (0.627) \\
Quintile 2 & 1.291 & 1.161 & 0.966 & 1.653 & 1.846^{*} & 0.968 \\
           & (0.242) & (0.449) & (0.455) & (1.175) & (0.634) & (0.307) \\
Quintile 4 & 0.920 & 0.771 & 0.818 & 0.559 & 0.827 & 0.744 \\
           & (0.140) & (0.211) & (0.276) & (0.287) & (0.252) & (0.206) \\
Quintile 5 & 1.760^{***} & 1.351 & 1.412 & 1.616 & 1.845^{**} & 1.527^{*} \\
           & (0.218) & (0.301) & (0.390) & (0.687) & (0.465) & (0.362) \\
Independent & 1.663^{***} & 1.203 & 1.312 & 1.626 & 1.789^{**} & 1.335 \\
            & (0.219) & (0.284) & (0.399) & (0.708) & (0.472) & (0.338) \\
Western Cape & 1.145 & 1.275^{*} & 1.144 & 1.661^{**} & 1.073 & 0.950 \\
             & (0.099) & (0.183) & (0.235) & (0.358) & (0.192) & (0.167) \\
High School GPA & 1.119^{***} & 1.119^{***} & 1.156^{***} & 1.111^{***} & 1.148^{***} & 1.134^{***} \\
                & (0.007) & (0.011) & (0.017) & (0.016) & (0.014) & (0.014) \\
Mathematics & 1.007^{**} & 1.012^{**} & 1.005 & 1.048^{***} & 1.054^{***} & 1.022^{***} \\
            & (0.003) & (0.006) & (0.008) & (0.009) & (0.008) & (0.006) \\
English & 1.013^{***} & 1.012 & 1.006 & 1.038^{***} & 1.007 & 1.003 \\
        & (0.004) & (0.008) & (0.011) & (0.012) & (0.009) & (0.008) \\
Science & 0.698^{***} & 1.053 & 1.352^{*} & 1.239 &  & 1.252 \\
        & (0.074) & (0.136) & (0.233) & (0.255) &  & (0.557) \\
Residence & 1.117 & 1.401^{**} & 1.240 & 1.061 & 1.019 & 0.937 \\
\midrule
Observations & \mc{36333} & \mc{20409} & \mc{7408} & \mc{13001} & \mc{9169} & \mc{6755} \\
Pseudo \(R^{2}\) & \mc{0.397} & \mc{0.451} & \mc{0.420} & \mc{0.574} & \mc{0.419} & \mc{0.431} \\
\midrule[\heavyrulewidth]
\multicolumn{7}{@{}l}{\footnotesize Standard errors in parentheses}\\
\multicolumn{7}{@{}l}{\footnotesize ${}^{*}$ \(p<0.05\), ${}^{**}$ \(p<0.01\), ${}^{***}$ \(p<0.001\)}\\
\end{tabular*}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.