Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 306
Felipe Alvarenga Avatar asked Apr 07 '16 21:04

Felipe Alvarenga


People also ask

How do you make a stargazer table smaller?

To adjust table size with stargazer, you can change the font size font. size= , make the Stargazer single row single. row = TRUE and change the space between columns column.

How do you use the stargazer in R regression?

This can be done by typing “install. packages(“stargazer”)”, and then “library(stargazer)” in the next line. Installing Stargazer will only need to be done once, but the second command, which loads the package will need to be typed each session you wish to use it.

What does the stargazer package do?

stargazer is an R package that creates LATEX code, HTML code and ASCII text for well-formatted regression tables, with multiple models side-by-side, as well as for summary statistics tables, data frames, vectors and matrices.


2 Answers

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  
like image 119
JWilliman Avatar answered Sep 22 '22 20:09

JWilliman


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

like image 28
Felipe Alvarenga Avatar answered Sep 19 '22 20:09

Felipe Alvarenga