# NOT RUN {
#
# Equivalence with lm/glm standard-errors
#
res = feols(Petal.Length ~ Petal.Width + Species, iris)
res_lm = lm(Petal.Length ~ Petal.Width + Species, iris)
# lm applies a correction of the type adj = 1 (fixest's default)
vcov(res) / vcov(res_lm)
# Glm
res_pois = fepois(round(Petal.Length) ~ Petal.Width + Species, iris)
res_glm = glm(round(Petal.Length) ~ Petal.Width + Species, iris, family = poisson())
# glm applies a correction of the type adj = 0 (this time not fixest's default)
vcov(res_pois, dof = dof(adj = 0)) / vcov(res_glm)
# Same example with the Gamma
res_gamma = feglm(round(Petal.Length) ~ Petal.Width + Species, iris, family = Gamma())
res_glm_gamma = glm(round(Petal.Length) ~ Petal.Width + Species, iris, family = Gamma())
vcov(res_gamma, dof = dof(adj = 0)) / vcov(res_glm_gamma)
#
# Fixed-effects corrections
#
# We create "irregular" FEs
base = data.frame(x = rnorm(10))
base$y = base$x + rnorm(10)
base$fe1 = rep(1:3, c(4, 3, 3))
base$fe2 = rep(1:5, each = 2)
est = feols(y ~ x | fe1 + fe2, base)
# fe1: 3 FEs
# fe2: 5 FEs
#
# Clustered standard-errors: by fe1
#
# Default: fixef.K = "nested"
# => adjustment K = 1 + 5 (i.e. x + fe2)
summary(est)
attributes(vcov(est))[c("dof.type", "dof.K")]
# fixef.K = FALSE
# => adjustment K = 1 (i.e. only x)
summary(est, dof = dof(fixef.K=FALSE))
attr(vcov(est, dof = dof(fixef.K=FALSE)), "dof.K")
# fixef.K = TRUE
# => adjustment K = 1 + 3 + 5 - 1 (i.e. x + fe1 + fe2 - 1 restriction)
summary(est, dof = dof(fixef.K=TRUE))
attr(vcov(est, dof = dof(fixef.K=TRUE)), "dof.K")
# fixef.K = TRUE & fixef.exact = TRUE
# => adjustment K = 1 + 3 + 5 - 2 (i.e. x + fe1 + fe2 - 2 restrictions)
summary(est, dof = dof(fixef.K=TRUE, fixef.exact = TRUE))
attr(vcov(est, dof = dof(fixef.K=TRUE, fixef.exact = TRUE)), "dof.K")
# There are two restrictions:
attr(fixef(est), "references")
# }
Run the code above in your browser using DataLab