0

I have been navigating around for some time, trying to find the answer to my problem. I have made a few regression in R and want to export them with the stargazer package into LaTeX.

However, because of the number of regression (6), the column do go over to oblivion. I have tried to reduce the intercolumn space, but with no success.

How is it possible to do so so that the table fits onto page page wide (I will delete some variables, as longtable is not compatible with stargazer. Thanks a lot for your time and help. Below is the simple export from R

\documentclass{article}
\usepackage{dcolumn}

\begin{document}

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Tue, May 15, 2018 - 11:03:04 AM
% Requires LaTeX packages: dcolumn 
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\small 
\begin{tabular}{@{\extracolsep{1pt}}lD{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} D{.}{.}{-3} } 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{6}{c}{\textit{Dependent variable:}} \\ 
\cline{2-7} 
\\[-1.8ex] & \multicolumn{6}{c}{FN} \\ 
\\[-1.8ex] & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} & \multicolumn{1}{c}{(6)}\\ 
\hline \\[-1.8ex] 
 Immig & -0.397^{***} & 0.209^{***} & 0.246^{***} & 0.161 & 0.701^{***} & -0.255^{***} \\ 
  & (0.010) & (0.047) & (0.066) & (0.101) & (0.147) & (0.088) \\ 
  Ref & 0.350^{***} & 0.397^{***} & 0.290^{***} & 0.255^{***} & 0.533^{***} & 0.238^{***} \\ 
  & (0.004) & (0.006) & (0.007) & (0.009) & (0.033) & (0.010) \\ 
  ImmigRef1 &  & -0.011^{***} & -0.007^{***} & -0.004^{**} & -0.019^{***} & 0.003 \\ 
  &  & (0.001) & (0.001) & (0.002) & (0.002) & (0.002) \\ 
  CAO &  &  & -0.900^{**} & -1.784 & 0.266 & -2.772^{***} \\ 
  &  &  & (0.420) & (1.391) & (0.408) & (0.748) \\ 
  Rur &  &  & 0.115 &  & 0.977 & 0.426^{***} \\ 
  &  &  & (0.127) &  & (4.161) & (0.159) \\ 
  LnInv &  &  & -2.625^{***} & -2.327^{***} & -6.017^{**} & -1.857^{***} \\ 
  &  &  & (0.327) & (0.368) & (2.631) & (0.442) \\ 
  LnMed &  &  & 12.479^{***} & 12.350^{***} & 7.328^{**} & 7.588^{***} \\ 
  &  &  & (0.600) & (0.709) & (2.860) & (0.899) \\ 
  Cho &  &  & 0.333^{***} & 0.285^{***} & 0.380^{***} & 0.329^{***} \\ 
  &  &  & (0.017) & (0.021) & (0.094) & (0.028) \\ 
  Cri &  &  & 1.737^{***} & 1.683^{***} & 1.244^{***} & 1.432^{***} \\ 
  &  &  & (0.045) & (0.057) & (0.157) & (0.063) \\ 
  LnPop17 &  &  & -1.817^{***} & -1.865^{***} & -1.136^{***} & -1.698^{***} \\ 
  &  &  & (0.071) & (0.097) & (0.302) & (0.097) \\ 
  Age0019 &  &  & 0.082^{***} & 0.134^{***} & 0.058 & -0.0001 \\ 
  &  &  & (0.023) & (0.025) & (0.156) & (0.032) \\ 
  Age2029 &  &  & 0.108^{***} & 0.139^{***} & 0.284^{*} & 0.039 \\ 
  &  &  & (0.020) & (0.023) & (0.167) & (0.028) \\ 
  Age4564 &  &  & -0.053^{***} & -0.046^{***} & 0.510^{***} & -0.060^{***} \\ 
  &  &  & (0.016) & (0.017) & (0.134) & (0.021) \\ 
  Age65 &  &  & -0.131^{***} & -0.131^{***} & 0.157 & -0.124^{***} \\ 
  &  &  & (0.016) & (0.018) & (0.117) & (0.023) \\ 
  Educ1 &  &  & -0.012 & -0.039^{**} & -0.093 & 0.027 \\ 
  &  &  & (0.014) & (0.017) & (0.098) & (0.022) \\ 
  Educ2 &  &  & -0.211^{***} & -0.294^{***} & 0.272^{**} & -0.223^{***} \\ 
  &  &  & (0.017) & (0.020) & (0.126) & (0.025) \\ 
  Educ3 &  &  & -0.462^{***} & -0.501^{***} & -0.316^{***} & -0.426^{***} \\ 
  &  &  & (0.012) & (0.014) & (0.078) & (0.016) \\ 
  Agr &  &  & -0.119^{***} & -0.139^{***} & 0.168 & -0.152^{***} \\ 
  &  &  & (0.011) & (0.012) & (0.273) & (0.019) \\ 
  Art &  &  & -0.059^{***} & -0.094^{***} & 0.663^{***} & -0.089^{***} \\ 
  &  &  & (0.011) & (0.013) & (0.116) & (0.017) \\ 
  Cad &  &  & -0.047^{***} & -0.047^{***} & -0.014 & -0.028^{*} \\ 
  &  &  & (0.011) & (0.013) & (0.093) & (0.014) \\ 
  Emp &  &  & -0.010 & -0.015 & -0.122 & -0.026^{**} \\ 
  &  &  & (0.009) & (0.010) & (0.082) & (0.013) \\ 
  Ouv &  &  & -0.022^{***} & -0.026^{***} & 0.055 & -0.015 \\ 
  &  &  & (0.008) & (0.009) & (0.073) & (0.011) \\ 
  Etu &  &  & -0.015 & 0.029 & -0.138^{*} & -0.077^{**} \\ 
  &  &  & (0.022) & (0.027) & (0.082) & (0.030) \\ 
  Retr &  &  & -0.206^{***} & -0.174^{***} & -0.953^{***} & -0.317^{***} \\ 
  &  &  & (0.021) & (0.023) & (0.158) & (0.030) \\ 
  Gau &  &  & -2.238^{***} & -2.452^{***} & -2.032^{***} & -3.128^{***} \\ 
  &  &  & (0.092) & (0.112) & (0.362) & (0.128) \\ 
  Part &  &  & -0.084^{***} & -0.099^{***} & -0.039 & -0.135^{***} \\ 
  &  &  & (0.013) & (0.015) & (0.053) & (0.019) \\ 
  Immig0914 &  &  & -0.005^{***} & -0.004^{***} & -0.026^{***} & -0.008^{***} \\ 
  &  &  & (0.001) & (0.001) & (0.006) & (0.001) \\ 
  Age20290914 &  &  & -0.003^{***} & -0.003^{***} & -0.007 & -0.003^{**} \\ 
  &  &  & (0.001) & (0.001) & (0.013) & (0.001) \\ 
  Age30440914 &  &  & -0.005^{**} & -0.003 & 0.050 & -0.007^{*} \\ 
  &  &  & (0.002) & (0.003) & (0.037) & (0.003) \\ 
  Age45640914 &  &  & 0.001 & 0.002 & -0.034 & -0.001 \\ 
  &  &  & (0.002) & (0.003) & (0.032) & (0.004) \\ 
  Age650914 &  &  & 0.006^{***} & 0.007^{***} & 0.020 & 0.001 \\ 
  &  &  & (0.001) & (0.001) & (0.013) & (0.001) \\ 
  Educ00914 &  &  & -0.008 & -0.013^{**} & 0.008 & -0.019^{**} \\ 
  &  &  & (0.006) & (0.006) & (0.034) & (0.007) \\ 
  Educ10914 &  &  & 0.023^{***} & 0.015 & 0.100^{*} & 0.003 \\ 
  &  &  & (0.009) & (0.010) & (0.055) & (0.014) \\ 
  Educ20914 &  &  & 0.011^{***} & 0.012^{***} & -0.006 & 0.0003 \\ 
  &  &  & (0.004) & (0.004) & (0.026) & (0.006) \\ 
  Educ30914 &  &  & 0.019^{***} & 0.016^{***} & 0.008 & 0.003 \\ 
  &  &  & (0.004) & (0.004) & (0.030) & (0.006) \\ 
  Agr0914 &  &  & 0.001^{***} & 0.003^{***} & 0.001 & 0.001^{*} \\ 
  &  &  & (0.0005) & (0.001) & (0.001) & (0.001) \\ 
  Art0914 &  &  & 0.001 & 0.002^{***} & -0.019^{***} & 0.001^{**} \\ 
  &  &  & (0.0005) & (0.001) & (0.007) & (0.001) \\ 
  Cad0914 &  &  & -0.001 & -0.0001 & -0.001 & -0.002^{**} \\ 
  &  &  & (0.001) & (0.001) & (0.012) & (0.001) \\ 
  PI0914 &  &  & -0.002^{***} & -0.002^{***} & 0.035 & -0.003^{**} \\ 
  &  &  & (0.001) & (0.001) & (0.027) & (0.001) \\ 
  Emp0914 &  &  & -0.002^{**} & -0.003^{**} & 0.078^{***} & 0.001 \\ 
  &  &  & (0.001) & (0.001) & (0.030) & (0.002) \\ 
  Ouv0914 &  &  & -0.001 & -0.001 & 0.011 & -0.0001 \\ 
  &  &  & (0.001) & (0.001) & (0.018) & (0.001) \\ 
  Etu0914 &  &  & -0.00001^{*} & -0.0003^{**} & -0.00000^{*} & -0.00000 \\ 
  &  &  & (0.00000) & (0.0002) & (0.00000) & (0.00000) \\ 
  Ret0914 &  &  & 0.0003 & -0.001 & 0.027^{*} & 0.004^{*} \\ 
  &  &  & (0.002) & (0.002) & (0.015) & (0.002) \\ 
  Constant & 7.327^{***} & 4.607^{***} & -80.080^{***} & -73.964^{***} & -68.736^{**} & -21.400^{**} \\ 
  & (0.264) & (0.335) & (6.413) & (7.477) & (32.468) & (9.613) \\ 
 \hline \\[-1.8ex] 
Observations & \multicolumn{1}{c}{34,901} & \multicolumn{1}{c}{34,901} & \multicolumn{1}{c}{17,398} & \multicolumn{1}{c}{12,484} & \multicolumn{1}{c}{880} & \multicolumn{1}{c}{8,144} \\ 
R$^{2}$ & \multicolumn{1}{c}{0.189} & \multicolumn{1}{c}{0.193} & \multicolumn{1}{c}{0.558} & \multicolumn{1}{c}{0.509} & \multicolumn{1}{c}{0.805} & \multicolumn{1}{c}{0.596} \\ 
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.189} & \multicolumn{1}{c}{0.193} & \multicolumn{1}{c}{0.557} & \multicolumn{1}{c}{0.508} & \multicolumn{1}{c}{0.795} & \multicolumn{1}{c}{0.593} \\ 
Residual Std. Error & \multicolumn{1}{c}{8.201 (df = 34898)} & \multicolumn{1}{c}{8.181 (df = 34897)} & \multicolumn{1}{c}{5.340 (df = 17354)} & \multicolumn{1}{c}{5.528 (df = 12441)} & \multicolumn{1}{c}{3.866 (df = 836)} & \multicolumn{1}{c}{4.982 (df = 8100)} \\ 
F Statistic & \multicolumn{1}{c}{4,077.335$^{***}$ (df = 2; 34898)} & \multicolumn{1}{c}{2,789.135$^{***}$ (df = 3; 34897)} & \multicolumn{1}{c}{509.447$^{***}$ (df = 43; 17354)} & \multicolumn{1}{c}{307.666$^{***}$ (df = 42; 12441)} & \multicolumn{1}{c}{80.379$^{***}$ (df = 43; 836)} & \multicolumn{1}{c}{277.453$^{***}$ (df = 43; 8100)} \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

\end{document}

The Code from R:

Data <- read.csv("C:/Users/Julien/Desktop/Data.csv", header=TRUE, sep=",", na.strings=c("#N/A", "#DIV/0!", "#VALUE!", "#NUM!"))
Data$ImmigRef1 <- Data$Immig*Data$Ref

library("sandwich")
library("AER")
library("lmtest")
library(stargazer)

Reg0 <- lm(FN ~ Immig + Ref, data=Data)
Reg1 <- lm(FN ~ Immig + Ref + ImmigRef1, data=Data)
Reg2 <- lm(FN ~ Immig + Ref + ImmigRef1 + CAO + Rur + LnInv + LnMed + 
       Cho + Cri + LnPop17 + Age0019 + Age2029 + Age4564 + Age65 + 
       Educ1 + Educ2 + Educ3 + Agr + Art + Cad + Emp + Ouv + Etu + 
       Retr + Gau + Part, data = Data)

Reg2 <- lm(FN ~ Immig + Ref + ImmigRef1 + CAO + Rur + LnInv + LnMed + 
           Cho + Cri + LnPop17 + Age0019 + Age2029 + Age4564 + Age65 +
           Educ1 + Educ2 + Educ3 + Agr + Art + Cad + Emp + Ouv + Etu +
           Retr + Gau + Part + Immig0914 + Age20290914 + Age30440914 +
           Age45640914 + Age650914 + Educ00914 + Educ10914 + Educ20914 +     
           Educ30914 + Agr0914 + Art0914 + Cad0914 + PI0914 + Emp0914 +
           Ouv0914 + Etu0914 + Ret0914, data=Data)

Reg3 <- lm(FN ~ Immig + Ref + ImmigRef1 + CAO + Rur + LnInv + LnMed + 
           Cho + Cri + LnPop17 + Age0019 + Age2029 + Age4564 + Age65 +
           Educ1 + Educ2 + Educ3 + Agr + Art + Cad + Emp + Ouv + Etu +         
           Retr + Gau + Part + Immig0914 + Age20290914 +Age30440914 + 
           Age45640914 + Age650914 + Educ00914 + Educ10914 + Educ20914 + 
           Educ30914 + Agr0914 + Art0914 + Cad0914 + PI0914 + Emp0914 + 
           Ouv0914 + Etu0914 + Ret0914, Rur == 1,  data = Data)

Reg4 <- lm(FN ~ Immig + Ref + ImmigRef1 + CAO + Rur + LnInv + LnMed + 
           Cho + Cri + LnPop17 + Age0019 + Age2029 + Age4564 + Age65 + 
           Educ1 + Educ2 + Educ3 + Agr + Art + Cad + Emp + Ouv + Etu + 
           Retr + Gau + Part + Immig0914 + Age20290914 +Age30440914 + 
           Age45640914 + Age650914 + Educ00914 + Educ10914 + Educ20914 + 
           Educ30914 + Agr0914 + Art0914 + Cad0914 + PI0914 + Emp0914 + 
           Ouv0914 + Etu0914 + Ret0914, LnPop17 > 9.07, data = Data)

Reg5 <- lm(FN ~ Immig + Ref + ImmigRef1 + CAO + Rur + LnInv + LnMed + 
           Cho + Cri + LnPop17 + Age0019 + Age2029 + Age4564 + Age65 + 
           Educ1 + Educ2 + Educ3 + Agr + Art + Cad + Emp + Ouv + Etu + 
           Retr + Gau + Part + Immig0914 + Age20290914 +Age30440914 + 
           Age45640914 + Age650914 + Educ00914 + Educ10914 + Educ20914 + 
           Educ30914 + Agr0914 + Art0914 + Cad0914 + PI0914 + Emp0914 + 
           Ouv0914 + Etu0914 + Ret0914, LnMed > 9.910, data = Data)

    OLSes <- stargazer(Reg0, Reg1, Reg2, Reg3, Reg4, Reg5, 
                   font.size = "small", 
                   align = TRUE, 
                   no.space = TRUE)

And I will attach the csv file.

1

The problem lies in printing "Residual Std. Error" and "F Statistic" lines (that you don't see on your pdf output...): very big "numbers" (like 2,789.135 ∗∗∗ (df = 3; 34897)) If you delete them with omit.stat=c("f", "ser"), you can output the results (it is documented in the examples of the stargazer function). There is also an option column.sep.width that you may use (see the doc)

stargazer(Reg0, Reg1, Reg2, Reg3, Reg4, Reg5,
          font.size = "small",
          align = TRUE,
          omit.stat=c("f", "ser"),
          column.sep.width = "-15pt" # Well... you can tweak this
)

For the length you can also use this recent Q/A: Help with long table from Stargazer

And, a minimal example would be something like: test.Rnw

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{dcolumn}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<results=tex>>=
library(stargazer)
data(mtcars)

Reg0 <- lm(mpg ~ cyl + disp, data = mtcars)

stargazer( Reg0, Reg0, Reg0, Reg0, Reg0, Reg0,
           font.size = "small",
           align = TRUE,
           omit.stat = c("f", "ser"),
           column.sep.width = "-15pt")
@

\end{document}

Output:

enter image description here

  • Thank you so much... I read about column.sep.width, just didn't know I could use negative number (I believe I tried 0 but it didn't work. Such a shame... – Julien Baldini May 16 '18 at 19:18
  • You're welcome! Upvoting is the preferred way here to say "thank you" to users who helped you. If you like an answer and it was helpful, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). See 2 – nebi May 17 '18 at 7:12

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.