2

I would like to output the interaction terms from several regressions in the same row and call it "Interaction". So far what I have is that the interaction terms show up in two different rows called "Interaction" (see code below).

This question has already been asked here, but my score isn't high enough yet to upvote it or comment on it: https://stackoverflow.com/questions/28859569/several-coefficients-in-one-line.

library("stargazer")
stargazer(attitude)
stargazer(attitude, summary=FALSE)
# 2 OLS models with Interactions
linear.1 <- lm(rating ~ complaints + privileges + complaints*privileges
           , data=attitude)
linear.2 <- lm(rating ~ complaints + learning + complaints*learning, data=attitude)
stargazer(linear.1, linear.2, title="Regression Results", type="text", 
      covariate.labels=c("Complaints", "Privileges", "Interaction", "Learning", "Interaction"))

Thank you for your help.

Community
  • 1
  • 1
Seb
  • 370
  • 2
  • 14

2 Answers2

5

I think this is not natively supported because it is not a good idea. You're asking to obfuscate the meaning of the numbers in your table, which won't help your reader.

That caveat now stated, you can do this by modifying the contents of the lm objects:

# copy objects just for demonstration
m1 <- linear.1
m2 <- linear.2

# see names of coefficients
names(m1$coefficients)
# [1] "(Intercept)"           "complaints"            "privileges"            "complaints:privileges"
names(m2$coefficients)
# [1] "(Intercept)"         "complaints"          "learning"            "complaints:learning"

# replace names
names(m1$coefficients)[names(m1$coefficients) == "complaints:privileges"] <- "interaction"
names(m2$coefficients)[names(m2$coefficients) == "complaints:learning"] <- "interaction"

The result:

> stargazer(m1, m2, title="Regression Results", type="text")

Regression Results
==========================================================
                                  Dependent variable:     
                              ----------------------------
                                         rating           
                                   (1)            (2)     
----------------------------------------------------------
complaints                       1.114**         0.307    
                                 (0.401)        (0.503)   

privileges                        0.434                   
                                 (0.570)                  

learning                                        -0.171    
                                                (0.570)   

interaction                       -0.007         0.006    
                                 (0.008)        (0.009)   

Constant                          -7.737        31.203    
                                 (27.409)      (31.734)   

----------------------------------------------------------
Observations                        30            30      
R2                                0.692          0.713    
Adjusted R2                       0.657          0.680    
Residual Std. Error (df = 26)     7.134          6.884    
F Statistic (df = 3; 26)        19.478***      21.559***  
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01
Thomas
  • 43,637
  • 12
  • 109
  • 140
  • Thank you, that was exactly what I needed. The reason why in my case this is not misleading, is because in my regressions I have different sets of 2 regressors and their interaction (i.e. (x1, x2, x1*x2) and (x2, x3, x2*x3)). Sorry for choosing a poor example with 3 regressors and 1 interaction here. – Seb Apr 10 '15 at 15:21
0

In case anyone is wondering, I needed this for a different purpose for the felm package. The following code is required for that:

reg ~ felm(....)
rownames(reg$coefficients)[rownames(reg$coefficients)=='oldname']<-'newname'
rownames(reg$beta)[rownames(reg$beta)=='oldname']<-'newname'
winitheju
  • 65
  • 1
  • 7