I know how I can create a linear regression model lm
and how to use the summary
function to obtain clustered standard errors and add them to the stargazer
output:
# estimate models
ols1 <- lm(y ~ x)
# summary with cluster-robust SEs
summary(ols1, cluster="cluster_id")
# create table in stargazer
stargazer(ols1, se=list(coef(summary(ols1,cluster = c("cluster_id")))[, 2]), type = "text")
Does anyone know how the code supposed to look like if I want to create one stargazer output with multiple regression models and clustered standard errors?
The logic of the code is as follows:
1 step: create lm models
ols1 <- lm(y ~ x)
ols2 <- lm(y ~ x + z)
ols3 <- lm(y ~ x + z + a)
ols2 <- lm(y ~ x + z + a + b)
2 step: include standard errors
summary(ols1, cluster="cluster_id")
summary(ols2, cluster="cluster_id")
summary(ols3, cluster="cluster_id")
summary(ols4, cluster="cluster_id")
3 step: create one output with 4 different models
stargazer(ols1,ols2,ols3,ols4, type="html", dep.var.labels=c("ROA"), intercept.bottom = FALSE,
out="OLS1")
I think step 1 and step 2 are not critical but I do not know how to set up the code for step 3.
I do not know how to implement the following code in step 3:
# create table in stargazer
stargazer(ols1, se=list(coef(summary(ols1,cluster = c("cluster_id")))[, 2]), type = "text")
Can anyone help?
Thank you so much!!!