# Let's make a short simulation
# Inspired from Grant McDermott bboot function
# See https://twitter.com/grant_mcdermott/status/1487528757418102787
# Simple function that computes a Bayesian bootstrap
bboot = function(x, n_sim = 100){
# We bootstrap on the weights
# Works with fixed-effects/IVs
# and with any fixest function that accepts weights
core_env = update(x, only.coef = TRUE, only.env = TRUE)
n_obs = x$nobs
res_all = vector("list", n_sim)
for(i in 1:n_sim){
## begin: NOT RUN
## We could directly assign in the environment:
# assign("weights.value", rexp(n_obs, rate = 1), core_env)
# res_all[[i]] = est_env(env = core_env)
## end: NOT RUN
## Instead we can use the argument weights, which does the same
res_all[[i]] = est_env(env = core_env, weights = rexp(n_obs, rate = 1))
}
do.call(rbind, res_all)
}
est = feols(mpg ~ wt + hp, mtcars)
boot_res = bboot(est)
coef = colMeans(boot_res)
std_err = apply(boot_res, 2, sd)
# Comparing the results with the main estimation
coeftable(est)
cbind(coef, std_err)
Run the code above in your browser using DataLab