How to add row to Stargazer table to indicate use of fixed effects
Asked Answered
E

1

5

I just run my regression including fixed effects, in this case id_school. Next I omitted all the dummy variables from my stargazer tab, so I can save some space.

The thing is I want to include a row in my tab in order to report that I used Fixed Effect like :Fixed Effects Yes NO ...Something like the image.

Thank you. enter image description here

Eyas answered 5/6, 2020 at 21:6 Comment(2)
Use the add.lines argument to stargazer() to add a row to your table that indicates you used fixed effects.Sustentacular
Note that I edited your question to be about stargazer and not rstudio. You also asked a second question about your data being balanced, which I deleted from here, since it is unrelated. If you still have that question, ask it in a new stackoverflow post.Sustentacular
P
13

Simple option is to use Stargazer add.lines, e.g.

#load a panel data
data("Wages", package = "plm")

#plain vanilla OLS
model1 <- lm(lwage ~ exp + union + ed + black, data=Wages)
# Least-Squares Dummy Variables model
model2 <- lm(lwage ~ factor(ind) + exp + union + ed + black, data=Wages)

library(stargazer)

stargazer(model1, model2, omit = '[i][n][d]', type='text',
add.lines=list(c('Fixed effects', 'Yes','No'))
)

Returns:

=======================================================================
                                    Dependent variable:
                    ---------------------------------------------------
                                           lwage
                               (1)                       (2)
-----------------------------------------------------------------------
exp                         0.013***                  0.013***
                             (0.001)                   (0.001)

unionyes                    0.121***                  0.113***
                             (0.013)                   (0.013)

ed                          0.079***                  0.082***
                             (0.002)                   (0.002)

blackyes                    -0.269***                 -0.256***
                             (0.024)                   (0.024)

Constant                    5.374***                  5.313***
                             (0.036)                   (0.037)

-----------------------------------------------------------------------
Fixed effects                  Yes                       No
Observations                  4,165                     4,165
R2                            0.283                     0.291
Adjusted R2                   0.283                     0.290
Residual Std. Error     0.391 (df = 4160)         0.389 (df = 4159)
F Statistic         411.209*** (df = 4; 4160) 341.333*** (df = 5; 4159)
=======================================================================
Note:                                       *p<0.1; **p<0.05; ***p<0.01

If you are using Latex, another option is to use starpolishr available from github. This allows you to set the position of the line to be added.

library(stargazer)
library(tidyverse)
library(starpolishr)
stargazer(model1, model2, omit = '[i][n][d]', type='latex') %>%  
star_insert_row(insert.after=14, 'Fixed effets & Yes & No \\\\ ') %>% cat(file='foo.tex',sep='\n')

Output: this

Puisne answered 8/6, 2020 at 10:17 Comment(6)
Note that my model probably does not make any sense, so please disregard the coefficient estimates :)Grilse
Hey Otto, how do you do if you have two fixed effects? One for individual and one for time?Breault
You can easily add two lines by e.g. add.lines=list(c('Individual fixed effects', 'Yes','No'), c('Time fixed effects', 'No','Yes'))Grilse
Or alternatively just chain two star_insert_row() commandsGrilse
Sorry. My question was more on how to ignore individual and time fixed effects in the table. Somehow I'm able to ignore the time fixed effects but not individual fixed effects at the same time. If you have clue about this, I would appreciate it.Breault
Sorry, I do not understand what you are trying to do. Maybe you should try to ask a separate question?Grilse

© 2022 - 2024 — McMap. All rights reserved.