简体   繁体   中英

Rename constant term using stargazer

I'd like to add the control group mean to my regression tables in Stargazer . My current idea is to replace the intercept with the control group mean and rename that term. I know how to replace the value of the intercept, but is there a way to rename the intercept term? It's often informative to replace the constant term with the control group mean.

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)
# Rename intercept
names(lm_model$coefficients)[1]

# Change value of intercept to control_mean
lm_model$coefficients[1] = control_mean

This isn't really a stargazer question, but is just a matter of how to modify a model object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM