[Tex/LaTex] Help with long table from Stargazer

longtablertables

I have a table made in R with Stargazer however, it is too big to fit a page in LyX. I have tried to use \longtable but it doesn't seem to work (might be doing it wrong). Here is the original code

\begin{table}[!htbp] \centering 
  \caption{Modellerne} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lcc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & \multicolumn{2}{c}{lprice} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 larea & 0.911$^{***}$ & 0.956$^{***}$ \\ 
  & (0.011) & (0.007) \\ 
  bathrooms & 0.059$^{***}$ & 0.060$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  floor & 0.020$^{***}$ & 0.020$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  rebuild00 & 0.062$^{***}$ & 0.067$^{***}$ \\ 
  & (0.011) & (0.011) \\ 
  roof\_cemen & $-$0.107$^{***}$ & $-$0.118$^{***}$ \\ 
  & (0.020) & (0.020) \\ 
  roof\_fiber & $-$0.068$^{***}$ & $-$0.075$^{***}$ \\ 
  & (0.009) & (0.008) \\ 
  roof\_board & $-$0.079$^{***}$ & $-$0.085$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_flat & $-$0.099$^{***}$ & $-$0.108$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_tile & $-$0.075$^{***}$ & $-$0.076$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  in1 & $-$0.031 & $-$0.038 \\ 
  & (0.035) & (0.035) \\ 
  in2 & $-$0.025$^{**}$ & $-$0.022$^{**}$ \\ 
  & (0.010) & (0.010) \\ 
  in3 & $-$0.038$^{***}$ & $-$0.035$^{***}$ \\ 
  & (0.007) & (0.007) \\ 
  in4 & $-$0.011$^{**}$ & $-$0.011$^{**}$ \\ 
  & (0.005) & (0.005) \\ 
  big\_roadsCon & $-$1.595$^{***}$ & $-$1.763$^{***}$ \\ 
  & (0.170) & (0.170) \\ 
  lrailways & 0.036$^{***}$ & 0.032$^{***}$ \\ 
  & (0.003) & (0.003) \\ 
  allgoods & 0.00004$^{***}$ & 0.0001$^{***}$ \\ 
  & (0.00001) & (0.00001) \\ 
  rental & $-$0.00004$^{***}$ & $-$0.0001$^{***}$ \\ 
  & (0.00000) & (0.00000) \\ 
  lIncome & 0.081$^{***}$ & 0.075$^{***}$ \\ 
  & (0.010) & (0.008) \\ 
  EducShort & $-$0.104$^{***}$ & $-$0.100$^{***}$ \\ 
  & (0.014) & (0.014) \\ 
  EducMed & $-$0.032$^{***}$ & $-$0.031$^{***}$ \\ 
  & (0.005) & (0.004) \\ 
  Wealth & $-$0.001$^{***}$ &  \\ 
  & (0.0002) &  \\ 
  Single & $-$0.013$^{**}$ &  \\ 
  & (0.006) &  \\ 
  shopservice & 0.003$^{***}$ &  \\ 
  & (0.0004) &  \\ 
  residents & $-$0.00000$^{***}$ &  \\ 
  & (0.00000) &  \\ 
  rooms & 0.016$^{***}$ &  \\ 
  & (0.003) &  \\ 
  Constant & 10.165$^{***}$ & 10.112$^{***}$ \\ 
  & (0.047) & (0.034) \\ 
 \hline \\[-1.8ex] 
Observations & 8,880 & 8,880 \\ 
R$^{2}$ & 0.809 & 0.806 \\ 
Adjusted R$^{2}$ & 0.809 & 0.805 \\ 
Residual Std. Error & 0.189 (df = 8854) & 0.190 (df = 8859) \\ 
F Statistic & 1,501.224$^{***}$ (df = 25; 8854) & 1,837.336$^{***}$ (df 
= 20; 8859) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; 
$^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

Does anybody know how to make the table fit over two pages?
Thank you

Best Answer

A table enviroment cannot be broken across pages. Delete \begin{table}\centering and \end{table}, replace tabular with longtable, move \caption and label to immediately after \begin{longtable}{..}. And add \usepackage{longtable} to the preamble, of course.

enter image description here

\documentclass{article}
\usepackage{longtable}

\begin{document}

\begin{longtable}{@{\extracolsep{5pt}}lcc} 
 \caption{Modellerne \label{foo}}   \\
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & \multicolumn{2}{c}{lprice} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 larea & 0.911$^{***}$ & 0.956$^{***}$ \\ 
  & (0.011) & (0.007) \\ 
  bathrooms & 0.059$^{***}$ & 0.060$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  floor & 0.020$^{***}$ & 0.020$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  rebuild00 & 0.062$^{***}$ & 0.067$^{***}$ \\ 
  & (0.011) & (0.011) \\ 
  roof\_cemen & $-$0.107$^{***}$ & $-$0.118$^{***}$ \\ 
  & (0.020) & (0.020) \\ 
  roof\_fiber & $-$0.068$^{***}$ & $-$0.075$^{***}$ \\ 
  & (0.009) & (0.008) \\ 
  roof\_board & $-$0.079$^{***}$ & $-$0.085$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_flat & $-$0.099$^{***}$ & $-$0.108$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_tile & $-$0.075$^{***}$ & $-$0.076$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  in1 & $-$0.031 & $-$0.038 \\ 
  & (0.035) & (0.035) \\ 
  in2 & $-$0.025$^{**}$ & $-$0.022$^{**}$ \\ 
  & (0.010) & (0.010) \\ 
  in3 & $-$0.038$^{***}$ & $-$0.035$^{***}$ \\ 
  & (0.007) & (0.007) \\ 
  in4 & $-$0.011$^{**}$ & $-$0.011$^{**}$ \\ 
  & (0.005) & (0.005) \\ 
  big\_roadsCon & $-$1.595$^{***}$ & $-$1.763$^{***}$ \\ 
  & (0.170) & (0.170) \\ 
  lrailways & 0.036$^{***}$ & 0.032$^{***}$ \\ 
  & (0.003) & (0.003) \\ 
  allgoods & 0.00004$^{***}$ & 0.0001$^{***}$ \\ 
  & (0.00001) & (0.00001) \\ 
  rental & $-$0.00004$^{***}$ & $-$0.0001$^{***}$ \\ 
  & (0.00000) & (0.00000) \\ 
  lIncome & 0.081$^{***}$ & 0.075$^{***}$ \\ 
  & (0.010) & (0.008) \\ 
  EducShort & $-$0.104$^{***}$ & $-$0.100$^{***}$ \\ 
  & (0.014) & (0.014) \\ 
  EducMed & $-$0.032$^{***}$ & $-$0.031$^{***}$ \\ 
  & (0.005) & (0.004) \\ 
  Wealth & $-$0.001$^{***}$ &  \\ 
  & (0.0002) &  \\ 
  Single & $-$0.013$^{**}$ &  \\ 
  & (0.006) &  \\ 
  shopservice & 0.003$^{***}$ &  \\ 
  & (0.0004) &  \\ 
  residents & $-$0.00000$^{***}$ &  \\ 
  & (0.00000) &  \\ 
  rooms & 0.016$^{***}$ &  \\ 
  & (0.003) &  \\ 
  Constant & 10.165$^{***}$ & 10.112$^{***}$ \\ 
  & (0.047) & (0.034) \\ 
 \hline \\[-1.8ex] 
Observations & 8,880 & 8,880 \\ 
R$^{2}$ & 0.809 & 0.806 \\ 
Adjusted R$^{2}$ & 0.809 & 0.805 \\ 
Residual Std. Error & 0.189 (df = 8854) & 0.190 (df = 8859) \\ 
F Statistic & 1,501.224$^{***}$ (df = 25; 8854) & 1,837.336$^{***}$ (df 
= 20; 8859) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; 
$^{***}$p$<$0.01} \\ 
\end{longtable} 

\end{document}
Related Question