2

I am trying to format the below code so that the table looks as follows:

enter image description here

I have tried adding toprule and midrule, but I couldn't achieve my goal. Here is the code I have so far.

\documentclass[final,3p,times,12pt]{elsarticle}
\usepackage{lscape}

\begin{document}

\begin{landscape}
\begin{tabular}{lcccccc} 

\hline
 & (1) & (2) & (3) & (4) & (5) & (6) \\
\hline
 &  &  &  &  &  &  \\
X & 0.198*** & 0.216*** & 0.141*** & 0.324*** & 0.305*** & 0.189*** \\
 & (0.0472) & (0.0399) & (0.0394) & (0.0456) & (0.0407) & (0.0374) \\
X2 & 0.153** & 0.281*** & 0.282*** & 0.353*** & 0.518*** & 0.448*** \\
 & (0.0632) & (0.0627) & (0.0592) & (0.0854) & (0.0834) & (0.0718) \\
X3 & 0.0577 & -0.0426 & -0.0985* & 0.0102 & -0.133* & -0.158** \\
 & (0.0555) & (0.0519) & (0.0508) & (0.0715) & (0.0693) & (0.0628) \\
Number of Nonstop Carriers &  &  & -0.0105*** &  &  & -0.00816** \\
 &  &  & (0.00262) &  &  & (0.00350) \\
Bus Indicator &  &  & -0.118*** &  &  & -0.148*** \\
 &  &  & (0.00936) &  &  & (0.0137) \\
Other PMS Indicator &  &  & -0.0589*** &  &  & -0.0982*** \\
 &  &  & (0.00743) &  &  & (0.0101) \\
Share of Passengers Traveling Connect, City-Level &  &  & 0.129*** &  &  & 0.177*** \\
 &  &  & (0.0173) &  &  & (0.0192) \\
Share of Passengers Traveling Connect &  &  & 0.104*** &  &  & 0 \\
 &  &  & (0.0139) &  &  & (5.35e-09) \\
Log(Population) &  &  & 0.304*** &  &  & 0.341*** \\
 &  &  & (0.106) &  &  & (0.122) \\
Log(Income Per Capita) &  &  & 0.373*** &  &  & 0.318*** \\
 &  &  & (0.102) &  &  & (0.109) \\
Constant & 5.043*** & 6.100*** & 5.545*** & 4.936*** & 0.636 & 2.836*** \\
 & (0.0203) & (0.249) & (0.447) & (0.0279) & (0.586) & (0.669) \\
 &  &  &  &  &  &  \\
Observations & 1,237,878 & 1,237,878 & 1,209,791 & 262,534 & 262,534 & 255,173 \\
R-squared & 0.821 & 0.826 & 0.836 & 0.852 & 0.861 & 0.876 \\
Number of city-state pairs & 46510 & 46510 & 45244 &  &  &  \\
 Number of cities &  &  &  & 7190 & 7190 & 6911 \\ \hline
\multicolumn{7}{c}{ Robust standard errors in parentheses} \\
\multicolumn{7}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}

\end{landscape}




\end{document}               
2

Assuming that your question is not just about the partial horizontal lines but also about adding the two additional column header rows, I'd suggest the following: In the example, I have used booktabs for lines with a bit more vertical white space around them. Since the table will be too tall for a landscape page if we use these lines and add two more rows, I have removed the landscape environment. To make the table fit into the textwidth I have added linebreaks in the longer contents of the first column and also lightly decreased the font size. To provide a guide to the eye, I have added some vertical white space between the entries:

enter image description here

\documentclass[final,3p,times,12pt]{elsarticle}


\usepackage{booktabs}
\begin{document}
%\begin{landscape}
\noindent{\small \setlength{\tabcolsep}{4pt}
\begin{tabular}{@{}lcccccc@{}} 
\toprule
& \multicolumn{6}{c}{Dependent Variable: Y}\\
\cmidrule{2-7}
& \multicolumn{3}{c}{City-State Level} & \multicolumn{3}{c}{State-Level}\\
\cmidrule(r){2-4} \cmidrule(l){5-7}
 & (1) & (2) & (3) & (4) & (5) & (6) \\
\midrule
 &  &  &  &  &  &  \\
X & 0.198*** & 0.216*** & 0.141*** & 0.324*** & 0.305*** & 0.189*** \\
 & (0.0472) & (0.0399) & (0.0394) & (0.0456) & (0.0407) & (0.0374) \\ \addlinespace
X2 & 0.153** & 0.281*** & 0.282*** & 0.353*** & 0.518*** & 0.448*** \\
 & (0.0632) & (0.0627) & (0.0592) & (0.0854) & (0.0834) & (0.0718) \\ \addlinespace
X3 & 0.0577 & -0.0426 & -0.0985* & 0.0102 & -0.133* & -0.158** \\
 & (0.0555) & (0.0519) & (0.0508) & (0.0715) & (0.0693) & (0.0628) \\ \addlinespace
Number of Nonstop  &  &  & -0.0105*** &  &  & -0.00816** \\
Carriers &  &  & (0.00262) &  &  & (0.00350) \\ \addlinespace
Bus Indicator &  &  & -0.118*** &  &  & -0.148*** \\
 &  &  & (0.00936) &  &  & (0.0137) \\ \addlinespace
Other PMS Indicator &  &  & -0.0589*** &  &  & -0.0982*** \\
 &  &  & (0.00743) &  &  & (0.0101) \\ \addlinespace
Share of Passengers Traveling  &  &  & 0.129*** &  &  & 0.177*** \\
Connect, City-Level &  &  & (0.0173) &  &  & (0.0192) \\ \addlinespace
Share of Passengers Traveling  &  &  & 0.104*** &  &  & 0 \\
Connect &  &  & (0.0139) &  &  & (5.35e-09) \\ \addlinespace
Log(Population) &  &  & 0.304*** &  &  & 0.341*** \\
 &  &  & (0.106) &  &  & (0.122) \\ \addlinespace
Log(Income Per Capita) &  &  & 0.373*** &  &  & 0.318*** \\
 &  &  & (0.102) &  &  & (0.109) \\ \addlinespace
Constant & 5.043*** & 6.100*** & 5.545*** & 4.936*** & 0.636 & 2.836*** \\
 & (0.0203) & (0.249) & (0.447) & (0.0279) & (0.586) & (0.669) \\ \addlinespace
 &  &  &  &  &  &  \\
Observations & 1,237,878 & 1,237,878 & 1,209,791 & 262,534 & 262,534 & 255,173 \\
R-squared & 0.821 & 0.826 & 0.836 & 0.852 & 0.861 & 0.876 \\
Number of city-state pairs & 46510 & 46510 & 45244 &  &  &  \\
 Number of cities &  &  &  & 7190 & 7190 & 6911 \\ \midrule
\multicolumn{7}{c}{ Robust standard errors in parentheses} \\
\multicolumn{7}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}}

%\end{landscape}




\end{document}  
  • thank you so much. Works very well! – Job Jun 12 at 19:46
2

booktabs package for partial rules:

\documentclass[final,3p,times,12pt]{elsarticle}
\usepackage{lscape}

\usepackage{booktabs}

\begin{document}

\begin{landscape}
\begin{tabular}{lcccccc} 
\toprule
& \multicolumn{6}{c}{"Dependent Variable: Log(Average Fare)"} \\
\cmidrule{2-7}
& \multicolumn{3}{c}{City} & \multicolumn{3}{c}{State}\\
\cmidrule(r){2-4}\cmidrule(l){5-7}
 & (1) & (2) & (3) & (4) & (5) & (6) \\
\addlinespace
X & 0.198*** & 0.216*** & 0.141*** & 0.324*** & 0.305*** & 0.189*** \\
 & (0.0472) & (0.0399) & (0.0394) & (0.0456) & (0.0407) & (0.0374) \\
 \bottomrule
\end{tabular}

\end{landscape}




\end{document}   

enter image description here

  • your answer is extremely helpful. I have just one followup question. When the "Dependent Variable" part is long, it doesn't fit into the middle. In other words, then I have "Dependent Variable: Log(Average Fare)", the top parts doesn't enline anymore. Any questions? – Job Jun 12 at 19:36
  • @Job I don't understand "doesn't enline anymore". Can you please rephrase? – Dynamite Jun 12 at 19:42
  • For some reason the first column title "Dependent Variable: Log(Average Fare)" was staying on the left side (i.e., not centering). But the code below somehow overcomes this (i.e., when I use the entire data, this issue doesn't appear). Your answer was very helpful!!! Thanks so much! – Job Jun 12 at 19:46
  • 1
    @Job Nice to hear it was helpful! – Dynamite Jun 12 at 19:47

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.