After reading the seminal paper on synthetic DiD, I think the way zeta is calculated in calculate_regularization may be incorrect depending how the input data is ordered. As it stands, the function will calculate the true first difference only if the data frame is ordered by time. Otherwise, it will calculate the "first difference" for each state/unit in whatever order the observations appear. I believe the following edit will solve this problem and ensure the first difference is always calculated properly. Thanks!
After reading the seminal paper on synthetic DiD, I think the way zeta is calculated in
calculate_regularization
may be incorrect depending how the input data is ordered. As it stands, the function will calculate the true first difference only if the data frame is ordered by time. Otherwise, it will calculate the "first difference" for each state/unit in whatever order the observations appear. I believe the following edit will solve this problem and ensure the first difference is always calculated properly. Thanks!first_diff_std = (data .query(f"~{post_col}") .query(f"~{treat_col}") .sort_values(year_col).groupby(state_col) [outcome_col] .diff() .std())