I want to use R to estimate a fixed effects model using different estimation approaches. Note that I am using an unbalanced panel . The easiest way to do this is using the function lm . Example: # load packages and create data library(dplyr) set.seed(123) x % group_by(id) %>% mutate(firm = 1:n()) %>% pull(firm) id.eff % group_by(id) %>% summarise(firm = max(firm)) %>% filter(firm == 1) %>% pull(id) db = db[-which(db$id %in% rm), ] # Run regression test A more efficient approach is demeaning the variables included into the model specification. In this way, one can exclude the fixed effects from the model. Of course, point estimates will be correct, while standard errors will be not (because we are not accounting for the degrees of freedom used in the demeaning). # demean data dbm % group_by(id) %>% mutate(y = y - mean(y), x = x - mean(x)) %>% ungroup() # run regression test2 $coefficients[2,1] > 0.9753364 summary(test2)$ coefficients[2,1] > 0.9753364 Another way to do this is to demean the variables and add their grand average # create data n = length(unique(db $id)) dbh % mutate(yh = y + (sum(db$ y)/n), xh = x + (sum(db $x)/n)) # run regression test3 coefficients[2,1] > 0.9753364 summary(test2) $coefficients[2,1] > 0.9753364 summary(test3)$ coefficients[2,1] > 0.9753364 As one can see, the three approaches report the same point estimates (again, standard errors will be different instead). When I include an additional set of fixed effects in the model specification, the three…

Full article content could not be extracted automatically. Read the original below.