How can I omit the regression intercept from my results table in stargazer
Asked Answered
A

2

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?

Arabesque answered 7/4, 2016 at 21:19 Comment(0)
M
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  
Malign answered 25/1, 2017 at 0:28 Comment(4)
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").Sussex
@MaxGhenis omit and omit.labels must be the same length, so omit.labels = c("Intercept", "ag") will work.Malign
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.Sussex
@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://mcmap.net/q/1098226/-potential-bug-in-stargazer-omit-labels/4241780.Malign
A
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

Arabesque answered 15/6, 2016 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.