User guide

Estimation and inference

This guide illustrates estimation of an average treatment effect under stratified randomization. A simulated example introduces the data structure, linear covariate adjustment, and interpretation of the reported estimates and standard errors.

Implementation
Detailed R documentation
For all estimator arguments, worked design specifications, returned results, plot customization, and simulation options, see the R guide and reference. The empirical application follows a complete analysis of experimental data.
Simulation specification
1,000 individuals · 4 large strata · 1 active treatment versus control · 2 baseline covariates. The simulated treatment effect is 0.5 outcome units.

01 · Installation

Install the released R package from CRAN, then load it:

install.packages("sreg")
library(sreg)

For the latest development version, install from the R repository:

install.packages("remotes")
remotes::install_github("jutrifonov/sreg")

The example below uses the large-strata estimator. Feature availability may differ between the CRAN release and the development version; record the installed version when reporting an empirical analysis.

02 · Data and estimand

For the individual-randomized example, let Y(1) and Y(0) denote potential outcomes under treatment and control. The estimand is the average treatment effect, τ = E[Y(1) − Y(0)]. With multiple active treatments, the package estimates an ATE for each treatment relative to control.

The simulation has 1,000 individuals in four strata and a treatment effect of 0.5. The generator returns observed outcomes Y, stratum indicators S, assignments D, and covariates x_1 and x_2. Treatment is assigned at the individual level within strata.

set.seed(42)
dat <- sreg.rgen(
  n = 1000,
  tau.vec = c(0.5),
  n.strata = 4,
  cluster = FALSE
)

head(dat)
table(dat$S, dat$D)

The random seed makes a simulation repeatable within a given implementation and environment. The same seed does not generate identical data across R, Stata, and Python. Compare estimates across languages using the same input dataset.

Variable Definition
Y The observed outcome for each individual
S The stratum used for randomization
D Treatment assignment: 0 for control, 1 for treatment
x_1, x_2 Baseline covariates used for linear adjustment

03 · Estimation and covariate adjustment

The following specification estimates the ATE with linear adjustment for x_1 and x_2. The default uses the large-strata procedure and applies the HC1 finite-sample correction to the variance estimator.

Covariates should be selected with reference to the experimental design and the intended adjustment specification. The package's adjustment procedure and corresponding variance estimator are described in the methodological references.

fit <- sreg(
  Y = dat$Y,
  S = dat$S,
  D = dat$D,
  X = dat[c("x_1", "x_2")]
)
print(fit)

Omit X for estimation without covariate adjustment:

fit_unadjusted <- sreg(Y = dat$Y, S = dat$S, D = dat$D)
print(fit_unadjusted)

04 · Interpretation and inference

Each row corresponds to an active treatment relative to control. The reported standard error is obtained from the variance estimator for the specified randomization design and adjustment procedure.

Quantity Interpretation
Treatment effect Estimated average effect of treatment relative to control, in the units of Y
Standard error Estimated sampling uncertainty, accounting for the selected design and adjustment
95% confidence interval The estimate plus or minus approximately 1.96 standard errors, based on the asymptotic normal approximation
p-value Two-sided asymptotic test of the null hypothesis that the corresponding ATE equals zero

In this simulation, the true ATE is 0.5. The estimation error varies across simulated samples. The efficiency properties of covariate adjustment concern the relevant asymptotic variance; they do not imply that estimated standard errors decrease in every finite sample.

Confidence intervals and tests rely on an asymptotic approximation. The HC1 correction does not make inference exact in finite samples. When several treatment effects are reported, the individual 95% intervals are marginal intervals, rather than a simultaneous confidence region.

The returned object provides the estimates, standard errors, and interval endpoints:

fit$tau.hat
fit$se.rob
cbind(lower = fit$CI.left, upper = fit$CI.right)

For this example, running R sreg 2.1.0 with seed 42 gives:

Estimated effect Standard error 95% confidence interval
0.48152 0.06456 [0.35500, 0.60805]

The estimated ATE is 0.48152 outcome units, with a standard error of 0.06456. The 95% interval contains the data-generating value of 0.5 and excludes zero.

05 · Specification for empirical applications

For an empirical application, supply observed outcomes, treatment assignments, randomization strata, and any covariates used for adjustment. Code control as 0 and active treatments as consecutive integers 1, 2, …. Stratum codes 1, 2, … provide a common format across implementations.

The specification must correspond to the assignment mechanism. Strata partition assignment units before randomization; clusters are groups of individuals assigned jointly to treatment. These identifiers have distinct roles in estimation and variance calculation.

Large strata

The example uses the large-strata procedure. For an unstratified experiment, omit the strata argument. The distinction between large and small strata concerns the stratification structure underlying the inference procedure, not the overall sample size alone.

Matched pairs and k-tuples

Select the small-strata estimator when the design uses small matched groups. The option is small.strata = TRUE in R, smallstrata in Stata, and small_strata=True in Python. In a uniform design the common group size can be inferred; an explicit k validates it.

Mixed small and large strata

Use the small-strata option to select mixed inference for varying stratum sizes. Specify k to identify the small component when it consists of 4-tuples or larger. At least 25% of strata must have the selected small-stratum size. See the estimator formulas and your implementation's reference before using this specification.

Cluster assignment

Supply cluster identifiers and represented cluster sizes: G.id and Ng in R, cluster() and clustersize() in Stata, or G_id and Ng in Python. For small or mixed strata, k counts clusters per small stratum. Individual-varying covariates are aggregated to cluster means for adjustment.

Design-specific variance estimation
The example uses individual assignment and large strata. Cluster-randomized and matched-group designs require their corresponding estimator options and variance formulas.

Empirical application

The Peru encouragement experiment provides a complete application using the package's AEJapp data: treatment recoding, unadjusted and age-adjusted estimates, confidence intervals, and plotting in R, Stata, and Python.

Reference documentation

Software citation

Cite the software version used in the analysis and the methodological papers corresponding to the estimator and randomization design. The project authors are Juri Trifonov, Yuehao Bai, Azeem Shaikh, and Max Tabord-Meehan.

Get the citation for your installed R version:

citation("sreg")

Based on the R, Stata, and Python package documentation. Installation routes and advanced features may differ by release.