*! version 2.1 16APR2026 Soo Jeong Lee and Jeffrey M. Wooldridge *

Title

lwdid -- Transformation-based rolling DID estimator (Lee & Wooldridge, 2025, 2026a)

Syntax

lwdid varlist [if] [in],
ivar(varname)
tvar(varname)
gvar(varname)
rolling(type)
[options]

Arguments and Options

Options

Main variables
varlist Outcome variable followed by optional covariates (x-variables).

Required options
ivar(varname) Panel identifier (numeric or string).

tvar(varname) Time variable, supplied as a single numeric time index. For seasonal adjustment, see rolling().

gvar(varname) Treatment cohort variable (first treated period). Never-treated units should be coded as 0 or missing. gvar() must be measured on the same scale as tvar().

rolling(type) Unit-specific outcome transformation for yvar:

demean removes the pre-treatment mean

detrend removes the pre-treatment linear trend

demeanq removes the pre-treatment mean and quarter-of-year effects

detrendq removes the pre-treatment linear trend and quarter-of-year effects

demeanm removes the pre-treatment mean and month-of-year effects

detrendm removes the pre-treatment linear trend and month-of-year effects

Required (depends on implementation)
method(ra|ipw|ipwra) Large-N only. Specifies the large-N estimation method:

ra for regression adjustment

ipw for inverse probability weighting

ipwra for doubly robust IPW-RA.

Required unless small is specified.

small Small-N only. Specifies the small-sample implementation for settings with few treated units, few control units, or both.

Optional options
save(filename) Save estimation results as a .dta file.

graph Displays graphical results.

Large-N: plots weighted ATT estimates by relative time.

Small-N: plots treated and control means of residualized outcomes over time.

gopts(string) Additional twoway graph options (only with graph).

gid(id) Select treated unit to plot (default: treated-group average).

vce(vartype) Variance estimator for regression (e.g., robust, cluster id, hc3).

reps(#) Large-N only. Number of bootstrap replications for large-N inference (default = 999).

ri Small-N only. Perform randomization inference (RI).

rireps(#) Small-N only. Number of RI repetitions (default = 999).

riseed(#) Small-N only. Seed for RI reproducibility (default: randomly drawn).

Description

lwdid implements the transformation-based rolling Difference-in-Differences estimators
developed in Lee and Wooldridge (2025, 2026a).
The command provides a unified implementation for panel data settings with either
a large-N or a small-N cross-sectional dimension, allowing treatment effects
to be estimated under both the staggered treatment adoption and the common timing case.

The central idea is to transform outcomes within each unit to remove
pre-treatment means, trends, or seasonal components, yielding residualized
outcomes. These transformed outcomes allow treatment effects to be estimated
using simple cross-sectional regressions in each post-treatment period,
facilitating both overall and period-specific ATT estimation.

By default, lwdid uses the large-N procedure of Lee and Wooldridge (2025),
which is designed for panels with a large cross-sectional dimension and allows for
heterogeneous treatment effects and unit-specific heterogeneous linear trends.

When the cross-sectional dimension is small (small-N), conventional
large-N inference may be unreliable. In such settings, specifying
the small option invokes the exact small-sample inference procedures
developed in Lee and Wooldridge (2026a). The seasonal-adjustment options
demeanq, detrendq, demeanm, and detrendm are currently available only under the small-N implementation.

Based on the treatment cohort variable specified in gvar(), lwdid
automatically detects whether the design involves a single treatment cohort
(common timing) or multiple cohorts (staggered adoption) and applies the
appropriate estimation procedure.

Details of the implementation are given in Lee and Wooldridge (2026b);
see also the lwdid GitHub repository
for additional examples and documentation.

Examples

Example 1: Large-N estimation (RA, demean transformation)

. lwdid y, ivar(id) tvar(year) gvar(first_treat) rolling(demean) method(ra) graph

Example 2: Large-N estimation (IPWRA, detrend transformation)

. lwdid y x1 x2, ivar(id) tvar(year) gvar(first_treat) rolling(detrend) method(ipwra) save(myresult) graph gopts(ytitle("Residualized average outcome") xtitle("Year") title("The Effects of Walmart Opening"))

This example estimates treatment effects using the IPWRA estimator with the
detrend transformation. The option save(myresult) saves the estimates to
myresult.dta. The gopts() option customizes the graph.

Example 3: Small-N estimation (Quarterly data with detrending and seasonal adjustment)

. gen qdate = yq(year, quarter)
. format qdate %tq
. gen gq = yq(first_year, first_quarter)
. format gq %tq
. lwdid y, small ivar(id) tvar(qdate) gvar(gq) rolling(detrendq) graph

With the small option, lwdid implements the small-N inference
procedure. Here the example uses quarterly data with the detrendq
transformation. For quarterly seasonal adjustment, tvar() should be
a single Stata quarterly date variable created by yq(), and gvar()
should be on the same scale.

Example 4: Small-N estimation (Monthly data with detrending and seasonal adjustment)

. gen mdate = ym(year, month)
. format mdate %tm
. gen gm = ym(first_year, first_month)
. format gm %tm
. lwdid y, small ivar(id) tvar(mdate) gvar(gm) rolling(detrendm) graph

This example uses monthly data with the detrendm transformation. For
monthly seasonal adjustment, tvar() should be a single Stata monthly
date variable created by ym(), and gvar() should be on the same
scale.

Citation

Lee, Soo Jeong, and Jeffrey M. Wooldridge (2025),
"A Simple Transformation Approach to Difference-in-Differences Estimation for Panel Data,"
Working Paper, Available at SSSRN 4516518.

Lee, Soo Jeong, and Jeffrey M. Wooldridge (2026a),
"Simple Approaches to Inference with Difference-in-Differences Estimators with Small Cross-Sectional Sample Sizes,"
Working Paper, Available at SSRN 5325686

Lee, Soo Jeong, and Jeffrey M. Wooldridge (2026b),
"Rolling Difference-in-Differences Estimation for Small and Large Panels,"
Working Paper, Available at SSRN 6502558

Authors

Soo Jeong Lee
Southern Illinois University Carbondale
soojeong.lee@siu.edu

Jeffrey M. Wooldridge
Michigan State University
wooldri1@msu.edu