Learn R Programming

fwildclusterboot (version 0.3.4)

boottest.fixest: Fast wild cluster bootstrap inference for object of class fixest

Description

boottest.fixest is a S3 method that allows for fast wild cluster bootstrap inference for objects of class fixest by implementing the fast wild bootstrap algorithm developed in Roodman et al., 2019.

Usage

# S3 method for fixest
boottest(
  object,
  clustid,
  param,
  B,
  bootcluster = "max",
  fe = NULL,
  sign_level = NULL,
  conf_int = NULL,
  seed = NULL,
  beta0 = 0,
  type = "rademacher",
  impose_null = TRUE,
  p_val_type = "two-tailed",
  tol = 1e-06,
  maxiter = 10,
  na_omit = TRUE,
  nthreads = getBoottest_nthreads(),
  ...
)

Arguments

object

An object of class fixest

clustid

A vector with the clusters

param

Character vector of length one. The name of the regression coefficient for which the hypothesis is to be tested

B

Integer. number of bootstrap iterations

bootcluster

A character vector. Sets the cluster used in the bootstrap dgp. Chooses the largest cluster by default

fe

A character vector of length one. Fixed effect to be projected out in the bootstrap. Note: if regression weights are used, fe needs to be NULL.

sign_level

A numeric between 0 and 1. E.g. sign_level = 0.05 returns 0.95% confidence intervals. By default, sign_level = 0.05.

conf_int

A logical vector. If TRUE, boottest computes confidence intervals by p-value inversion. If FALSE, only the p-value is returned.

seed

An integer. Allows the user to set a random seed

beta0

A numeric. Shifts the null hypothesis H0: param = beta0 vs H1: param != beta0

type

character or function. The character string specifies the type of boostrap to use: One of "rademacher", "mammen", "norm" and "webb". Alternatively, type can be a function(n) for drawing wild bootstrap factors. "rademacher" by default.

impose_null

Logical. Controls if the null hypothesis is imposed on the bootstrap dgp or not. Null imposed (WCR) by default. If FALSE, the null is not imposed (WCU)

p_val_type

Character vector of length 1. Type of p-value. By default "two-tailed". Other options: "equal-tailed"

tol

Numeric vector of length 1. The desired accuracy (convergence tolerance) for confidence interval inversion. 1e-6 by default.

maxiter

Integer. Maximum number of iterations for confidence interval inversion. 10 by default.

na_omit

Logical. If TRUE, boottest() omits rows with missing variables that are added to the model via the clustid argument in boottest()

nthreads

The number of threads. Can be: a) an integer lower than, or equal to, the maximum number of threads; b) 0: meaning all available threads will be used; c) a number strictly between 0 and 1 which represents the fraction of all threads to use. The default is to use 1 core.

...

Further arguments passed to or from other methods.

Value

An object of class boottest

p_val

The bootstrap p-value.

t_stat

The bootstrap t-statistic.

conf_int

The bootstrap confidence interval.

param

The tested parameter.

N

Sample size. Might differ from the regression sample size if the cluster variables contain NA values.

B

Number of Bootstrap Iterations.

clustid

Names of the cluster Variables.

N_G

Dimension of the cluster variables as used in boottest.

sign_level

Significance sign_level used in boottest.

type

Distribution of the bootstrap weights.

p_test_vals

All p-values calculated while calculating the confidence interval.

test_vals

All t-statistics calculated while calculating the confidence interval.

regression

The regression object used in boottest.

call

Function call of boottest.

Confidence Intervals

boottest computes confidence intervals by inverting p-values. In practice, the following procedure is used:

  • Based on an initial guess for starting values, calculate p-values for 26 equal spaced points between the starting values.

  • Out of the 26 calculated p-values, find the two pairs of values x for which the corresponding p-values px cross the significance sign_level sign_level.

  • Feed the two pairs of x into an numerical root finding procedure and solve for the root. boottest currently relies on stats::uniroot and sets an absolute tolerance of 1e-06 and stops the procedure after 10 iterations.

Standard Errors

boottest does not calculate standard errors.

References

Roodman et al., 2019, "Fast and wild: Bootstrap inference in STATA using boottest", The STATA Journal. (https://journals.sagepub.com/doi/full/10.1177/1536867X19830877)

Examples

Run this code
# NOT RUN {
library(fwildclusterboot)
library(fixest)
data(voters)
feols_fit <-feols(proposition_vote ~ treatment + ideology1 + log_income,
           fixef =  "Q1_immigration", 
           data = voters)
boot1 <- boottest(feols_fit, 
                  B = 9999, 
                  param = "treatment",
                  clustid = "group_id1")
boot2 <- boottest(feols_fit, 
                  B = 9999, 
                  param = "treatment", 
                  clustid = c("group_id1", "group_id2"))
boot3 <- boottest(feols_fit,
                  B = 9999,
                  param = "treatment", 
                  clustid = c("group_id1", "group_id2"),
                  fe = "Q1_immigration")
boot4 <- boottest(feols_fit, 
                  B = 10000, 
                  param = "treatment", 
                  clustid = c("group_id1", "group_id2"),
                  fe = "Q1_immigration", 
                  sign_level = 0.2, 
                  seed = 8,
                  beta0 = 2)
summary(boot1)
plot(boot1)
# }

Run the code above in your browser using DataLab