synth-inference / synthdid

Synthetic difference in differences
https://synth-inference.github.io/synthdid
BSD 3-Clause "New" or "Revised" License
262 stars 98 forks source link

Proposal to enhance standard error estimation for CI using placebo_se #128

Open PetraTschuchnig opened 5 days ago

PetraTschuchnig commented 5 days ago

The current implementation of the placebo_se function uses the weights from the true treatment group as the initial weights for the placebo estimation (adjusted for the placebo number of control groups, N0). This initialization can lead to biased weights in the placebo evaluation, as it may cause the optimization to get stuck in a local minimum. To ensure that the placebo_se function works for all estimation methods (e.g., SDID, SC, DID, ...), the theta function in the placebo_se function should be modified as follows:

theta = function(ind) {
    N0 = length(ind)-N1
    noise.level = sd(apply(setup$Y[ind[1:(length(ind)-1)], 1:setup$T0], 1, diff))
    opts$min.decrease = 1e-05 * noise.level
    if((opts$zeta.omega/noise.level) > 1e-05){
      eta.omega = (N1 * (ncol(setup$Y) - setup$T0))^(1/4)
      opts$zeta.omega = eta.omega * noise.level
    }else{
      eta.omega = 1e-06
      opts$zeta.omega = eta.omega * noise.level
    }
    if((opts$zeta.lambda/noise.level) < 1e-05){
      eta.lambda = 1e-06
      opts$zeta.lambda = eta.lambda * noise.level
    }
    weights.boot = list()
    if(opts$update.lambda == TRUE){
      weights.boot$lambda = rep(1/setup$T0, setup$T0)
    }else{
      weights.boot$lambda = weights$lambda
    }
    if(opts$update.omega == TRUE){
      weights.boot$omega = rep(1/N0, N0)
    }else{
      weights.boot$omega = sum_normalize(weights$omega[ind[1:N0]])
    }
    do.call(synthdid_estimate, c(list(Y=setup$Y[ind,], N0=N0,  T0=setup$T0, weights=weights.boot), opts))
  }

If you find this change reasonable, I would be happy to push the changes to a fork and create a merge request.

(To know what the unbiased standard errors need to be, I used the specific function for each estimation method during the placebo evaluation, without applying options or weights from the true treatment group. For example, as theta function in the placebo_se function for SC I used:

theta = function(ind) {
    N0 = length(ind)-N1
    do.call(sc_estimate, c(list(Y=setup$Y[ind,], N0=N0,  T0=setup$T0)))
  }

If needed, I'd be happy to send you the code via email.)