- Introduced by
- Li & Marchand (formal Bayesian DiD framework); Brodersen et al. (Bayesian causal inference in time series)
- Year
- 2015-2023
- Type
- Bayesian causal inference / panel regression
- Family
- Quasi-experimental / causal inference
What does it do?
Bayesian Difference-in-Differences applies Bayesian inference to the standard two-group, two-period DiD regression.
Priors are placed on the coefficients, and the treatment effect, the interaction coefficient β3, is reported as a posterior distribution with a credible interval rather than a single point estimate with a confidence interval. The approach is most relevant when data are limited or when external prior information about the effect is available. The outcome model shown here assumes conditionally independent observations; panel data require unit and period effects or clustered random effects before credible intervals are reported.
The intuition behind the method
Classic DiD gives a single number for the treatment effect, with a confidence interval. Bayesian DiD gives a probability distribution over the plausible effect sizes, called the posterior. You start with a prior belief about the coefficients, update it with the data, and read off how probable different values of the interaction term are. This is useful when external evidence should inform the estimate or when the data are sparse and a frequentist estimate is unstable. The posterior lets you ask directly how probable it is that the effect is positive, instead of relying only on a significance test.
History
Brodersen et al. (2015) proposed a Bayesian state-space model for estimating the causal impact of an intervention by predicting a counterfactual market response from a synthetic control. Their abstract contrasts this approach with classical difference-in-differences schemes: state-space models make it possible to infer the temporal evolution of attributable impact, incorporate empirical priors on the parameters in a fully Bayesian treatment, and accommodate local trends, seasonality and time-varying covariates. Posterior inference uses Markov chain Monte Carlo, and the approach is implemented in the CausalImpact R package.
When to use it
Use Bayesian DiD when you have panel or repeated cross-sectional data with a treated group, a comparison group, and at least one period before and after treatment, and when you want probability statements about the effect or want to include prior evidence from earlier studies. It is most useful when the number of units is small, so that a frequentist interval is unstable. Do not use it to compensate for a weak design: the parallel-trends assumption still applies, and a prior cannot correct confounding. For panel data, the outcome model must include unit and period effects, or clustered random effects, before its credible intervals are interpreted. It is also a poor fit when the journal or audience requires frequentist reporting, or when MCMC sampling is not feasible. If the question concerns the impact of an intervention on one aggregate time series with a synthetic counterfactual, the state-space approach of Brodersen et al. (2015) may be more appropriate.
Limitations and considerations
- As written, the likelihood has no unit or period effects and treats observations as conditionally independent given four coefficients. With repeated observations per unit, uncertainty for β3 is understated unless unit and period effects or clustered random effects are added.
- When there are few units, the prior on β3 can carry substantial weight, so the posterior partly reflects the prior rather than the data.
- The parallel-trends assumption is still required. If the groups were diverging before treatment, the posterior for β3 will attribute that divergence to the treatment, whatever the prior.
- The posterior is computed by MCMC or a similar method, so the estimate depends on sampler convergence and the run must be checked before results are reported.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The treatment effect is a single named coefficient (β3) in the model, so the posterior answers a direct question about its sign and magnitude, such as how much posterior mass lies above zero. This answer holds only under the identifying assumptions, chiefly parallel trends, which the posterior does not test.
- σ² is estimated jointly with β3, so uncertainty about the residual variance feeds into the credible interval for the effect instead of being fixed at a point estimate.
- The prior on β3 is the explicit point where external evidence about the effect enters, which can stabilise the estimate when there are few units.
- Because β3 is on the outcome scale, the posterior summary can be compared directly with the coefficient from an OLS DiD regression on the same data.
Applications
- Evaluating a small policy pilot with few treated and comparison units, where a prior from earlier evaluations of similar interventions is available.
- Sensitivity analysis: reporting the posterior for β3 under several prior choices alongside the OLS DiD estimate on the same data.
- Decision settings where the question is the probability that the effect is positive, rather than whether a p-value falls below a threshold.
- Panel applications that extend the two-period model with unit and period effects or clustered random effects, as described under the likelihood step.
How it works
How it works
The outcome model has the standard DiD regression structure: the outcome for unit i at time t depends on a treatment-group indicator, a post-period indicator, and their interaction, which carries the causal effect. The Bayesian version treats these coefficients and the error variance as unknown parameters and defines a Normal likelihood for the observed outcomes given them. The model as written has no unit-level or period-level effects, so it treats observations as conditionally independent given the four coefficients. This is appropriate for a single cross-section of independent units. For panel data, where the same unit is observed repeatedly, unit and period effects or clustered random effects should be added so that within-unit correlation is modelled and the credible interval for β3 is not too narrow.
Formula
y_{it} \mid \beta, \sigma^2 \sim \mathcal{N}(\beta_0 + \beta_1\,\text{Treat}_i + \beta_2\,\text{Post}_t + \beta_3\,(\text{Treat}_i \times \text{Post}_t),\; \sigma^2)The model places priors on the interaction coefficient β3 and on the error variance σ². The prior on β3 is the most consequential choice, because it is the treatment effect. A weakly informative prior centred at zero, scaled to the units of the outcome, is one option when no prior evidence exists, but the scale should be justified rather than assumed. Informative priors can encode findings from earlier studies, and their influence on the posterior should be reported. When the number of units is small, the prior on β3 can dominate the posterior, so a prior sensitivity analysis should be reported alongside the main result. Priors for the intercept and the group and period coefficients must also be specified to fit the model.
Formula
\beta_3 \sim p(\beta_3),\quad \sigma^2 \sim p(\sigma^2)
The posterior for the treatment effect follows from Bayes' theorem: the joint posterior is proportional to the joint likelihood multiplied by the joint prior. The expression in the mechanics step is not a complete marginal posterior, because the likelihood depends on all coefficients and σ². The marginal posterior of β3 is obtained by integrating out the intercept, the group and period coefficients, and σ². This integral has no closed form in general and is approximated by Markov Chain Monte Carlo (MCMC) or variational inference, which produce samples from which the marginal for β3 is read.
Formula
p(\beta_3 \mid y) \propto p(y \mid \beta_3)\, p(\beta_3)
The effect is usually summarised by the posterior mean or median of β3, together with a posterior credible interval such as a 90% or 95% interval. Because β3 is on the scale of the outcome, it can be interpreted in the same units as an OLS DiD coefficient. A credible interval states directly how probable it is, given the data and prior, that the true effect lies within it.
Formula
\hat{\tau}_{ATT} = \mathbb{E}[\beta_3 \mid y]\quad \text{with posterior credible interval}Pre-treatment trends should be checked with an event-study extension of the model: add interactions between the treatment-group indicator and indicators for several pre-treatment periods, omitting one period as the reference. Under parallel trends these pre-period interaction coefficients should be near zero, so their posteriors should concentrate near zero with credible intervals that include zero. Large posterior mass away from zero indicates diverging pre-treatment trends, which undermines the estimate of β3. The check is performed on the extended model, not on the two-period model alone.
Common pitfalls
- Choosing an informative prior on β3 without a stated source, which can make the posterior reflect the assumed effect rather than the data.
- Reading a credible interval as if it were a frequentist confidence interval. The two have different interpretations and can differ numerically.
- Interpreting posterior mass away from zero on β3 as evidence of a causal effect without a pre-period check. The two-period model does not test pre-trends by itself.
- Reporting posterior summaries without checking MCMC convergence, which can yield unreliable posterior means and intervals.
Frequently asked questions
Does Bayesian DiD still require the parallel-trends assumption?
Yes. The Bayesian framework changes how uncertainty is quantified, not the identification strategy. Parallel trends is still the core assumption: if the groups were diverging before treatment, the posterior treatment effect will be biased regardless of the prior choice.
What prior should I use for the treatment effect?
There is no single default. A weakly informative normal prior centred at zero, scaled to the units of the outcome, is one option when no prior evidence exists, but the scale must be justified. Informative priors should be grounded in published evidence or strong theory. Whatever prior is used, report a sensitivity analysis across alternatives, especially when the number of units is small, because the prior can then dominate the posterior.
How is a Bayesian credible interval different from a frequentist confidence interval?
A 95% credible interval means there is a 95% posterior probability that the true effect lies in that range, given the data and prior. A frequentist 95% confidence interval means that if you repeated the procedure many times, 95% of such intervals would contain the true value. It makes no direct probability statement about a single interval.
When does Bayesian DiD outperform classical DiD?
Bayesian DiD is most useful when the sample is small, when relevant prior evidence exists, or when the decision calls for posterior probabilities rather than p-values. With a large sample and a diffuse prior, the posterior for β3 is driven mainly by the data and should be close to the OLS DiD estimate from the same specification, so comparing the two is a useful check.
Which software supports Bayesian DiD?
Stan (via RStan or CmdStan), PyMC, and brms (an R package providing a formula interface over Stan) are the most common tools. The brms package makes it especially straightforward to specify a DiD regression with Bayesian priors.
Related methods
Sources
Li, F., & Marchand, J. (2023). Bayesian inference for difference-in-differences. Econometrics Journal, 26(3), 509-529.
Open publication referenceBrodersen, K. H., Gallusser, F., Koehler, J., Remy, N., & Scott, S. L. (2015). Inferring causal impact using Bayesian structural time-series models. Annals of Applied Statistics, 9(1), 247-274.
Open DOI reference