Statistics
AuraScore 83/100

Bayesian Hierarchical Staggered Rollout Estimator

Generate a self-contained PyMC script to estimate causal treatment effects under staggered adoption with unit-level heterogeneity.

Apply this template when observational panel data involves staggered policy interventions and varying group treatment effects. It generates a full Bayesian MCMC estimation and posterior predictive diagnostic script.

Template

Role: Senior Causal Inference Statistician and Bayesian Modeler

Context

  • Treatment Assignment: {{treatment_assignment_variable}}
  • Unit Identification: {{panel_unit_identifier}}
  • Temporal Dimension: {{temporal_index_variable}}
  • Prior Philosophy: {{prior_specification_level}}
  • Sampling Budget: {{mcmc_draws_target}}
  • Likelihood Family: {{outcome_distribution_family}}

Task

Author an end-to-end Bayesian hierarchical panel regression script using PyMC and ArviZ that estimates dynamic Average Treatment Effects on the Treated (ATT) under staggered adoption, accounting for two-way fixed effects and group-time heterogeneity without two-way fixed effects bias.

Method

  1. Ingest panel data, indexing {{panel_unit_identifier}} and {{temporal_index_variable}} into dense categorical tensor coordinates for PyMC.
  2. Engineer relative event-time indices ($k = t - g$) tracking relative duration since {{treatment_assignment_variable}} activation.
  3. Formulate the hierarchical model structure: baseline unit intercepts, temporal drift components, and event-time treatment parameters.
  4. Assign prior distributions conforming strictly to {{prior_specification_level}}, utilizing non-centered parameterizations for group variances.
  5. Specify the observation likelihood matching {{outcome_distribution_family}} to model heteroskedasticity and outlier contamination.
  6. Execute No-U-Turn Sampler (NUTS) with target parameters from {{mcmc_draws_target}}, capturing energy diagnostics and divergences.
  7. Compute posterior predictive distributions and calculate synthetic counterfactual trajectory plots for treated units.
  8. Extract dynamic event-study ATT estimates with 94% highest density intervals (HDI) and calculate the cumulative causal impact.

Constraints

  • Code MUST compile under PyMC v5+ using standard ArviZ and Aesara/PyTensor syntax.
  • MUST include explicit divergence tracking, $\hat{R}$ (Gelman-Rubin) convergence assertions, and effective sample size (ESS) checks.
  • MUST NOT use naive pooled OLS estimators or standard difference-in-differences with homogeneous dynamic effect assumptions.
  • Model coordinates and dimensions MUST be defined using PyMC coords and dims schema rather than hardcoded array indices.

Output format

Deliver the technical artifact divided into three exact parts:

  1. Model Architecture & DAG: A 200-word mathematical and structural explanation of the hierarchical parameterization.
  2. Complete PyMC Python Script: Executable script containing synthetic data generation for testing, PyMC model definition, sampling call, and convergence evaluation.
  3. Convergence & Inference Protocol: Structured markdown summary listing diagnostic thresholds (divergences = 0, $\hat{R} < 1.01$) and posterior interpretation guidelines.

Self-review

  • Confirm that the event-time indexing handles never-treated units without producing missing coordinate keys.
  • Verify that non-centered parameterization is correctly implemented on unit-level random intercepts.
  • Ensure the likelihood specification perfectly matches {{outcome_distribution_family}} with appropriate dispersion priors.
AuraScore breakdown
83/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness5/5 · Strong

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-statistics
complex-reasoning-analysis-math
statistics
causal-inference
bayesian