2

Does anyone know what could be the opposite of stargazer's argument "omit" when making a regression table output?

I'm trying to show just one (or a few) covariates from a regression. I know one could use "omit" and then list all the variable's names which one doesn't want to be shown in the output, but is there any way to call variable's names one actually wants to maintain in the final table?

I'm having a hard time dealing with interactions between dummy variables directly called within a linear model. For example, let's say I want to run the following model:

# Libraries
library(stargazer)

# Data:
data <- data.frame(
  "Y" = rnorm(100,20,45),
  "Dummy1" = sample(c(1,0),100, replace = T),
  "Dummy2" = sample(c(1,0),100, replace = T),
  "Dummy3" =sample(c(1,0),100, replace = T))

# Model:
model1 <- lm(Y ~ Dummy1*Dummy2*Dummy3, data)

And let's say I want to report in the output stargazer table only the triple interaction. But when I try, for example, to remove the results of the simple variable "Dummy1", stargazer drops all the variables that begin with "Dummy1" therefore also removing the triple interaction.

# Problem
stargazer(model1, type = "text", omit = "Dummy1")


===============================================
                        Dependent variable:    
                    ---------------------------
                                 Y             
-----------------------------------------------
Dummy2                        23.705           
                             (17.236)          
                                               
Dummy3                        19.221           
                             (17.591)          
                                               
Dummy2:Dummy3                 -25.568          
                             (23.908)          
                                               
Constant                       5.373           
                             (12.188)          
                                               
-----------------------------------------------
Observations                    100            
R2                             0.099           
Adjusted R2                    0.031           
Residual Std. Error      43.943 (df = 92)      
F Statistic             1.450 (df = 7; 92)     
===============================================
Note:               *p<0.1; **p<0.05; ***p<0.01

How do I make a table with just the triple interaction's result ? Any guess?

  • Asking to only display "only the triple interaction" is statistically meaningless. You can only make sense of the meaning of an interaction by presenting the lower order components that involve the same variables. – IRTFM Apr 25 '21 at 03:42
  • Sure, but still, the question is not about the statistical validity of showing results in this way, Its more about using stargazer to show just a selected covariate result, instead of selecting which covariates results which you do not want to show. Any guess? – Guibor Camargo Salamanca Apr 25 '21 at 03:46
  • The help page says you can use a regex pattern as your argument to omit.. Have you tried that? – IRTFM Apr 25 '21 at 04:01
  • Yes, so there is a way to for example delete specific variables when others could be starting with the same name or letters. Instead of using: ( omit = "name") you should use (omit = "/^name$/"). However, this is not optimal in all cases, since you will still have to specify in "omit" all the other variables which you do not want to report in the output table, instead of just selecting the ones you want to report. – Guibor Camargo Salamanca Apr 25 '21 at 04:08
  • I'm guessing from your response that you are not a seasoned regex user. – IRTFM Apr 25 '21 at 04:12
  • Sure, that is the reason why I'm asking. – Guibor Camargo Salamanca Apr 25 '21 at 04:14

2 Answers2

6

Instead of using omit, you can use keep to keep only the variables that you need.

stargazer::stargazer(model1, type = "text", keep = 'Dummy1:Dummy2:Dummy3')

================================================
                         Dependent variable:    
                     ---------------------------
                                  Y             
------------------------------------------------
Dummy1:Dummy2:Dummy3           42.430           
                              (35.315)          
                                                
------------------------------------------------
Observations                     100            
R2                              0.145           
Adjusted R2                     0.080           
Residual Std. Error       43.587 (df = 92)      
F Statistic             2.222** (df = 7; 92)    
================================================
Note:                *p<0.1; **p<0.05; ***p<0.01
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
0

The main effects and constant terms can be matched with

stargazer(model1, type = "text",omit="^.{6,8}$")  # terms with length 6 to 8 characters

Or:

stargazer(model1, type = "text",keep="^[^:]+$") #not any :

The two variable effects can be matched with:

stargazer(model1, type = "text",omit="^[^:]{6}[:][^:]{6}$") # not-:*6,then :, then not-:*6

So the combination can be matched with:

stargazer(model1, type = "text",omit="^.{6,8}$|^[^:]{6}[:][^:]{6}$")

The more general version to Ronak Shah's approach of using keep parameter patterns would be:

stargazer(model1, type = "text",keep="[:].+[:]") #keeps any with 2 (or more) interaction variables
IRTFM
  • 258,963
  • 21
  • 364
  • 487