我正在尝试使用 R 中的 Stargazer 包创建一个回归表。我有几个回归,它们仅在虚拟变量中有所不同。我希望它报告自变量、常数等的系数,并在回归中包含某些固定效应(即虚拟变量)时说“是”或“否”。这些是我的回归:
m1 <- lm(data=merge1,log(total_units)~log(priceIndex))
m2 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code))
m3 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month))
m4 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+factor(year))
m5 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+time*factor(fips_state_code))
m6 <- lm(data=merge1,log(total_units)~log(priceIndex)+factor(fips_state_code)+factor(month)+factor(year)+time*factor(fips_state_code))
我已经尝试了 stargazer 命令的几种变体来让表格看起来正确,但它从来没有。当我运行这个命令时,对于五个或六个回归中的每一个,它都会按我的预期工作:
stargazer(m2,type="text",
omit = c("fips_state_code","month","year","time"),
omit.labels = c("State FE?","Month of year FE?","Year FE?","State time trend?"))
即,对于 m2,它在“State FE?”旁边显示“Yes”。和所有其他问题旁边的“否”。对于 m3,它在“状态 FE?”旁边显示“是”。和“FE 年月?” 和其他问题旁边的“否”。
但是当我运行这个命令时,该表对所有回归的所有问题都报告“否”:
stargazer(m1,m2,m3,m4,m5,m6,type="text",
omit = c("fips_state_code","month","year","time"),
omit.labels = c("State FE?","Month of year FE?","Year FE?","Time FE?"))
有人知道发生了什么吗?无论我是单独还是一起进行每个回归,它都应该是一样的,不是吗?
我也得到了其他奇怪的结果......当我运行以下命令时:
stargazer(m3,m4,m5,m6,type="html",
omit = c("fips_state_code","month","year","time"),
omit.labels = c("State FE?","Month of year FE?","Year FE?","State time trend?"))
我明白了:
<table style="text-align:center"><tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td colspan="4"><em>Dependent variable:</em></td></tr>
<tr><td></td><td colspan="4" style="border-bottom: 1px solid black"></td></tr>
<tr><td style="text-align:left"></td><td colspan="4">log(total_units)</td></tr>
<tr><td style="text-align:left"></td><td>(1)</td><td>(2)</td><td>(3)</td><td>(4)</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">log(priceIndex)</td><td>2.962<sup>***</sup></td><td>-0.746<sup>***</sup></td><td>0.142</td><td>-1.947<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.206)</td><td>(0.249)</td><td>(0.224)</td><td>(0.276)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td></tr>
<tr><td style="text-align:left">Constant</td><td>-0.094</td><td>11.248<sup>***</sup></td><td>8.570<sup>***</sup></td><td>15.030<sup>***</sup></td></tr>
<tr><td style="text-align:left"></td><td>(0.652)</td><td>(0.779)</td><td>(0.709)</td><td>(0.868)</td></tr>
<tr><td style="text-align:left"></td><td></td><td></td><td></td><td></td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">State FE?</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
<tr><td style="text-align:left">Month of year FE?</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
<tr><td style="text-align:left">Year FE?</td><td>No</td><td>No</td><td>No</td><td>No</td></tr>
<tr><td style="text-align:left">State time trend?</td><td>No</td><td>No</td><td>No</td><td>No</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Observations</td><td>2,853</td><td>2,853</td><td>2,853</td><td>2,853</td></tr>
<tr><td style="text-align:left">R<sup>2</sup></td><td>0.968</td><td>0.974</td><td>0.984</td><td>0.985</td></tr>
<tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.967</td><td>0.974</td><td>0.983</td><td>0.984</td></tr>
<tr><td style="text-align:left">Residual Std. Error</td><td>0.340 (df = 2806)</td><td>0.305 (df = 2800)</td><td>0.244 (df = 2771)</td><td>0.235 (df = 2766)</td></tr>
<tr><td style="text-align:left">F Statistic</td><td>1,830.438<sup>***</sup> (df = 46; 2806)</td><td>2,019.427<sup>***</sup> (df = 52; 2800)</td><td>2,041.885<sup>***</sup> (df = 81; 2771)</td><td>2,084.570<sup>***</sup> (df = 86; 2766)</td></tr>
<tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"><em>Note:</em></td><td colspan="4" style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
</table>