1

I recently received a question about the answer here about how to change the names of variables when outputting regression results using Stargazer. The answer didn't work for the lrm function from rms. Specifically, the coefficients were output correctly but the standard errors disappeared. Here's a reproducible example:

library(rms)
library(stargazer)
stargazer(attitude)

# logit models
m1 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
m2 <- lrm(rating ~ complaints + learning + privileges,x=TRUE, y=TRUE,data=attitude)
names(m1$coefficients)[names(m1$coefficients) == "privileges"] <- "past"
names(m2$coefficients)[names(m2$coefficients) == "privileges"] <- "past"

stargazer(m1,m2, type="text")

Any idea how to make this work?

Community
  • 1
  • 1
Thomas
  • 43,637
  • 12
  • 109
  • 140

1 Answers1

0

The answer is that the lrm class object stores not just coefficients but the variance-covariance matrix, as well, so you need to do an additional step:

rownames(m1$var)[rownames(m1$var) == "privileges"] <- "past"
rownames(m2$var)[rownames(m2$var) == "privileges"] <- "past"
colnames(m1$var)[colnames(m1$var) == "privileges"] <- "past"
colnames(m2$var)[colnames(m2$var) == "privileges"] <- "past"

This changes the rownames and colnames of the variance-covariance matrix and thus produces the correct result:

stargazer(m1,m2, type="text")

==========================================
                  Dependent variable:     
              ----------------------------
                         rating           
                   (1)            (2)     
------------------------------------------

....

complaints       0.196***      0.196***   
                 (0.045)        (0.045)   

learning          0.063          0.063    
                 (0.039)        (0.039)   

past              -0.034        -0.034    
                 (0.035)        (0.035)   

------------------------------------------
Observations        30            30      
R2                0.713          0.713    
chi2 (df = 3)   37.238***      37.238***  
==========================================
Note:          *p<0.1; **p<0.05; ***p<0.01
Thomas
  • 43,637
  • 12
  • 109
  • 140