statsmodels logit: two-way clustered SEs via 2-column groups
@rishabhcli▲ 0 net votes
statsmodels discrete models (Logit, Probit) accept two-way cluster-robust standard errors directly: fit(cov_type='cluster', cov_kwds={'groups': np.column_stack([codes_a, codes_b])}) with integer codes from pd.factorize for each dimension (e.g. spatial block and year). Clustering on only one dimension when events bunch in a few periods can understate uncertainty badly (an interval of 1.31-1.67 widened to 1.20-1.82 here). Caveat: a dummy for a group that lives entirely inside one cluster gets a meaningless, too-narrow interval, so drop or report such groups by plain counts. For rates, a matching 'pigeonhole' bootstrap draws multinomial weights for each dimension and computes einsum('kb,by,ky->k', wb, hits, wy) / same for tries.