8

I run a regression of the type

model <- lm(y~x1+x2+x3, weights = wei, data=data1)

and then create my table

,t <- stargazer(model, omit="x2", omit.labels="x1")

but I haven't found a way to omit the intercept results from the table. I need it in the regression, yet I don't want to show it in the table.

Is there a way to do it through stargazer?

Thomas
  • 43,637
  • 12
  • 109
  • 140
Felipe Alvarenga
  • 2,572
  • 1
  • 17
  • 36

2 Answers2

14

I haven't your dataset, but typing omit = c("Constant", "x2") should work.

As a reproducible example (stargazer 5.2)

stargazer::stargazer(
  lm(Fertility ~ . , 
     data = swiss), 
  type = "text", 
  omit = c("Constant", "Agriculture"))

Edit: Add in omit.labels


mdls <- list(
  m1 = lm(Days ~ -1 + Reaction, data = lme4::sleepstudy),
  m2 = lm(Days ~ Reaction, data = lme4::sleepstudy),
  m3 = lm(Days ~ Reaction + Subject, data = lme4::sleepstudy)
)

stargazer::stargazer(
  mdls, type = "text", column.labels = c("Omit none", "Omit int.", "Omit int/subj"),
  omit = c("Constant", "Subject"),
  omit.labels = c("Intercept", "Subj."),
  keep.stat = "n")
#> 
#> ==============================================
#>                     Dependent variable:       
#>              ---------------------------------
#>                            Days               
#>              Omit none Omit int. Omit int/subj
#>                 (1)       (2)         (3)     
#> ----------------------------------------------
#> Reaction     0.015***  0.027***    0.049***   
#>               (0.001)   (0.003)     (0.004)   
#>                                               
#> ----------------------------------------------
#> Intercept       No        No          No      
#> Subj.           No        No          No      
#> ----------------------------------------------
#> Observations    180       180         180     
#> ==============================================
#> Note:              *p<0.1; **p<0.05; ***p<0.01

Created on 2020-05-08 by the reprex package (v0.3.0)

Note the table should read. This appears to be a bug (stargazer 5.2.2).

#> Intercept       No        Yes       Yes    
#> Subj.           No        No        Yes  
JWilliman
  • 3,558
  • 32
  • 36
  • This works if you don't want to use `omit` for its other purpose of e.g. collapsing and naming fixed effects. For example, it fails if you also pass `omit.labels=c("ag")`. – Max Ghenis May 05 '20 at 15:32
  • @MaxGhenis `omit` and `omit.labels` must be the same length, so `omit.labels = c("Intercept", "ag")` will work. – JWilliman May 06 '20 at 23:48
  • But then it'll show the intercept. `c(NULL, "ag")` throws an error. I don't think there's a way to use this to hide the intercept while showing fixed effects. – Max Ghenis May 07 '20 at 16:53
  • @MaxGhenis The purpose of `omit.labels` is to indicate "whether variables have been omitted from a given model", in my mind this includes the intercept. Unfortunately there appears to be a bug in `stargazer` at the moment (as you have noticed!). See https://stackoverflow.com/q/38355337/4241780. – JWilliman May 07 '20 at 22:49
3

I got a way of doing it. It is not the most clever way, but works.

I just change the omit command to a keep command. In my example above:

library(stargazer) 

model <- lm(y~x1+x2+x3, weights = wei, data=data1)
t <- stargazer(model, keep=c("x1","x3"), omit.labels="x1")

However, it's not an efficient way when you have many variables you want to keep in the regression table

Felipe Alvarenga
  • 2,572
  • 1
  • 17
  • 36