2

I have some issues when creating my OLS regression in LaTeX and I really hope, that some of you could help me. I have three questions:

1) How to make "Growth 91-92" and "Growth92-93" with a space, so I can see it is a part of the "Growth"-categori. 2) How to make all models (1-5) columns in the same length? 3) How to make the first column a big bigger then the models-columns?

I would like to create a table, which look like this:

enter image description here My preamble look like this:

\documentclass[a4paper,12pt,oneside]{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{pgf}
\usetikzlibrary{shapes,arrows,positioning,calc,threeparttable} 
\usepackage{tabu}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow,tabularx,booktabs}
\begin{document}
\begin{table}[H]
\begin{threeparttable}
\renewcommand\arraystretch{1.0}
\medskip
\renewcommand\tabcolsep{1pt}  
\begin{tabular*}{\textwidth}{ @{} p{2.4cm} 
     @{\extracolsep{\fill}}   
     *{10}{S[table-format=2.6]} @{}}
\toprule
& {Model I} & {Model II} & {Model III} & {Model IV} & {Model V} \\
\emph{Afh.\ var.}
& {All partys} & {All partys} & {Social Democrat} & {Liberal} & {Conservative} \\
\midrule
\emph{Uafh.\ var.} \\
Nationalpol. effects & 
\multicolumn{1}{c}{0,11\sym{***}} & 
\multicolumn{1}{c}{0,22\sym{*}} &  
\multicolumn{1}{c}{0,33\sym{***}} &  
\multicolumn{1}{c}{0,44\sym{*}} &  
\multicolumn{1}{c}{0,55\sym{***}} &   \\
& 
\multicolumn{1}{c}{(0,11)} & 
\multicolumn{1}{c}{(0,22)} & 
\multicolumn{1}{c}{(0,33)} & 
\multicolumn{1}{c}{(0,44)} & 
\multicolumn{1}{c}{(0,55)} &  \\
Economic growth & 
\multicolumn{1}{c}{0,11} & 
\multicolumn{1}{c}{0,22} & 
\multicolumn{1}{c}{0,33\sym{***}} & 
\multicolumn{1}{c}{0,44} & 
\multicolumn{1}{c}{0,55\sym{**}} & \\
&
\multicolumn{1}{c}{(0,11)} & 
\multicolumn{1}{c}{(0,22)} & 
\multicolumn{1}{c}{(0,33)} & 
\multicolumn{1}{c}{(0,44)} & 
\multicolumn{1}{c}{(0,55)} & \\
\cmidrule{1-1}
Adjusted R\textsuperscript{2} & 
\multicolumn{1}{c}{0,11} & 
\multicolumn{1}{c}{0,22} & 
\multicolumn{1}{c}{0,33} & 
\multicolumn{1}{c}{0,44} & 
\multicolumn{1}{c}{0,55} &   \\
N & 
\multicolumn{1}{c}{111} & 
\multicolumn{1}{c}{222} & 
\multicolumn{1}{c}{333} & 
\multicolumn{1}{c}{444} & 
\multicolumn{1}{c}{555} &  \\
\bottomrule
\end{tabular*}
\end{threeparttable}
\end{table}
3

I suggest you make a few changes to your code.

  • Most importantly, don't encase each and every numeric cell in a \multicolumn{1}{c}{...} wrapper. Not only is it not necessary to do this, it's counterproductive: the wrappers override the intended formatting effects of the basic column type you chose, and in consequence you get none of the intended formatting.

  • It looks like you're using the siunitx package mainly (exclusively?) for its S table column type, probably to achieve alignment of the numbers on their decimal markers. If this impression is correct, I recommend you actually use a different column type: D, provided by the dcolumn package. With the D column type, less overhead is required to deal with parentheses and symbols that occur in the numeric columns.

  • To avoid getting a gap between the regression coefficient and standard error lines, you may want to place the names of the regressors (in the first column) in a little wrapper that hides the fact that the regressor names occupy two lines from the surrounding tabular-like environment. In the code below, I've created a macro called \narrowtab for this purpose; feel free to rename it to something else.

  • To make the five data columns appear like they're roughly equally wide, it appears to be necessary to abbreviate the labels of Models III and V.

I'm afraid I wasn't able to address your first question since your example code made no reference to that matter.

enter image description here

\documentclass[a4paper,12pt,oneside]{article}
\usepackage{threeparttable,dcolumn,caption,amsmath,array,booktabs}
\newcommand{\sym}[1]{{}^{#1}} % correct?
\newcommand\mc[1]{\multicolumn{1}{@{}c@{}}{#1}} % handy shortcut macro
\newcommand\narrowtab[2]{%  %% macro to hide depth of its argument from outer tabular
 \ensuremath{\smash{\begin{tabular}[t]{@{}>{\raggedright\arraybackslash}p{#1}@{}}%
     #2 \end{tabular}}}}
\begin{document}
\begin{table}
\caption{Regression results}
\begin{threeparttable}
%\renewcommand\tabcolsep{1pt}  
\begin{tabular*}{\textwidth}{@{} p{1in} @{\extracolsep{\fill}} *{5}{D{,}{,}{2.4}} @{}}
\toprule
& \mc{Model I} & \mc{Model II} & \mc{Model III} & \mc{Model IV} & \mc{Model V} \\
\emph{Afh.\ var.}
& \mc{All partys} & \mc{All partys} & \mc{Soc.\ Dem.} & \mc{Liberal} & \mc{Cons.} \\
\midrule
\emph{Uafh.\ var.} \\
\narrowtab{1in}{Nationalpol.\ effects} & 
0,11\sym{***} & 0,22\sym{*} & 0,33\sym{***} & 0,44\sym{*} & 0,55\sym{***} \\
& (0,11) & (0,22) & (0,33) & (0,44) & (0,55) \\
\addlinespace
\narrowtab{1in}{Economic growth} & 
0,11 & 0,22 & 0,33\sym{***} & 0,44 & 0,55\sym{**}\\
& (0,11) & (0,22) & (0,33) & (0,44) & (0,55) \\
\cmidrule{1-1}
Adjusted R\textsuperscript{2} & 
0,11 & 0,22 & 0,33 & 0,44 & 0,55  \\
N & \mc{111} & \mc{222} & \mc{333} & \mc{444} & \mc{555} \\
\bottomrule
\end{tabular*}
\end{threeparttable}
\end{table}

\end{document}
  • Dear Mico. Thank you so much for you answer. As you mentioned, I am not helping with the code by intend the lines below Economic growth. The reason why I don't do that, is because I don't know why. I read somewhere, that I should put "/ / /" before "Growth 91-92" Is that the right way of doing it? – A. F. Dec 9 '14 at 10:35
  • 1
    @A.F. - You're welcome. To indent the string "Growth 91-92" a bit, use backslash rather than forward-slash characters: \ \ \ . This will insert three "space" characters. – Mico Dec 9 '14 at 11:07
  • Is this the right solution: "\ \ \" for my problem? – A. F. Dec 9 '14 at 11:28
  • @A.F. - What is "right" depends on your objective. Indenting the start of some lines by three spaces may well be OK, but I can't make that decision for you. – Mico Dec 9 '14 at 11:30
  • I got following message, when compile my document: "! Package array Error: Illegal pream-token (D): `c' used." – A. F. Dec 10 '14 at 16:18

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.