help clusterdid

Title

clusterdid -- Power analysis for cluster randomized trials, difference-in-differences sample size, and repeated cross-sections power calculator. Determines minimum detectable effect size (MDES), required clusters, and sample scale for dynamic panel evaluations.

Syntax

clusterdid [, evaluation_targets design_options]

You must specify exactly three of the four evaluation_targets (m, n, d/(p), or power). The command will automatically evaluate the missing parameter. Providing a numlist for any single target automatically generates a diagnostic frontier graph.

Evaluation Targets

m(numlist) total number of level-2 clusters across both arms

n(numlist) number of level-1 observations per cluster, per time period

d(numlist) raw continuous mean difference (e.g., d(15)), or expected treatment and control means (e.g., d(60 45))

p(numlist) expected treatment and baseline/control proportions for binary outcomes (e.g., p(0.6 0.4)). Replaces d

power(numlist) statistical power (1 - beta)

Design Options

Architecture
t0(#) number of baseline (pre-treatment) periods; default is t0(1)

t1(#) number of evaluation (post-treatment) periods; default is t1(1)

alloc(#) proportion of clusters assigned to treatment; default is alloc(0.5)

Error Components
rhoj(#) between-cluster intraclass correlation coefficient (ICC); default is rhoj(0.05)

rhot(#) time autocorrelation of the cluster-level error; default is rhot(0.70)

Covariate Adjustments
r2c(#) proportion of cluster-level variance explained by covariates (partial R-squared); default is r2c(0.0)

r2i(#) proportion of individual-level variance explained by covariates (partial R-squared); default is r2i(0.0)

Outcome Distributions
sd(numlist) raw population standard deviation for continuous outcomes. Can accept a single value (e.g., sd(15)) or two values to be pooled (e.g., sd(15 12)); default is sd(1.0)

Significance
alpha(#) Type I error probability (significance level); default is alpha(0.05)

Graphing
name(string) name of the graph tab in Stata's memory (useful for keeping multiple graphs open simultaneously)

Description

clusterdid establishes a generalized, parallel-group difference-in-differences (DiD) cluster randomized trial framework observed over a longitudinal panel of T = T0 + T1 periods. It integrates the multi-way and nested error component models from Baltagi (2021) to capture permanent and time-varying cluster shocks.

Unlike legacy power commands restricted to single post-treatment snapshots or purely standardized metrics, clusterdid natively accommodates multi-period repeated cross-sections, allowing researchers to evaluate how expanding baseline and endline tracking horizons mathematically reduces the variance multiplier.

Precision Gains & Covariate Adjustments: Unlike older tools that apply a blunt, global correlation penalty across all variance, clusterdid properly partitions covariate adjustment. Users can specify r2c to absorb cluster-level shocks (e.g., school district funding) and r2i to absorb idiosyncratic individual-level shocks (e.g., student baseline test scores). This mathematically isolates the variance reduction to the correct tier in the error components framework.

The command operates seamlessly across outcome types using an intuitive 1- or 2-value input parser:

1. Continuous Outcomes: Users can specify a single raw difference (d(15)) or paired treatment and control means (d(60 45)). Standard deviations can likewise be specified as a single population parameter (sd(20)) or paired values to be pooled (sd(20 18)). If sd is omitted, it defaults to 1.0 (standardized effect size).

2. Binary Proportions: By specifying p, users can provide paired expected treatment and control proportions (p(0.6 0.4)) or a single treatment target (p(0.6), which implicitly assumes a 0.5 baseline). The command automatically routes inputs through a linear probability model approximation, imputing the binomial population variance without requiring manual standardization.

Automated Graphing Engine: Supplying a Stata numlist to any evaluation target (e.g., m(10(5)50)) triggers an automated line graph mapping the evaluation parameter frontier. If standard policy benchmarks (e.g., 80% power) are intercepted, the graph automatically overlays target crosshairs and intersection points. Using the name option allows users to pop open multiple scenarios in separate tabs for easy comparison.

Examples

1. Classic 2x2 DiD with continuous outcome (Solving for Power)

Solve for statistical power given 1 pre-period, 1 post-period, 40 total clusters, 50 individuals per cluster, paired treatment and control means of 60 and 45, and a pooled standard deviation of 45:

. clusterdid, t0(1) t1(1) rhoj(0.05) rhot(0.70) m(40) n(50) d(60 45) sd(45)

2. Symmetric Multi-Period Panel with Binary Proportion (Solving for Clusters)

Determine required total clusters for a 3-baseline, 3-endline panel tracking an employment intervention moving from 40% (control) to 50% (treatment):

. clusterdid, t0(3) t1(3) rhoj(0.05) rhot(0.70) p(0.50 0.40) n(30) power(0.80)

3. Asymmetric Reality (Solving for MDE with imbalanced allocation)

Determine the expected raw mean difference required for a trial with 1 baseline, 4 endlines, a 30/70 treatment allocation split, and unequal standard deviations (1.2 and 1.5):

. clusterdid, t0(1) t1(4) alloc(0.30) rhoj(0.10) rhot(0.50) m(60) n(20) power(0.80) sd(1.2 1.5)

4. Covariate-Adjusted Power Evaluation

Calculate the required sample scale (n) when incorporating covariates that explain 40% of the cluster-level variance and 15% of the individual-level variance:

. clusterdid, t0(2) t1(2) rhoj(0.08) rhot(0.60) r2c(0.40) r2i(0.15) m(30) d(0.20) power(0.80)

5. Generating an Interactive Graph (Range Plotting with Tabs)

Visualize the power curve across a range of cluster counts from 10 to 80, given a raw difference of 0.25 and an SD of 1.0. Name the graph so it opens in a new tab without overwriting your existing ones:

. clusterdid, t0(2) t1(2) rhoj(0.05) rhot(0.70) m(10(2)80) n(50) d(0.25) sd(1.0) name(power_curve, replace)

Saved results

clusterdid saves the following scalars in r():

Scalars

r(m) Total number of level-2 clusters

r(mt) Number of level-2 clusters in the treatment arm

r(mc) Number of level-2 clusters in the control arm

r(n) Number of level-1 observations per cluster, per period

r(delta) Raw minimum detectable effect size (MDE)

r(power) Statistical power (1 - beta)

r(N) Total individual observations across all groups and all tracked periods

Author

Wael Moussa, PhD

FHI 360

Washington, DC

wmoussa@fhi360.org

References

Baltagi, B. H. (2021). Econometric Analysis of Panel Data. Springer Texts in Business and Economics.

Frison, L. and Pocock, S. J. (1992). Repeated measures in clinical trials: Analysis using mean summary statistics and its implications for design. Statistics in Medicine, 11(13):1685-1704.

McKenzie, D. (2012). Beyond baseline and follow-up: The case for more T in experiments. American Economic Journal: Applied Economics, 4(2):210-234.

Schochet, P. Z. (2021). Statistical Power for Estimating Treatment Effects Using Difference-in-Differences and Comparative Interrupted Time Series Estimators with Variation in Treatment Timing.

Disclaimer

Any errors are the author's alone. Please email wmoussa@fhi360.org to report any issues.