Rename constant term using stargazer

750 views Asked by At

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)
1

There are 1 answers

1
eipi10 On BEST ANSWER
# 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.