Doubly Robust Difference-in-Differences Estimators
Overview
Implements the locally efficient doubly robust difference-in-differences (DiD) estimators for the average treatment effect proposed by Sant'Anna and Zhao (2020) doi:10.1016/j.jeconom.2020.06.003. The estimator combines inverse probability weighting and outcome regression estimators (also implemented in the package) to form estimators with more attractive statistical properties. Two different estimation methods can be used to estimate the nuisance functions.
- Panel preprocessing now excludes whole units with missing covariates or sampling weights before checking time invariance. Retained units remain matched by ID, and observed time-varying covariates or weights still fail.
- Formula-based estimators preserve user columns named
y,D,post, orwwhen extracting outcomes, weights, and covariates. Renaming a variable no longer changes its meaning through internal preprocessing columns. - Improved DR estimators now require a numerically verified solution of the original exponential-IPT equations. Logit MLE is used only for initialization; failed IPT fits stop and suggest explicitly rerunning the traditional DR estimator. The secondary IPT candidate is checked against the original equations even when its continued objective reports convergence. The returned
ps.flagidentifies the verified fitting route (0 or 1); value 2 is removed. Fitting normalizes the common scale of weights to avoid scale-dependent optimizer stopping. Numerically ill-conditioned designs are rejected. Every weighted-bootstrap replicate must pass the same check, and failures stop with the replicate number without skipping or redrawing the fit.
Show all changes in 1.4.0Hide the rest of the changes in 1.4.0
- The weighted bootstrap in
drdid_imp_panel()now uses the point estimator's treated-weight denominator for its combined residual contributions. This makes each draw refit the same implemented statistic, including active trimming and supplied designs without an intercept. Weighted-bootstrap draws, standard errors, and intervals can change; point estimates, analytic inference, and multiplier inference are unchanged. - IPT criteria now evaluate weighted nonlinear contributions without first creating avoidable overflowing or underflowing intermediate exponentials. Weighted values, gradients, and Hessians retain representable terms and reject unresolved opposing overflow terms. The original criteria and continuation rule are preserved. Fitting reuses fixed-data checks and avoids unnecessary exceptional arithmetic while retaining these safeguards.
- Zero-weight rows no longer enter IPT objective, gradient, or Hessian arithmetic. Extreme finite covariates in those rows cannot create NaNs through zero times an overflowing intermediate value. The original objective divisor, model dimension, and secondary continuation threshold are preserved.
- The IPT propensity-score fallback used by the improved DR estimators now weights its full objective consistently with its gradient and Hessian. This corrects optimization with unequal observation or bootstrap weights when the primary
trustfit does not converge. - Sampling weights are checked before normalization; negative, nonfinite, all-zero, or incorrectly sized low-level weights now give a clear error. Legitimate zero weights and existing missing-data exclusion are preserved.
- The weighted bootstrap in
ipw_did_rc()now refits the same statistic as the point estimator, including normalization of the combined observation and bootstrap weights and the full-sample pre/post time shares. Trimming affects comparison contributions, as in the point estimator. Weighted bootstrap draws, standard errors, and intervals can change; the original ATT, analytic inference, and multiplier bootstrap are unchanged. ipw_did_rc()now includes the effect of sample-mean normalization of observation weights in its influence function and the resulting analytic and multiplier-bootstrap inference under iid sampling. The ATT point estimate is unchanged.- Bootstrap inference now returns a zero standard error and point interval when every centered bootstrap draw is exactly zero. Nonfinite draws or a zero IQR with nonzero draws stop with a clear error; no draws are removed or redrawn, and positive-scale inference retains its existing arithmetic.
twfe_did_panel()andtwfe_did_rc()now preserve matrix dimensions when removing a supplied intercept. An intercept plus one covariate now fits the same regression as supplying that covariate as a numeric vector or a matrix with one column, instead of failing. Intercept-only inputs retain their existing no-covariate behavior.twfe_did_panel()now accounts for dependence between each individual's pre/post observations in its analytical standard error. With covariates, the returned influence function now has one value per individual instead of one per period row. This matches individual-clustered sandwich inference without small-sample corrections and the other panel estimators' convention. The point estimate and both bootstrap procedures are preserved, up to floating-point precision. The no-covariate inference path is unchanged. Direct calls now reject missing or mismatched individual inputs before fitting, preventing row omission from breaking pre/post alignment.- Bootstrap estimation now rejects
nbootvalues that are not finite scalar integers of at least 2 before fitting or drawing bootstrap weights. The low-levelNULLdefault remains 999;boot = FALSEcontinues to ignore it. - Panel preprocessing for
drdid(),ordid(), andipwdid()now removes both observations of a unit when either outcome is missing, matches pre/post outcomes by individual ID, and checks group sizes after exclusions. Previously, dropping individual rows with missing outcomes could silently pair different individuals and produce incorrect point estimates and standard errors. Warnings now report the number of affected panel units. drdid_rc()anddrdid_rc1(): the estimation effect of the pre-period outcome regression for the comparison group now enters the influence function with the sign given in Appendix B of Sant'Anna and Zhao (2020). It previously entered with the opposite sign. Point estimates are unchanged. Analytic and multiplier-bootstrap standard errors change. The two versions agree asymptotically when the propensity score model is correctly specified, but not when only the outcome regressions are.- Treatment indicators must use 0 for comparison and 1 for treated units. Invalid coding is rejected explicitly rather than silently changing weights.
- The internal GLM fitter now rejects designs with fewer rows than columns before entering
fastglm. Such designs cannot have full column rank. Callers receive an ordinary R error when a regression cell is undersized; supported fits retain the same calculations.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
- ERROR12 OK, 1 ERROR2026-06-08
- OK13 OK2026-05-02
Show 4 earlier changesHide 4 earlier changes
- ERROR11 OK, 1 ERROR2026-04-25
- OK14 OK2026-04-22
- ERROR13 OK, 1 ERROR2026-04-18
- OK14 OK2026-03-10
Documentation
- Help pages
- 21 (1 internal)includes a package overview page
- Examples that run
- 100%17 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 86%
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- 350
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
Commits over time
Commit identities over time
10 development-tooling and community-health practices detected across 6 families in the upstream repository
Checks run against github.com/pedrohcgs/drdid on 2026-10-21.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-10-21 · The repository has a site deploy workflow
pkgdown site last built 2026-10-21, before release 1.4.0 (2026-10-22)
Show all practicesHide 2 practices
This repository shows signs of AI coding tools.
- Claude Codefirst seen 2026-05-25Commits: at least 1 crediting it in the message
- Claude CodePull requests: 1 from outside contributors, first on 2026-05-25, 1 from forks
- Claude Sonnet 4.61 commit · May 2026
Dependencies
Installing DRDID adds 12 packages (8 with compiled code, 26 MB of source tarballs). Heaviest: BH 14 MB, data.table 5.7 MB, Rcpp 1.8 MB.
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 1.4.0Latest
- 1.3.02026-06-10 · diff ↗
- RR 4.6.0 released · 2026-04-24
- 1.2.32025-12-04 · diff ↗
- 1.2.22025-05-30 · diff ↗
- RR 4.5.0 released · 2025-04-11
- 1.2.02024-10-07 · diff ↗
- 1.1.02024-09-05 · diff ↗
- 1.0.72024-07-06 · diff ↗
- RR 4.4.0 released · 2024-04-24
- 1.0.62023-05-18 · diff ↗
- RR 4.3.0 released · 2023-04-21
- unarchivedReturned to CRAN2022-07-19
- 1.0.42022-07-19 · diff ↗
- archivedRemoved from CRAN2022-07-09requires archived package 'BMisc'
- RR 4.2.0 released · 2022-04-22
Package metadata
- First published
- 2020-05-18
- Total releases
- 12 / 6 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 3.5
- Bundled data
- 401 KB / 3 files
- Download size
- 534 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("DRDID")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.1016/j.jeconom.2020.06.003.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-23, which the citation names so these numbers can be found later. More on citing and the projects behind them.