Longtable not working with Stargazer Table

longtabletables

I am trying to make a table span many pages. Here is my code:

\begin{table}[!htbp] \centering 
  \caption{Results for Living Standard Indicators} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{3}{c}{\textit{Dependent variable:}} \\ 
\cline{2-4} 
\\[-1.8ex] & $K_{i,t}$ & $H_{i,t}$ & $I_{i,t}$ \\ 
 & Physical Capital & Human Capital & Institutional Capital \\ 
\\[-1.8ex] & (1) & (2) & (3)\\ 
\hline \\[-1.8ex] 
 $R_{i}$ & $-$0.10$^{***}$ & $-$0.05 & 0.08 \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$^{2}$ & $-$0.002 & $-$0.01$^{**}$ & $-$0.01 \\ 
  & (0.002) & (0.004) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$ & 0.13$^{*}$ & 0.69$^{***}$ & 0.22 \\ 
  & (0.07) & (0.18) & (0.42) \\ 
  & & & \\ 
 $R_{i}$*$NR_{i}$ & $-$0.50$^{***}$ & 0.18 & $-$0.98$^{*}$ \\ 
  & (0.09) & (0.23) & (0.56) \\ 
  & & & \\ 
 $R_{i}$*$D_{i}$ & 0.01 & 0.05 & 0.11 \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  & & & \\ 
 $R_{i}$*$L_{i}$ & 0.0004 & $-$0.05 & $-$0.23$^{***}$ \\ 
  & (0.01) & (0.03) & (0.06) \\ 
  & & & \\ 
 $R_{i}$*$V_{i}$ & 0.02$^{**}$ & $-$0.06$^{*}$ & $-$0.12$^{***}$ \\ 
  & (0.01) & (0.03) & (0.04) \\ 
  & & & \\ 
 $R_{i}$*$C_{i}$ & 0.03$^{**}$ & $-$0.08$^{**}$ & $-$0.17$^{**}$ \\ 
  & (0.01) & (0.04) & (0.07) \\ 
  & & & \\ 
 $R_{i}$*$M_{i}$ & $-$0.01 & $-$0.04$^{**}$ & 0.09$^{***}$ \\ 
  & (0.01) & (0.02) & (0.03) \\ 
  & & & \\ 
 $R_{i}$*$S_{i}$ & 0.04$^{***}$ & 0.23$^{***}$ & 0.19$^{**}$ \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  & & & \\ 
 $R_{i}$*$Dem_{i}$ & 0.05$^{***}$ & 0.07$^{***}$ & 0.07 \\ 
  & (0.02) & (0.02) & (0.05) \\ 
  & & & \\ 
 $R_{i}$*$Right_{i}$ & $-$0.02 & $-$0.03 & $-$0.20$^{*}$ \\ 
  & (0.02) & (0.05) & (0.10) \\ 
  & & & \\ 
 $R_{i}$*$Left_{i} & 0.02 & $-$0.03 & $-$0.08 \\ 
  & (0.01) & (0.05) & (0.07) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$L_{i}$ & $-$0.01 & $-$0.37$^{*}$ & $-$0.52 \\ 
  & (0.07) & (0.19) & (0.37) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$V_{i}$ & 0.001 & 0.51$^{***}$ & 0.18 \\ 
  & (0.05) & (0.12) & (0.22) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$C_{i}$ & $-$0.08 & $-$0.33$^{**}$ & $-$0.80$^{**}$ \\ 
  & (0.06) & (0.16) & (0.36) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$M_{i}$ & $-$0.01 & $-$0.17$^{**}$ & 0.14 \\ 
  & (0.03) & (0.08) & (0.16) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$S_{i}$ & $-$0.01 & $-$0.86$^{***}$ & 0.87$^{**}$ \\ 
  & (0.08) & (0.20) & (0.42) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$Dem_{i} & 0.10$^{*}$ & $-$0.14 & 0.07 \\ 
  & (0.05) & (0.09) & (0.27) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$Left_{i}$ & 0.02 & $-$0.67$^{***}$ & 0.31 \\ 
  & (0.05) & (0.20) & (0.29) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$Right_{i}$ & 0.15$^{*}$ & 0.39 & 0.11 \\ 
  & (0.08) & (0.24) & (0.53) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$D_{i}$ & $-$0.29$^{***}$ & $-$0.35$^{**}$ & 0.59$^{*}$ \\ 
  & (0.07) & (0.16) & (0.32) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}$*$NR_{i}$ & 0.56 & 0.83 & 1.05 \\ 
  & (0.39) & (1.15) & (2.35) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$L_{i}$ & $-$0.002 & 0.003 & $-$0.02$^{*}$ \\ 
  & (0.002) & (0.005) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$V_{i}$ & $-$0.0001 & $-$0.004$^{*}$ & 0.004 \\ 
  & (0.001) & (0.002) & (0.004) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$C_{i}$ & 0.003$^{**}$ & 0.01$^{*}$ & 0.01$^{*}$ \\ 
  & (0.001) & (0.003) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$M_{i}$ & $-$0.001 & 0.003$^{*}$ & $-$0.001 \\ 
  & (0.001) & (0.002) & (0.004) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$S_{i}$ & $-$0.0005 & 0.01$^{***}$ & $-$0.01$^{**}$ \\ 
  & (0.002) & (0.003) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$Dem_{i}$ & $-$0.001 & 0.001 & 0.01 \\ 
  & (0.001) & (0.002) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$D_{i}$ & 0.001 & 0.01 & $-$0.01 \\ 
  & (0.002) & (0.004) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$NR_{i}$ & $-$0.01 & $-$0.004 & 0.02 \\ 
  & (0.01) & (0.04) & (0.08) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$Left_{i}$ & 0.004$^{**}$ & 0.01$^{**}$ & 0.02$^{***}$ \\ 
  & (0.001) & (0.005) & (0.01) \\ 
  & & & \\ 
 $R_{i}$*$Y_{i,t}^{2}$*$Right_{i}$ & $-$0.0003 & $-$0.003 & 0.01 \\ 
  & (0.001) & (0.003) & (0.01) \\ 
  & & & \\ 
 Constant & 0.05$^{***}$ & 0.22$^{***}$ & 0.42$^{***}$ \\ 
  & (0.01) & (0.03) & (0.05) \\ 
  & & & \\ 
\hline \\[-1.8ex] 
F Statistic & 20.67*** & 84.70*** & 39.09*** \\ 
Observations & 1,053 & 1,053 & 1,053 \\ 
R$^{2}$ & 0.28 & 0.56 & 0.44 \\ 
Adjusted R$^{2}$ & 0.25 & 0.54 & 0.42 \\ 
Residual Std. Error (df = 1002) & 0.08 & 0.16 & 0.26 \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{3}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table}

I have tried to incorporate longtable, but it does not work for me. The table was created using the stargazer package in R-Studio, and then imported into Overleaf. Has anyone run into a similar problem? Is this a stargazer limitation and if so how would I overcome this?

Thanks in advance!

Best Answer

Here's an adaptation of your code that employs a longtable environment. Observe that I had to fix a number of issues with your code in addition to changing over from a table/tabular combination to a longtable. Among them are a replacement of all instances of $*$ with \times and a replacement of all instances of & & & \\ with \addlinespace, a macro provided by the booktabs package.

The following screenshot shows just the first few rows of the resulting table.

enter image description here

\documentclass{article}
\usepackage{longtable,booktabs}
\newcommand{\vn}[1]{\mathit{#1}}

\begin{document}
   
\begin{longtable}{@{} l ccc @{}} 
\caption{Results for Living Standard Indicators} 
  \label{tab:results}\\
\toprule
 & \multicolumn{3}{c}{Dependent variables} \\ 
\cmidrule(l){2-4}
 & $K_{i,t}$ & $H_{i,t}$ & $I_{i,t}$ \\ 
 & Physical Capital & Human Capital & Instit.\ Capital \\ 
 & (1) & (2) & (3) \\ 
\midrule
\endfirsthead

\multicolumn{4}{@{}l}{Table \thetable, continued}\\
\addlinespace
\toprule
 & \multicolumn{3}{c}{Dependent variables} \\ 
\cmidrule(l){2-4}
 & $K_{i,t}$ & $H_{i,t}$ & $I_{i,t}$ \\ 
 & Physical Capital & Human Capital & Instit.\ Capital \\ 
 & (1) & (2) & (3) \\ 
\midrule
\endhead

\midrule
\endfoot

\bottomrule
\addlinespace
\multicolumn{4}{@{}l}{\textit{Note}: $^{*}\ p<0.1$; $^{**}\ p<0.05$; $^{***}\ p<0.01$} 
\endlastfoot

 $R_{i}$ & $-$0.10$^{***}$ & $-$0.05 & 0.08 \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}$ & $-$0.002 & $-$0.01$^{**}$ & $-$0.01 \\ 
  & (0.002) & (0.004) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}$ & 0.13$^{*}$ & 0.69$^{***}$ & 0.22 \\ 
  & (0.07) & (0.18) & (0.42) \\ 
  \addlinespace 
 $R_{i}\times \vn{NR}_{i}$ & $-$0.50$^{***}$ & 0.18 & $-$0.98$^{*}$ \\ 
  & (0.09) & (0.23) & (0.56) \\ 
  \addlinespace 
 $R_{i}\times D_{i}$ & 0.01 & 0.05 & 0.11 \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  \addlinespace 
 $R_{i}\times L_{i}$ & 0.0004 & $-$0.05 & $-$0.23$^{***}$ \\ 
  & (0.01) & (0.03) & (0.06) \\ 
  \addlinespace 
 $R_{i}\times V_{i}$ & 0.02$^{**}$ & $-$0.06$^{*}$ & $-$0.12$^{***}$ \\ 
  & (0.01) & (0.03) & (0.04) \\ 
  \addlinespace 
 $R_{i}\times C_{i}$ & 0.03$^{**}$ & $-$0.08$^{**}$ & $-$0.17$^{**}$ \\ 
  & (0.01) & (0.04) & (0.07) \\ 
  \addlinespace 
 $R_{i}\times M_{i}$ & $-$0.01 & $-$0.04$^{**}$ & 0.09$^{***}$ \\ 
  & (0.01) & (0.02) & (0.03) \\ 
  \addlinespace 
 $R_{i}\times S_{i}$ & 0.04$^{***}$ & 0.23$^{***}$ & 0.19$^{**}$ \\ 
  & (0.02) & (0.04) & (0.08) \\ 
  \addlinespace 
 $R_{i}\times \vn{Dem}_{i}$ & 0.05$^{***}$ & 0.07$^{***}$ & 0.07 \\ 
  & (0.02) & (0.02) & (0.05) \\ 
  \addlinespace 
 $R_{i}\times \vn{Right}_{i}$ & $-$0.02 & $-$0.03 & $-$0.20$^{*}$ \\ 
  & (0.02) & (0.05) & (0.10) \\ 
  \addlinespace 
 $R_{i}\times \vn{Left}_{i}$ & 0.02 & $-$0.03 & $-$0.08 \\ 
  & (0.01) & (0.05) & (0.07) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times L_{i}$ & $-$0.01 & $-$0.37$^{*}$ & $-$0.52 \\ 
  & (0.07) & (0.19) & (0.37) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times V_{i}$ & 0.001 & 0.51$^{***}$ & 0.18 \\ 
  & (0.05) & (0.12) & (0.22) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times C_{i}$ & $-$0.08 & $-$0.33$^{**}$ & $-$0.80$^{**}$ \\ 
  & (0.06) & (0.16) & (0.36) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times M_{i}$ & $-$0.01 & $-$0.17$^{**}$ & 0.14 \\ 
  & (0.03) & (0.08) & (0.16) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times S_{i}$ & $-$0.01 & $-$0.86$^{***}$ & 0.87$^{**}$ \\ 
  & (0.08) & (0.20) & (0.42) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times \vn{Dem}_{i}$ & 0.10$^{*}$ & $-$0.14 & 0.07 \\ 
  & (0.05) & (0.09) & (0.27) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times \vn{Left}_{i}$ & 0.02 & $-$0.67$^{***}$ & 0.31 \\ 
  & (0.05) & (0.20) & (0.29) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times \vn{Right}_{i}$ & 0.15$^{*}$ & 0.39 & 0.11 \\ 
  & (0.08) & (0.24) & (0.53) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times D_{i}$ & $-$0.29$^{***}$ & $-$0.35$^{**}$ & 0.59$^{*}$ \\ 
  & (0.07) & (0.16) & (0.32) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}\times \vn{NR}_{i}$ & 0.56 & 0.83 & 1.05 \\ 
  & (0.39) & (1.15) & (2.35) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times L_{i}$ & $-$0.002 & 0.003 & $-$0.02$^{*}$ \\ 
  & (0.002) & (0.005) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times V_{i}$ & $-$0.0001 & $-$0.004$^{*}$ & 0.004 \\ 
  & (0.001) & (0.002) & (0.004) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times C_{i}$ & 0.003$^{**}$ & 0.01$^{*}$ & 0.01$^{*}$ \\ 
  & (0.001) & (0.003) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times M_{i}$ & $-$0.001 & 0.003$^{*}$ & $-$0.001 \\ 
  & (0.001) & (0.002) & (0.004) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times S_{i}$ & $-$0.0005 & 0.01$^{***}$ & $-$0.01$^{**}$ \\ 
  & (0.002) & (0.003) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times \vn{Dem}_{i}$ & $-$0.001 & 0.001 & 0.01 \\ 
  & (0.001) & (0.002) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times D_{i}$ & 0.001 & 0.01 & $-$0.01 \\ 
  & (0.002) & (0.004) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times \vn{NR}_{i}$ & $-$0.01 & $-$0.004 & 0.02 \\ 
  & (0.01) & (0.04) & (0.08) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times \vn{Left}_{i}$ & 0.004$^{**}$ & 0.01$^{**}$ & 0.02$^{***}$ \\ 
  & (0.001) & (0.005) & (0.01) \\ 
  \addlinespace 
 $R_{i}\times Y_{i,t}^{2}\times \vn{Right}_{i}$ & $-$0.0003 & $-$0.003 & 0.01 \\ 
  & (0.001) & (0.003) & (0.01) \\ 
  \addlinespace 
 Constant & 0.05$^{***}$ & 0.22$^{***}$ & 0.42$^{***}$ \\ 
  & (0.01) & (0.03) & (0.05) \\ 
\midrule 
$F$-Statistic & 20.67$^{***}$ & 84.70$^{***}$ & 39.09$^{***}$ \\ 
Observations & 1,053 & 1,053 & 1,053 \\ 
$R^{2}$ & 0.28 & 0.56 & 0.44 \\ 
Adjusted $R^{2}$ & 0.25 & 0.54 & 0.42 \\ 
Res.\ Std.\ Error  & 0.08 & 0.16 & 0.26 \\ 
\quad ($\vn{df} = 1{,}002$)
\end{longtable} 
\end{document}