我在R中使用stargazer
包进行回归输出。我有一个自定义的估算程序,它不会产生模型对象,只会产生系数和标准误差的向量。有没有办法可以将这些提供给stargazer
并获得格式良好的输出表?
示例:
dep.var <- "foo"
regressors <- c("bar", "baz", "xyz")
vec.coeffs <- c(1.2, 2.3, 3.4)
vec.se <- c(0.1, 0.1, 0.3)
输出应该类似于:
===============================================
Dependent variable:
---------------------------
foo
-----------------------------------------------
bar 1.200***
(0.100)
baz 2.300***
(0.100)
xyz 3.400***
(0.300)
-----------------------------------------------
答案 0 :(得分:4)
以下是一个建议:主要想法是创建一个假的lm
对象,然后将自定义系数,SE等应用于stargazer
输出:
d <- as.data.frame(matrix(rnorm(10 * 4), nc = 4))
names(d) <- c(dep.var, regressors)
f <- as.formula(paste(dep.var, "~ 0 +", paste(regressors, collapse = "+")))
p <- lm(f, d)
stargazer(p, type = "text",
coef = list(vec.coeffs),
se = list(vec.se),
t = list(vec.coeffs / vec.se),
omit.stat = "all")
# =================================
# Dependent variable:
# ---------------------------
# foo
# ---------------------------------
# bar 1.200***
# (0.100)
# baz 2.300***
# (0.100)
# xyz 3.400***
# (0.300)
# =================================
# =================================
# Note: *p<0.1; **p<0.05; ***p<0.01