我有一个数据集形式的回归输出。我如何在stargazer
中手动输入估计值和标准误差?这样,stargazer
创建了它的典型回归表?
term estimate std.error statistic p.value
1 rho 0.56782511824 0.016618530837 34.168190 0.000000e+00
2 (Intercept) -4.10698330735 0.537699847356 -7.638059 2.198242e-14
4 Unemployment_Rate 0.02288489900 0.016412419393 1.394365 1.632075e-01
5 pop_sq_mi 0.00020135202 0.000045361286 4.438852 9.044016e-06
6 prcntHS 0.13303000437 0.006002571434 22.162169 0.000000e+00
7 prcntBA 0.03698563228 0.012723399878 2.906899 3.650316e-03
8 prcntBlack 0.00877367484 0.004458885465 1.967683 4.910448e-02
9 prcntMulti 0.01404154066 0.004182210799 3.357445 7.866653e-04
10 prcntHisp 0.04316697336 0.003523552546 12.250980 0.000000e+00
11 prcntForeignBorn 0.02229836451 0.009707563865 2.297009 2.161824e-02
12 medianIncome -0.00002809549 0.000002933667 -9.576917 0.000000e+00
13 per_gop_2016 -0.02366390363 0.002698813668 -8.768261 0.000000e+00
我试着用下面的方法(作为一个例子),但运气不好。
X1 <- sample(seq(1,100,1), 100,replace= T)
X2 <- sample(seq(1,100,1), 100,replace= T)
Y <- sample(seq(1,100,1), 100,replace= T)
df <- data.frame(Y, X1, X2)
Results <- lm(Y ~ X1 + X2, data = df)
library(broom)
Results_DF <- data.frame(tidy(Results))
stargazer(type = "text",
coef = list(Results_DF$estimate, Results_DF$estimate),
se = list(Results_DF$std.error, Results_DF$std.error),
omit.table.layout = "s")
Error in if (substr(inside[i], 1, nchar("list(")) == "list(") { :
missing value where TRUE/FALSE needed
如有任何建议,我将不胜感激。谢谢你!你就快成功了。
这里有一个可重复的例子。应该可以修改它,使其与您的数据一起工作。注意t和p值。检查p.auto
选项在占星器。当然,您需要手动更改或删除包含观察值,F-stat等的回归页脚。
library(stargazer)
# coefficients data
d_lm <- data.frame(var = letters[1:4],
est = runif(4),
sd = runif(4),
t = runif(4),
p = runif(4))
# fake data
d <- data.frame(y = runif(30),
a = runif(30),
b = runif(30),
c = runif(30),
d = runif(30))
# fake regression
lm <- lm(y ~ a + b + c + d -1, d)
stargazer(lm,
coef = list(d_lm$est),
se = list(d_lm$sd),
t = list(d_lm$t), # if not supplied stargazer will calculate t values for you
p = list(d_lm$p), # if not supplied stargazer will calculate p values for you
type = "text")