1

I'm trying to print the following model in R

a = subset(control, Content=="Support")
lm_control<-lm(value~Race+Income+Potential+age+gender+ethnicity+hhi+hispanic+political_party+education+population_density,data=a)
lm_control_vcov<-vcovCL(lm_control,cluster = a$ResponseId)

Using sandwich and stargazer to regression with robust clustered standard errors. My stargazer code looks like this:

stargazer(lm_control,
          se = list(sqrt(diag(lm_control_vcov))), 
          title = "Control Regression Model",
          dep.var.labels.include = FALSE,
          covariate.labels = c("Race","Community Income","Potential", "age","gender","ethnicity","hhi"," hispanic ","political party", "education","population density"),
          omit.stat = c("adj.rsq", "rsq", "ser", "f"),
          star.char = c("*", "**", "***"),
          star.cutoffs = c(0.1, 0.05, 0.01),
          omit.table.layout = "ln",
          type = "latex",
          header = FALSE)

and prints the following output:

Regression Table with Multiple Outputs

As you can see, it prints the variables "Political Party", "education" and "population density" twice. Previous posts on the topic tend to focus on tables that display multiple models or that display interactions-neither of which is happening here.

Any advice?

Thank you!

I've tried changing variable names and checked all other posts on the topic.

  • Sorry, I can't help, but maybe you can try one of the more modern regression table packages (`stargazer` has not received a meaningful update in a long time). Disclaimer: I am [the `modelsummary` developer](https://vincentarelbundock.github.io/modelsummary/) – Vincent May 10 '23 at 10:09
  • When you provide minimal data, it makes people more willing to help with your problem. Using minimal data, you would have recognized the factor problem yourself. – Marco Jul 13 '23 at 16:24

1 Answers1

0

Since the variable at the bottom seem to be exactly match your variable names, I assume there are some of them coded as factor. It's not the package that creates more variables, you have some levels that you didn't label.

data(mtcars)

model1 <- lm(mpg ~ drat + cyl + vs, data = mtcars)

library(sandwich)
mtcars$names <- rownames(mtcars)
model_vcov <- vcovCL(model, cluster = mtcars$names)

library(stargazer)
stargazer(model1,
          se = list(sqrt(diag(model_vcov))), 
          title = "Regression Model",
          dep.var.labels.include = FALSE,
          covariate.labels = c("DRAT", "CYL", "VS"),
          omit.stat = c("adj.rsq", "rsq", "ser", "f"),
          type = "text")

Regression Model
========================================
                 Dependent variable:    
             ---------------------------
----------------------------------------
DRAT                    1.820           
                       (1.173)          
                                        
CYL                    -2.545           
                                        
                                        
VS                     -0.222           
                       (1.131)          
                                        
Constant              29.392***         
                       (5.380)          
                                        
----------------------------------------
Observations             32             
========================================
Note:        *p<0.1; **p<0.05; ***p<0.01

Whereas

model2 <- lm(mpg ~ drat + factor(cyl) + vs, data = mtcars)

stargazer(model2,
          se = list(sqrt(diag(model_vcov))), 
          title = "Regression Model",
          dep.var.labels.include = FALSE,
          covariate.labels = c("DRAT", "CYL", "VS"),
          omit.stat = c("adj.rsq", "rsq", "ser", "f"),
          type = "text")

Regression Model
========================================
                 Dependent variable:    
             ---------------------------
----------------------------------------
DRAT                    1.795           
                       (1.173)          
                                        
CYL                   -6.047***         
                       (1.653)          
                                        
VS                   -10.044***         
                       (1.903)          
                                        
vs                      0.010           
                       (1.131)          
                                        
Constant              19.348***         
                       (5.380)          
                                        
----------------------------------------
Observations             32             
========================================
Note:        *p<0.1; **p<0.05; ***p<0.01
Marco
  • 2,368
  • 6
  • 22
  • 48