help for causalspline

Title

causalspline -- Nonlinear causal dose-response estimation
via restricted cubic splines

Syntax

causalspline
[if] [in]
,
outcome(varname)
treatment(varname)
confounders(varlist)
[options]

Required
outcome(varname) outcome variable Y

treatment(varname) continuous treatment variable T

confounders(varlist) pre-treatment confounders X

Estimation
method(string) estimation method: ipw (default),
gcomp, dr

dfexposure(#) spline df for treatment curve; default 4

evalgrid(#) number of grid evaluation points; default 100

bootreps(#) bootstrap replications for SE; default 200

level(#) confidence level; default 95

Output
savecurve(filename) save dose-response curve to dataset

verbose print progress messages

Description

causalspline estimates the causal dose-response function
E[Y(t)] = E[Y^(t)] for a continuous treatment T under the
unconfoundedness assumption (Y(t) ? T | X for all t).

The exposure-response curve f(T) is modeled using restricted cubic
splines (Harrell parameterisation), allowing recovery of nonlinear
dose-response shapes: thresholds, diminishing returns, inverted-U
patterns, and other nonlinear structures without parametric assumptions.

Three identification strategies are available:

ipw: Inverse Probability Weighting via the Generalised Propensity
Score (GPS). Fits a linear model for T|X, computes stabilised weights
w_i = f(T_i) / f(T_i|X_i) using normal densities, trims at the 1st/99th
percentiles, and estimates E[Y(t)] by weighted regression of Y on the
spline basis.

gcomp: G-computation (outcome regression). Fits OLS of Y on
spline basis plus covariates, then standardises predictions over the
covariate distribution.

dr: Doubly robust. Averages the IPW and G-computation estimates.
Consistent if either the GPS model or the outcome model is correctly
specified.

Standard errors are obtained by nonparametric bootstrap.

Post-estimation commands

After causalspline, the following companion commands are available:

cs_gradient - first and second numerical derivatives of E[Y(t)]

cs_fragility - geometric fragility curve (curvature / slope diagnostics)

cs_region, a(#) b(#) - regional fragility integral over [a, b]

cs_overlap - ESS and weight diagnostics

cs_plot - dose-response curve graph

Stored results

causalspline stores the following in r():

Scalars

r(n) sample size

r(t_min) minimum treatment value

r(t_max) maximum treatment value

r(ess) effective sample size (IPW/DR only)

r(ess_pct) ESS as % of n (IPW/DR only)

r(evalgrid) number of evaluation points

r(dfexposure) spline df for exposure

Matrices

r(curve_t) treatment grid (ng x 1)

r(curve_est) estimated E[Y(t)] (ng x 1)

r(curve_se) bootstrap SE (ng x 1)

r(curve_lo) lower CI bound (ng x 1)

r(curve_hi) upper CI bound (ng x 1)

Macros

r(method) estimation method

r(outcome) outcome variable name

r(treatment) treatment variable name

r(cmd) causalspline

Examples

Simulate data and run all methods

. cs_simulate 500, dgp(threshold) seed(1) clear

. causalspline, outcome(Y) treatment(T) confounders(X1 X2 X3) method(ipw)

. cs_plot

. cs_overlap

. cs_gradient

. cs_fragility, type(curvature_ratio)

. cs_region, a(2) b(4)

G-computation

. causalspline, outcome(Y) treatment(T) confounders(X1 X2 X3) ///

method(gcomp) dfexposure(5) evalgrid(100)

Doubly robust with saved curve

. causalspline, outcome(Y) treatment(T) confounders(X1 X2 X3) ///

method(dr) bootreps(500) savecurve(my_curve.dta)

Fragility diagnostics

. cs_fragility, type(inverse_slope) savefragility(frag.dta)

. cs_region, a(3) b(7) type(curvature_ratio)

Methods and formulas

Let T be a continuous treatment, Y the outcome, X a vector of covariates.
The causal dose-response function is mu(t) = E[Y(t)].

GPS / IPW weights:
Fit E[T|X] via OLS. Compute stabilised weights:
w_i = ?(T_i; mu_T, ?_T) / ?(T_i; ?[T_i|X_i], ??)
where ? is the normal density. Weights are trimmed and Hajek-normalised.

Spline basis:
Uses Harrell's restricted cubic spline parameterisation (implemented via
mkspline, cubic).

Fragility measures:
slope fragility: F_s(t) = 1 / (|mu'(t)| + epsilon)
curvature fragility: F_c(t) = |mu''(t)| / (|mu'(t)| + epsilon)
where epsilon = 0.05 x median|mu'(t)| (adaptive).

Regional fragility:
F?[a,b] = (1/(b-a)) ?_a^b F(t) dt (trapezoidal integration)

References

Hirano, K. & Imbens, G.W. (2004). The propensity score with continuous
treatments. In Gelman & Meng (Eds.), Applied Bayesian Modeling and Causal
Inference from Incomplete-Data Perspectives (pp. 73-84). Wiley.

Imbens, G.W. (2000). The role of the propensity score in estimating
dose-response functions. Biometrika, 87(3), 706-710.

Robins, J.M., Hernan, M.A. & Brumback, B. (2000). Marginal structural
models and causal inference in epidemiology.
Epidemiology, 11(5), 550-560.

Hait, S. (2026). CausalSpline: Nonlinear Causal Dose-Response Estimation
via Splines. R package v0.1.0.
https://github.com/causalfragility-lab/CausalSpline

Author

Stata port based on CausalSpline R package by Subir Hait,
Michigan State University (haitsubi@msu.edu).

Also see

Online: cs_gradient, cs_fragility, cs_region,
cs_overlap, cs_simulate, cs_plot