我想将控制组平均值添加到Stargazer
中的回归表中。我目前的想法是用对照组平均值替换截距并重命名该术语。我知道如何替换拦截的值,但有没有办法重命名拦截术语?用对照组的意思取代常数术语通常可以提供信息。
library(stargazer)
attitude$treatment <- rbinom(n = 30, size = 1, prob = .5)
lm_model <- lm(rating ~ treatment + complaints + privileges + learning
+ raises + critical, data=attitude)
#add in control mean
control_mean <- mean(attitude[attitude$treatment == 0, "rating"])
lm_model[["coefficients"]][names(lm_model[["coefficients"]]) ==
"(Intercept)"] <- control_mean
stargazer(lm_model)
答案 0 :(得分:1)
# Rename intercept
names(lm_model$coefficients)[1]
# Change value of intercept to control_mean
lm_model$coefficients[1] = control_mean
这不是一个stargazer
问题,但只是如何修改模型对象。