3

I will be grateful if you can help in creating a statistical table. Actually my problem is mainly in the editing. Here is the table I am trying to create:

enter image description here

In the table, there should be C and C&T columns under both the ADF test and KPSS test columns. However, I cannot center the ADF test and KPSS columns, and I cannot place the values under each column exactly. C and C&T columns also do not fit under the At Level and First Difference columns.

The codes I use are as follows:

\documentclass{article} 
\usepackage{booktabs}
\begin{document}
\begin{table}[h!]
\caption{Summary statistics of the variables}
\bigskip
\begin{tabular}{@{}l ccccp{1.5cm} p{0.5cm} ccccp{1.5cm}@{}}
    \toprule
    & \multicolumn{2}{c}{ADF Test} & \phantom{ab} && \multicolumn{2}{c}{KPSS Test} & \phantom{ab}\\ \cmidrule{2-5}\cmidrule{6-9}    
    & At Level & & First \newline Difference && At Level & & First \newline  Difference \\ \cmidrule{2-3}\cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
    Variables & C & C\&T & C & C\&T && C & C\&T & C & C\&T \\ \midrule
    vix & -59.907*** & -59.903*** & -4.382*** & -4.460 && 0.73 & 0.13 & 0.07 & -1.05 \\
    NSP & -0.74 & -2.16 & -6.98*** & -1.05 && 0.77 & 0.16 & 0.1 & -1.05\\
    \bottomrule
\end{tabular}
\end{table}
\end{document}
3
  • Welcome to TeX.SE.
    – Mico
    Oct 2, 2021 at 10:27
  • Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Oct 2, 2021 at 10:31
  • I've taken the liberty of augmenting your code (added three lines at the top, and one at the bottom) in order to make it minimally compilable. Feel free to revert.
    – Mico
    Oct 2, 2021 at 11:10

3 Answers 3

2

Like this?

enter image description here

(red lines indicate part of page layout)

Edit: MWE now consider @Mico suggestions (thank you very much, Mico!)

With use of tabularray package and its libraries booktabs and siunitx. Since table is quite wide, reduced are font size and column separation:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}


\begin{document}
    \begin{table}[ht]
    \sisetup{round-mode=places, % <---added
             round-precision=2,
             tight-spacing,
             }
\caption{ADF and KPSS test of (non)stationarity}
    \centering
    \small                 % <---
\begin{tblr}{colsep=4pt,   % <---
             colspec={@{} l *{2}{Q[c,si={table-format=-2.2{***} }]} % <--- changed
                                 Q[c,si={table-format=-1.2{***} }]  % <--- changed
                            *{5}{Q[c,si={table-format=-1.2}]}
                      @{} },
             row{1}={font=\bfseries} 
            }
    \toprule
    & \SetCell[c=4]{c} {{{ADF Test}}}    &   &   &    
        & \SetCell[c=4]{c}  {{{KPSS Test}}}    &   &    &   \\ 
    \cmidrule[r]{2-5}  \cmidrule[l]{6-9}
    & \SetCell[c=2]{c} {{{At Level}}}    &   
        & \SetCell[c=2]{c} {{{1st Diff.}}}  &
            & \SetCell[c=2]{c} {{{At Level}}}  &
                & \SetCell[c=2]{c} {{{1st Diff.}}}  \\
    \cmidrule[r]{2-3}   \cmidrule[lr]{4-5} 
    \cmidrule[lr]{6-7}  \cmidrule[lr]{8-9}
Variables   & {{{C}}} & {{{C\&T}}}  
                & {{{C}}} & {{{C\&T}}}
                    & {{{C}}} & {{{C\&T}}}
                        & {{{C}}} & {{{C\&T}}}\\ 
    \midrule
vix         & -59.907*** 
                & -59.903***
                    & -4.382***
                        & -4.460
                            & 0.73
                                & 0.13
                                    & 0.07
                                        & -1.05 \\
NSP         & -0.74     
                & -2.16 
                    & -6.98*** 
                        & -1.05 
                            & 0.77 
                                & 0.16 
                                    & 0.1 
                                        & -1.05\\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}
3
  • See my comment under one of the other answers: It's not good form to write "Difference", as in these tests one can be dealing with both first and higher-order differences. Also, I think there's no reason for showing third decimals; 2 decimals should be more than enough (and eliminating them simplifies/streamlines the table noticeably).
    – Mico
    Oct 2, 2021 at 13:18
  • 1
    @Mico, you are right. For my excuse, I just tried to reproduce desired form of table and consequently I didn't dig into the meaning of its content. I will edit my answer ASAP (hopefully site will be available next few hours) and correct it considering your advice.
    – Zarko
    Oct 2, 2021 at 17:07
  • Thank you very much indeed for your answer Zarko, it really helped me a lot. Oct 3, 2021 at 12:29
3

I would use 8 c but no p columns for the 8 tests. I would also strive to use the same number of significant digits throughout. If need be, consider aligning the numbers on the decimal markers.

Oh, and do try to provide a caption that's a tad more informative than "Summary statistics of the variables". In the code below, I suggest "ADF and KPSS tests of (non)stationarity". [Aside: I'm an econometrician. I'm rather familiar with both ADF and KPSS tests, in no small part because the "P" in "KPSS" denotes the first letter of my thesis adviser's surname...)

enter image description here

\documentclass{article} 
\usepackage{booktabs}
\newcommand\sym[1]{\ifmmode{^{#1}}\else{$^{#1}$}\fi}
\begin{document}

\begin{table}[h!]
\setlength\tabcolsep{0pt} % let LaTeX figure out amount of intercol. whitespace
\caption{ADF and KPSS tests of (non)stationarity\strut}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{c}}
    \toprule
    & \multicolumn{4}{c}{ADF Test} & \multicolumn{4}{c}{KPSS Test} \\ 
    \cmidrule{2-5} \cmidrule{6-9}    
    & \multicolumn{2}{c}{At Level} & \multicolumn{2}{c}{First Diff.}
    & \multicolumn{2}{c}{At Level} & \multicolumn{2}{c}{First Diff.} \\ 
    \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
    Variables & C & C\&T & C & C\&T & C & C\&T & C & C\&T \\ 
    \midrule
    VIX & $-$59.91\sym{***} & $-$59.90\sym{***} 
        &  $-$4.38\sym{***} & $ -$4.46 
        & 0.73 & 0.13 & 0.07 & $-$1.05 \\
    NSP & \hphantom{0}$-$0.74\hphantom{\sym{***}} 
        & \hphantom{0}$-$2.16\hphantom{\sym{***}} 
        & $-$6.98\sym{***} & $-$1.05 
        & 0.77 & 0.16 & 0.10 & $-$1.05\\
    \bottomrule
\end{tabular*}
\end{table}

\end{document}
13
  • 1
    @Dr.ManuelKuehner - The macro Isn't a test for math mode, it just starts with a test for math mode. If the condition is true, ^{#1} is executed; if it's not, $^{#1}$ is executed. I suppose the outer curly braces aren't necessary. Writing newcommand\sym[1]{\ifmmode^{#1}\else$^{#1}$\fi} would have been more parsimonious -- though not easier for humans to read.
    – Mico
    Oct 2, 2021 at 20:59
  • 1
    @Dr.ManuelKuehner - Many thanks for my aside being a "cool remark". :-) My adviser (Peter Phillips) was one of the early researchers of the properties of various types of non-stationarity. My thesis didn't involve the ADF and KPSS tests, though. Instead, I looked into the properties of tests of constancy of (unconditional) second moments if the observed time series are leptokurtic ("heavy-tailed"). The asymptotic theory I developed relied heavily on the properties of stable distributions. I've pursued a non-academic career, but I've never regretted having written a "far-out" thesis. :-)
    – Mico
    Oct 2, 2021 at 21:17
  • 1
    Thanks a lot. I will have a look at the references. I really enjoy the community here, I learn about TeX and beyond. Oct 5, 2021 at 14:20
  • 1
    @Dr.ManuelKuehner - You're most welcome. A minor correction: The research conference in Eltville, Germany was held in late 2005, not late 2006.
    – Mico
    Oct 5, 2021 at 15:58
  • 1
    I just now actually see that you wrote that you have worked for "The Mandelbrot"! Sometimes the text does not go from the eyes to the brain :). That's a cool side note. Oct 5, 2021 at 22:11
1

Edited to take into account @Mico 's comment

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[h!]
\caption{Summary statistics of the variables}
\bigskip
\begin{tabular}{l *8c}
    \toprule
    & \multicolumn{4}{c}{ADF Test} & \multicolumn{4}{c}{KPSS Test} \\ \cmidrule(rl){2-5}\cmidrule(rl){6-9}    
    & \multicolumn{2}{c}{At Level }& \multicolumn{2}{c}{Difference} & \multicolumn{2}{c}{At Level }& \multicolumn{2}{c}{Difference} \\ \cmidrule(rl){2-3}\cmidrule(rl){4-5} \cmidrule(rl){6-7} \cmidrule{8-9}
    Variables & C & C\&T & C & C\&T & C & C\&T & C & C\&T \\ \midrule
    vix & -59.907*** & -59.903*** & -4.382*** & -4.460 & 0.73 & 0.13 & 0.07 & -1.05 \\
    NSP & -0.74 & -2.16 & -6.98*** & -1.05 & 0.77 & 0.16 & 0.1 & -1.05\\
    \bottomrule
\end{tabular}
\end{table}


\end{document}

enter image description here

4
  • For these tests, you can't just write "difference", as (depending on the circumstance) it could be the first, second or very (rarely) third difference. A separate issue: Your setup offers no assurance that the table will fit inside the text block. (In fact, when I compile your code, LaTeX complains that the table is ca 1.5cm too wide.)
    – Mico
    Oct 2, 2021 at 12:01
  • Hi @Mico. I have delete inadvertently the word #First" before "Difference". You are write the table is too wide and we can fix it as you did by \setlength\tabcolsep{0pt} Oct 2, 2021 at 13:07
  • One respect in which the table in "Zarko"'s answer is better than the one is this answer is that it uses genuine minus signs rather than hyphens. I presume you could get the same effect here by setting the numbers (including, of course, the minus signs) in math mode. Oct 2, 2021 at 20:26
  • Thank you @Mico Oct 2, 2021 at 21:25

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.