R/wboot_twfe_rc.R

Defines functions wboot_twfe_rc

# Bootrstapped TWFE Difference-in-Differences with Repeated Cross Section Data
# 2 periods and 2 groups

wboot_twfe_rc <- function(nn, n, y, dd, post, x, i.weights){
  #-----------------------------------------------------------------------------
  v <- stats::rexp(n)
  #v <- v / mean(v)
  #weights for the bootstrap
  b.weights <- as.vector(i.weights * v)
  #Compute the TWFE Regression
  if(!is.null(x)){
    reg.b <- stats::lm(y ~  dd:post + post + dd + x, weights = b.weights)
  } else{
    reg.b <- stats::lm(y ~  dd:post + post + dd, weights = b.weights)
  }
  twfe.att.b <- reg.b$coefficients["dd:post"]
  #-----------------------------------------------------------------------------
  return(twfe.att.b)
}

Try the DRDID package in your browser

Any scripts or data that you put into this service are public.

DRDID documentation built on May 31, 2023, 9:10 p.m.