# NOT RUN {
#
# Equivalence with lm/glm standard-errors
#
# LM
# In the absence of fixed-effects,
# by default, the standard-errors are computed in the same way
res = feols(Petal.Length ~ Petal.Width + Species, iris)
res_lm = lm(Petal.Length ~ Petal.Width + Species, iris)
vcov(res) / vcov(res_lm)
# GLM
# By default, there is no small sample adjustment in glm, as opposed to feglm.
# To get the same SEs, we need to use dof(adj = FALSE)
res_pois = fepois(round(Petal.Length) ~ Petal.Width + Species, iris)
res_glm = glm(round(Petal.Length) ~ Petal.Width + Species, iris, family = poisson())
vcov(res_pois, dof = dof(adj = FALSE)) / 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 = FALSE)) / 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 = "none"))
attr(vcov(est, dof = dof(fixef.K = "none")), "dof.K")
# fixef.K = TRUE
# => adjustment K = 1 + 3 + 5 - 1 (i.e. x + fe1 + fe2 - 1 restriction)
summary(est, dof = dof(fixef.K = "full"))
attr(vcov(est, dof = dof(fixef.K = "full")), "dof.K")
# fixef.K = TRUE & fixef.force_exact = TRUE
# => adjustment K = 1 + 3 + 5 - 2 (i.e. x + fe1 + fe2 - 2 restrictions)
summary(est, dof = dof(fixef.K = "full", fixef.force_exact = TRUE))
attr(vcov(est, dof = dof(fixef.K = "full", fixef.force_exact = TRUE)), "dof.K")
# There are two restrictions:
attr(fixef(est), "references")
#
# To permanently set the default dof:
#
# eg to set it a la Stata's reghdfe:
setFixest_dof(dof(cluster.df = "min", t.df = "min"))
# To reset it
setFixest_dof()
# }
Run the code above in your browser using DataLab