我已经四处寻找了一段时间,试图找到问题的答案。我在 R 中做了一些回归分析,并想使用 stargazer 包将它们导出到 LaTeX 中。
然而,由于回归次数(6),该列确实被遗忘了。我曾尝试减少列间距,但没有成功。
如何才能使表格适合页面宽度(我将删除一些变量,因为 longtable 与 stargazer 不兼容。非常感谢您的时间和帮助。下面是从 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}
来自 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)
我将附加 csv 文件。
答案1
问题在于打印“残差标准误差”和“F 统计量”行(您在 pdf 输出中看不到这些行...):非常大的“数字”(如2,789.135 ∗∗∗ (df = 3; 34897)
)如果您使用删除它们omit.stat=c("f", "ser")
,则可以输出结果(它记录在函数的示例中stargazer
)。还有一个选项column.sep.width
,您可以使用(查看文档)
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
)
对于长度,您还可以使用这个最近的问答:Stargazer 帮忙摆放长桌
并且,一个最小的例子是这样的: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}
输出: