Skip to content

Instantly share code, notes, and snippets.

@apoorvalal
Created December 8, 2023 20:16
Show Gist options
  • Save apoorvalal/f268f64d3cf32c5264aca415ef51abb0 to your computer and use it in GitHub Desktop.
Save apoorvalal/f268f64d3cf32c5264aca415ef51abb0 to your computer and use it in GitHub Desktop.
numerical verification of equality of coefficient and SE per FWL
library(estimatr)
data(auto)
# %% FWL regression coefficient
auto$ytil = lm(price ~ displacement, auto)$resid
auto$x2til = lm(weight ~ displacement, auto)$resid
(fwlest = lm_robust(ytil ~ x2til, auto, se_type = "HC0")
%>% summary %>% .$coefficients %>% .[2, 1:2])
# %%
(fullest =
lm_robust(price ~ weight + displacement, auto, se_type = "HC0") %>%
summary %>% .$coefficients %>% .[2, 1:2]
)
# %% theorem 1 and theorem 2 - Ding 2021 Statistics and Probability Letters
all.equal(fwlest, fullest)
# %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment