1

I am trying to produce a latex table from Stata, and I want to group my regressions and add titles. So I used Stata code "esttab, mygroup()". However the table created by this code looks like this: there is no gap between the two groups

and i want it to look like this: enter image description here

I knew this could be done manually in Latex by inserting an empty column. But is there a more convenient way?

Many thanks in advance!

2
  • 1
    Could you please add a minimal working example (MWE) that allows others to reproduce the output you show? If your code uses \cmidrule from booktabs, you might want to use \cmidrule(r){2-3} \cmidrule(l){4-5} in order to get the small gap in the horizontal line.
    – leandriis
    Commented Aug 25, 2019 at 15:00
  • It looks like you've got two separate accounts, which means you cannot edit your original post or leave comments. The Stack Exchange staff can merge them together for you.
    – Mensch
    Commented Aug 26, 2019 at 2:00

3 Answers 3

2

It seems that you looking for this:

enter image description here

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{l*{4}{c}}
    \toprule
    &\multicolumn{2}{c}{Weight}             
                            &\multicolumn{2}{c}{Length} \\
    \cmidrule(l){2-3}   \cmidrule(l){4-5}
    & (1)       & (2)       & (3)       & (4)       \\
    & {price}   & {price}   & {price}   & {price}   \\
    \midrule
weight  &       &           &           &           \\
    \bottomrule
\end{tabular}

However, your table have other issues too (aligning numbers in table, etc). For this you should look siunitx and threeparttable package if it can help you in table design.

As an example of similar table design see this answer.

0

You can add empty space by inserting @{\hskip amountOfSpace} between the specifiers, see minimal example 1. You can also add other things between the columns insted of the standard space, try e.g. example 2

First example:

\begin{tabular}{l@{\hskip 1cm}c@{\hskip 2cm}c}
    Djamble&Ha& Blar\\
    Foo& Bar& Barfoo
\end{tabular}

Second example:

\begin{tabular}{l@{ or }c@{\hskip 2cm}c}
    Djamble&Ha& Blar\\
    Foo& Bar& Barfoo
\end{tabular}

Screenshot of output on my machine

1
  • In their question, the OP showed an image of the desired output that has a small gap in the horizontal line. Could you please add an explanation on how one can achieve such a gap with the approch in your answer?
    – leandriis
    Commented Aug 25, 2019 at 15:02
0

Thanks! The code for table titles shown in the image is:

\begin{tabular}{l*{4}{c}}
\hline\hline
            &\multicolumn{2}{c}{Weight}                 &\multicolumn{2}{c}{Length}                 \\\cline{2-3}\cline{4-5}
            &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\
            &\multicolumn{1}{c}{price}&\multicolumn{1}{c}{price}&\multicolumn{1}{c}{price}&\multicolumn{1}{c}{price}\\
\hline

\end{tabular}

and this is created automatically by Stata code:

eststo clear sysuse auto

eststo: qui reg price weight eststo: qui reg price weight foreign

eststo: qui reg price length eststo: qui reg price length foreign

esttab using example.tex, replace mgroups( "Weight" "Length" , pattern(1 0 1 0 ) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cline{@span}))

3
  • Do you have two accounts? Is this part of question above?
    – Zarko
    Commented Aug 26, 2019 at 0:22
  • It looks like you've got two separate accounts, which means you cannot edit your original post or leave comments. The Stack Exchange staff can merge them together for you.
    – Mensch
    Commented Aug 26, 2019 at 2:00
  • Yes, this is part of the question. I will merge the two accounts together. Thank you!
    – Jiaman Xu
    Commented Aug 26, 2019 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .