Results

class diff_stream.DIDResult[source]

Group-time estimates and their joint covariance.

Inherits tidy, confint, wald_test, summary, summary_json and etable support. aggregate returns event-time, cohort, calendar-time or simple effects. CS additionally retains covariance blocks accounting for estimation of cohort shares; no full unit-by-effect array is retained.

covariate_balance(*, cohort=None, time=None)[source]

Copy saved CS before/after propensity-weight balance diagnostics.

Request balance=True at fitting. Regression-only fits report before weighting; no artificial regression-adjusted covariate sample is defined. Native unbalanced fits report pre/post date strata separately. Baseline pooled SD scales are held fixed after weighting. These are descriptive diagnostics, not tests of parallel trends or a DR identification check.

effective_sample_size()[source]

CS Kish ESS by required comparison stratum, including aggregate contributors.

Sampling weights define treated ESS and regression controls; IPW/DR controls include propensity odds and trimming. Native unbalanced panels report pre/post strata separately. This is not regression-leverage or influence-score ESS. Aggregates retain component ESS, never a pooled ESS.

suppress(min_effective_sample=30)[source]

Copy with low-support CS coefficients and covariance rows/columns as NaN.

Uses the minimum Kish ESS among each coefficient’s required component strata. Existing suppression is retained. No refitting, dropping cells, renormalizing aggregation weights or changing the original fit occurs. Aggregates depending on a suppressed cell are also suppressed. Joint inference must explicitly select unsuppressed coefficients.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

pretrend_test(*, level='auto', horizons=None)[source]

Joint chi-squared Wald test of clean pre-treatment effects.

By default test cohort-time cells on an original CS/SA fit, or horizons on an event-time aggregate. level=”event_time” aggregates an original fit first. Anticipation periods and omitted references are excluded. Singular covariance raises. BJS tests its separate clean-lead fit, requested at fit time with pretrend_leads=L; only pooled event-time tests apply. The returned dictionary lists the exact coefficients, cells and horizons.

plot_event_study(*, horizons=None, alpha=0.05, joint=False, ax=None, title=None, **joint_options)[source]

Plot the event study: each event time’s estimate and confidence interval, the omitted reference period at zero (hollow) and a dashed line after it, as pyfixest’s iplot does. Cohort-time fits are aggregated by event time first; did_dcdh plots placebo l at event time -l - 1 and effect l at l - 1. Needs matplotlib, which is not a dependency (pip install diff-stream[plot]).

Parameters:
  • horizons (list of int, optional) – Event times to plot (default: all estimated).

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted event times (confint(joint=True); reps and seed pass through) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

trend_sensitivity(*, target=None, horizons=None, restriction='relative_magnitudes', M=None, bias=None, monotonicity=None, ci_method=None, alpha=0.05, **options)[source]

Sensitivity of the event study to violations of parallel trends (Rambachan and Roth, 2023; the method of R’s HonestDiD).

Confidence intervals for a post-treatment effect that remain valid when parallel trends fails by up to M, with M measured against the pre-treatment coefficients: by default ("relative_magnitudes") no period-to-period change in the violation after treatment exceeds M times the largest one before it.

Parameters:
  • target (int, "average" or dict, optional) – The effect to bound: an event time (default 0, the first treated period), "average" over every event time after the reference, or weights {event time: weight}.

  • horizons (list of int, optional) – Event times to use (default: all estimated). They must be consecutive on each side of the reference period.

  • restriction ({"relative_magnitudes", "smoothness", "smoothness_relative_magnitudes"}) – "smoothness" bounds the change in the violation’s slope by M (M = 0 allows a linear trend); "smoothness_relative_magnitudes" bounds it by M times the largest such change before treatment.

  • M (float or list of float, optional) – Values of M (M-bar); by default R’s grid for the restriction.

  • bias ({"positive", "negative"}, optional) – Also restrict the sign of the violation after treatment.

  • monotonicity ({"increasing", "decreasing"}, optional) – Also restrict the violation to be monotone.

  • ci_method ({"fixed_length", "conditional", "hybrid_fixed_length", "hybrid_least_favorable"}, optional) – The interval (R’s FLCI, Conditional, C-F, C-LF); R’s default for the restriction.

  • alpha (float, default 0.05) – One minus the coverage.

  • **options – grid_points (default 1000), grid_bounds, simulations (default 1000), seed (default 0), n_threads.

Returns:

TrendSensitivityResult – .table (the robust interval at each M), .original, .breakdown (the largest M at which the effect stays significant), .plot() (needs matplotlib).

placebos()[source]

Separate BJS clean-lead regression result, fitted with pretrend_leads=L.

Available after cleanup and on treatment-effect aggregates. Lead coefficients are pooled WLS regression effects, not group-time ATTs. No joint covariance with the main treatment estimates is estimated.

multiplier_draws(*, keep=None, drop=None, exact_match=False)[source]

Copy saved CS unit-multiplier perturbations (repetitions x effects).

Fit with bootstrap_reps>=2. Draws include share uncertainty after aggregation and the selected CRV0/CRV1 scaling; no data are reread.

multiplier_confint(alpha=0.05, *, keep=None, drop=None, exact_match=False, joint=True, studentization='bootstrap')[source]

CS unit-multiplier intervals, simultaneous by default.

Bootstrap studentization uses the draw IQR and empirical type-1 quantiles, as R did. ‘analytic’ uses the stored analytic standard errors instead. The result’s vcov/se and inherited confint stay analytic. Exactly the keep/drop selection defines the simultaneous family.

cleanup()[source]

Release optional weighted/native unbalanced BJS aggregation files.

Estimates, stored covariance and coefficient tables remain available. Further BJS aggregation requires refitting. Shallow copies made by with_vcov share ownership of these files.

with_vcov(vcov)[source]

Copy using CRV0 or CRV1 (the latter applies G/(G-1) only, G the clusters).

cohort_time()[source]

Coefficient table with cohort/time and weighting/observed/cohort counts.

contributions(kind=None, *, horizons=None, balanced_horizon=None, balance_window=None)[source]

Cell weights, estimates and sample counts for each aggregate.

On an original result, arguments match aggregate(). On an aggregate, call without arguments to inspect its saved contributors. Inspection does not reread BJS aggregation files and works after cleanup().

composition(kind=None, *, horizons=None, balanced_horizon=None, balance_window=None)[source]

Cohort membership, cohort weights and sample totals per aggregate.

observed_unit_periods sums target-cell observations; it is not a count of unique units across dates, nor a treated/control comparison sample.

aggregate(kind='event_time', *, horizons=None, balanced_horizon=None, balance_window=None)[source]

Aggregate by event time, post-treatment cohort, calendar time or overall ATT.

kind is “event_time” (default, an event study), “cohort”, “calendar” or “overall” (one post-treatment ATT). horizons selects event times for every kind; kinds other than “event_time” use only post-treatment cells. CS weights by retained cohort mass; SA/BJS by observed cell mass (unit counts without sampling weights). CS propagates estimated-share uncertainty, and BJS recomputes contrast-specific smart residual/leave-out inference.

Event-time balanced_horizon=E requires supported events 0..E and retains R did’s event-time range [E-(Tmax-Tmin), E]. balance_window=(lo,hi) requires every estimated event in that window in each retained cohort; omitted reference events -(anticipation+1) are exempt. These restrictions balance cohorts, not the identities of observed units. They are applied before horizons.

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', estimator, cells, counts, n_units, _share_cross=None, _share_cov=None, _bjs_inference=None, observed_counts=None, cohort_counts=None, _contributor_table=None, _composition_table=None, _multiplier_draws=None, _multiplier_shares=None, _bjs_placebos=None, _balance_table=None, _ess_table=None, _suppression_mask=None, _suppression_source=None, _internal=None, _periods=None, _display=None, _cluster_count=None)
coef()[source]

The coefficients, as {name: estimate}.

property se

Standard errors, under the current vcov.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

class diff_stream.TwoStageResult[source]

Direct second-stage coefficients, rather than cohort-time estimates.

Selection returns fitted coefficients without changing either regression. No temporary store survives estimation.

support()[source]

Observed cohort/date counts and original-scale weights per coefficient.

contributions()[source]

Support table used by the common pre-treatment Wald helper.

select(horizons)[source]

Select fitted event-time coefficients, keeping their joint covariance.

plot_event_study(*, horizons=None, alpha=0.05, joint=False, ax=None, title=None, **joint_options)[source]

Plot the event study: each event time’s estimate and confidence interval, the omitted reference period at zero (hollow) and a dashed line after it, as pyfixest’s iplot does. Cohort-time fits are aggregated by event time first; did_dcdh plots placebo l at event time -l - 1 and effect l at l - 1. Needs matplotlib, which is not a dependency (pip install diff-stream[plot]).

Parameters:
  • horizons (list of int, optional) – Event times to plot (default: all estimated).

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted event times (confint(joint=True); reps and seed pass through) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

trend_sensitivity(*, target=None, horizons=None, restriction='relative_magnitudes', M=None, bias=None, monotonicity=None, ci_method=None, alpha=0.05, **options)[source]

Sensitivity of the event study to violations of parallel trends (Rambachan and Roth, 2023; the method of R’s HonestDiD).

Confidence intervals for a post-treatment effect that remain valid when parallel trends fails by up to M, with M measured against the pre-treatment coefficients: by default ("relative_magnitudes") no period-to-period change in the violation after treatment exceeds M times the largest one before it.

Parameters:
  • target (int, "average" or dict, optional) – The effect to bound: an event time (default 0, the first treated period), "average" over every event time after the reference, or weights {event time: weight}.

  • horizons (list of int, optional) – Event times to use (default: all estimated). They must be consecutive on each side of the reference period.

  • restriction ({"relative_magnitudes", "smoothness", "smoothness_relative_magnitudes"}) – "smoothness" bounds the change in the violation’s slope by M (M = 0 allows a linear trend); "smoothness_relative_magnitudes" bounds it by M times the largest such change before treatment.

  • M (float or list of float, optional) – Values of M (M-bar); by default R’s grid for the restriction.

  • bias ({"positive", "negative"}, optional) – Also restrict the sign of the violation after treatment.

  • monotonicity ({"increasing", "decreasing"}, optional) – Also restrict the violation to be monotone.

  • ci_method ({"fixed_length", "conditional", "hybrid_fixed_length", "hybrid_least_favorable"}, optional) – The interval (R’s FLCI, Conditional, C-F, C-LF); R’s default for the restriction.

  • alpha (float, default 0.05) – One minus the coverage.

  • **options – grid_points (default 1000), grid_bounds, simulations (default 1000), seed (default 0), n_threads.

Returns:

TrendSensitivityResult – .table (the robust interval at each M), .original, .breakdown (the largest M at which the effect stays significant), .plot() (needs matplotlib).

with_vcov(vcov)[source]

A copy of this result with another of the vcovs computed at fit time: "iid", "hetero", or a clustering given as {"CRV1": var} or "CRV1:var" (likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time with vcov= or cluster=.

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', n_units, _support, _internal=None, _periods=None)
cleanup()[source]

Delete any files the result holds (none here).

coef()[source]

The coefficients, as {name: estimate}.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

property se

Standard errors, under the current vcov.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

class diff_stream.StackedResult[source]

Event-time coefficients of the weighted stacked regression.

select(horizons) reports a subset with its covariance, overall() the average of the post-treatment coefficients, sub_experiments() the stack’s composition and weights, and pretrend_test() tests the leads.

sub_experiments()[source]

One row per sub-experiment: its cohort, units and corrective weights.

overall(horizons=None)[source]

The equally weighted average of post-treatment event-time effects.

horizons selects the event times averaged (default: every fitted event time from 0 on).

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', n_units, _support, _internal=None, _periods=None, _sub_experiments=None)
cleanup()[source]

Delete any files the result holds (none here).

coef()[source]

The coefficients, as {name: estimate}.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

contributions()[source]

Support table used by the common pre-treatment Wald helper.

plot_event_study(*, horizons=None, alpha=0.05, joint=False, ax=None, title=None, **joint_options)[source]

Plot the event study: each event time’s estimate and confidence interval, the omitted reference period at zero (hollow) and a dashed line after it, as pyfixest’s iplot does. Cohort-time fits are aggregated by event time first; did_dcdh plots placebo l at event time -l - 1 and effect l at l - 1. Needs matplotlib, which is not a dependency (pip install diff-stream[plot]).

Parameters:
  • horizons (list of int, optional) – Event times to plot (default: all estimated).

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted event times (confint(joint=True); reps and seed pass through) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

property se

Standard errors, under the current vcov.

select(horizons)[source]

Select fitted event-time coefficients, keeping their joint covariance.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

support()[source]

Observed cohort/date counts and original-scale weights per coefficient.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

trend_sensitivity(*, target=None, horizons=None, restriction='relative_magnitudes', M=None, bias=None, monotonicity=None, ci_method=None, alpha=0.05, **options)[source]

Sensitivity of the event study to violations of parallel trends (Rambachan and Roth, 2023; the method of R’s HonestDiD).

Confidence intervals for a post-treatment effect that remain valid when parallel trends fails by up to M, with M measured against the pre-treatment coefficients: by default ("relative_magnitudes") no period-to-period change in the violation after treatment exceeds M times the largest one before it.

Parameters:
  • target (int, "average" or dict, optional) – The effect to bound: an event time (default 0, the first treated period), "average" over every event time after the reference, or weights {event time: weight}.

  • horizons (list of int, optional) – Event times to use (default: all estimated). They must be consecutive on each side of the reference period.

  • restriction ({"relative_magnitudes", "smoothness", "smoothness_relative_magnitudes"}) – "smoothness" bounds the change in the violation’s slope by M (M = 0 allows a linear trend); "smoothness_relative_magnitudes" bounds it by M times the largest such change before treatment.

  • M (float or list of float, optional) – Values of M (M-bar); by default R’s grid for the restriction.

  • bias ({"positive", "negative"}, optional) – Also restrict the sign of the violation after treatment.

  • monotonicity ({"increasing", "decreasing"}, optional) – Also restrict the violation to be monotone.

  • ci_method ({"fixed_length", "conditional", "hybrid_fixed_length", "hybrid_least_favorable"}, optional) – The interval (R’s FLCI, Conditional, C-F, C-LF); R’s default for the restriction.

  • alpha (float, default 0.05) – One minus the coverage.

  • **options – grid_points (default 1000), grid_bounds, simulations (default 1000), seed (default 0), n_threads.

Returns:

TrendSensitivityResult – .table (the robust interval at each M), .original, .breakdown (the largest M at which the effect stays significant), .plot() (needs matplotlib).

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

with_vcov(vcov)[source]

A copy of this result with another of the vcovs computed at fit time: "iid", "hetero", or a clustering given as {"CRV1": var} or "CRV1:var" (likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time with vcov= or cluster=.

class diff_stream.DoseResponseResult[source]

Dose-response effects of a continuous treatment.

The coefficients are the overall ATT (the effect of being treated, at the doses received) and the overall ACRT (the average causal response, the derivative of ATT(d) averaged over the treated doses), as contdid reports them. dose_response() gives the curves ATT(d) and ACRT(d); aggregate() event studies and other aggregations of the binarized ATT or of the ACRT; cohort_time() the cohort-period estimates.

dose_response(target='level', dose=None, *, alpha=0.05, uniform=False)[source]

ATT(d) (target=”level”) or ACRT(d) (target=”slope”) over doses.

dose defaults to the grid of the fit (dose_grid). The curve averages the post-treatment cohort-period curves with the weights of the overall effects. Intervals are pointwise, from the analytic standard errors; with uniform=True they are simultaneous over the doses, from the multiplier bootstrap (fit with multiplier_bootstrap_reps), studentized by the draws’ interquartile range as R’s contdid does.

trend_sensitivity(**options)[source]

Not available for continuous treatments: the sensitivity analysis (Rambachan and Roth, 2023) is defined for a binary event study.

aggregate(kind='event_time', *, target='level', **options)[source]

Aggregate the binarized ATT (target=”level”) or the ACRT (target=”slope”).

kind and the options are those of DIDResult.aggregate. The event study of the ACRT is contdid’s aggregation="eventstudy", target_parameter="slope"; that of the ATT is the Callaway-Sant’Anna event study of being treated.

cohort_time(target='level')[source]

The cohort-period binarized ATT or ACRT, with standard errors.

with_vcov(vcov)[source]

A copy of this result with another of the vcovs computed at fit time: "iid", "hetero", or a clustering given as {"CRV1": var} or "CRV1:var" (likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time with vcov= or cluster=.

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', n_units, _att, _acrt, _basis, _grid, _cells, _weights, _theta, _theta_cov, _theta_draws=None, _internal=None, _periods=None, _cluster_count=None)
cleanup()[source]

Delete any files the result holds (none here).

coef()[source]

The coefficients, as {name: estimate}.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

plot_event_study(keep=None, *, reference=-1, alpha=0.05, joint=False, ax=None, title=None, drop=None, exact_match=False, **joint_options)[source]

Plot an event study: the coefficients named <variable>::<event time> (as i(event_time, ref=-1) names them) against their event times, with their confidence intervals, the omitted reference period at zero, and a dashed line after it (pyfixest’s iplot). Needs matplotlib (not a dependency: pip install hdfe-stream[plot]).

Parameters:
  • keep – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • drop – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • exact_match – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • reference (int or None, default -1) – The omitted reference event time; None draws none.

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted coefficients (confint’s joint=True, with its reps and seed in joint_options) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

property se

Standard errors, under the current vcov.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

class diff_stream.DCDHResult[source]

Dynamic effects of a treatment that may switch on and off and take several values.

The coefficients are effect::l (the effect l periods after the first switch), placebo::l and average_total_effect, with their joint covariance. pretrend_test() tests that the placebos are jointly zero, effects_equal_test() that the effects are equal, and switchers() lists the groups behind each estimate.

switchers()[source]

Switching groups (and their weight) behind each coefficient, by direction.

pretrend_test()[source]

Wald test that the placebos are jointly zero.

plot_event_study(*, horizons=None, alpha=0.05, joint=False, ax=None, title=None, **joint_options)[source]

Plot the event study: each event time’s estimate and confidence interval, the omitted reference period at zero (hollow) and a dashed line after it, as pyfixest’s iplot does. Cohort-time fits are aggregated by event time first; did_dcdh plots placebo l at event time -l - 1 and effect l at l - 1. Needs matplotlib, which is not a dependency (pip install diff-stream[plot]).

Parameters:
  • horizons (list of int, optional) – Event times to plot (default: all estimated).

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted event times (confint(joint=True); reps and seed pass through) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

trend_sensitivity(*, target=None, horizons=None, restriction='relative_magnitudes', M=None, bias=None, monotonicity=None, ci_method=None, alpha=0.05, **options)[source]

Sensitivity of the event study to violations of parallel trends (Rambachan and Roth, 2023; the method of R’s HonestDiD).

Confidence intervals for a post-treatment effect that remain valid when parallel trends fails by up to M, with M measured against the pre-treatment coefficients: by default ("relative_magnitudes") no period-to-period change in the violation after treatment exceeds M times the largest one before it.

Parameters:
  • target (int, "average" or dict, optional) – The effect to bound: an event time (default 0, the first treated period), "average" over every event time after the reference, or weights {event time: weight}.

  • horizons (list of int, optional) – Event times to use (default: all estimated). They must be consecutive on each side of the reference period.

  • restriction ({"relative_magnitudes", "smoothness", "smoothness_relative_magnitudes"}) – "smoothness" bounds the change in the violation’s slope by M (M = 0 allows a linear trend); "smoothness_relative_magnitudes" bounds it by M times the largest such change before treatment.

  • M (float or list of float, optional) – Values of M (M-bar); by default R’s grid for the restriction.

  • bias ({"positive", "negative"}, optional) – Also restrict the sign of the violation after treatment.

  • monotonicity ({"increasing", "decreasing"}, optional) – Also restrict the violation to be monotone.

  • ci_method ({"fixed_length", "conditional", "hybrid_fixed_length", "hybrid_least_favorable"}, optional) – The interval (R’s FLCI, Conditional, C-F, C-LF); R’s default for the restriction.

  • alpha (float, default 0.05) – One minus the coverage.

  • **options – grid_points (default 1000), grid_bounds, simulations (default 1000), seed (default 0), n_threads.

Returns:

TrendSensitivityResult – .table (the robust interval at each M), .original, .breakdown (the largest M at which the effect stays significant), .plot() (needs matplotlib).

effects_equal_test()[source]

Wald test that the effects are all equal (did_multiplegt_dyn’s effects_equal).

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', n_units, _switchers, _internal=None)
cleanup()[source]

Delete any files the result holds (none here).

coef()[source]

The coefficients, as {name: estimate}.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

property se

Standard errors, under the current vcov.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

with_vcov(vcov)[source]

A copy of this result with another of the vcovs computed at fit time: "iid", "hetero", or a clustering given as {"CRV1": var} or "CRV1:var" (likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time with vcov= or cluster=.

class diff_stream.BJSPlaceboResult[source]

Pooled clean lead coefficients from a separate untreated-sample WLS fit.

Standard coefficient/interval/Wald methods are inherited from the family. There is no estimated joint covariance with the main treatment effects.

support()[source]

Observed cohort/date support and original-scale weight totals.

trend_sensitivity(**options)[source]

Not available: the leads have no covariance with the treatment effects.

pretrend_test(*, level='auto', horizons=None)[source]

Joint clean-lead Wald test; horizon selection does not refit the model.

with_vcov(vcov)[source]

A copy of this result with another of the vcovs computed at fit time: "iid", "hetero", or a clustering given as {"CRV1": var} or "CRV1:var" (likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time with vcov= or cluster=.

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', n_units, _support, _internal=None, _periods=None)
cleanup()[source]

Delete any files the result holds (none here).

coef()[source]

The coefficients, as {name: estimate}.

confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]

Confidence intervals, one coefficient at a time or simultaneous.

Pointwise intervals use the t distribution with df_t degrees of freedom, or the normal for GLMs, as tidy does. With joint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’s confint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).

Parameters:
  • alpha (float, default 0.05) – One minus the coverage.

  • keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a keep pattern, in the order of the patterns (all, by default), less those matching a drop pattern. A joint interval covers exactly these.

  • exact_match (bool, default False) – Match names exactly instead of as regular expressions.

  • joint (bool, default False) – Simultaneous intervals.

  • reps (int, default 10000) – Draws for the joint critical value.

  • seed (int, optional) – Seed for those draws.

Returns:

polars.DataFrame – Coefficient and the lower and upper bounds, in columns named by their percentiles ("2.5%", "97.5%").

plot_event_study(keep=None, *, reference=-1, alpha=0.05, joint=False, ax=None, title=None, drop=None, exact_match=False, **joint_options)[source]

Plot an event study: the coefficients named <variable>::<event time> (as i(event_time, ref=-1) names them) against their event times, with their confidence intervals, the omitted reference period at zero, and a dashed line after it (pyfixest’s iplot). Needs matplotlib (not a dependency: pip install hdfe-stream[plot]).

Parameters:
  • keep – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • drop – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • exact_match – Select the coefficients, as in confint (by default every one named <variable>::<event time>, from one variable).

  • reference (int or None, default -1) – The omitted reference event time; None draws none.

  • alpha (float, default 0.05) – One minus the coverage.

  • joint (bool, default False) – Simultaneous intervals over the plotted coefficients (confint’s joint=True, with its reps and seed in joint_options) instead of pointwise ones.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

property se

Standard errors, under the current vcov.

summary(logger=None, level=20)[source]

Print the report, or write it to logger (one record, at level).

summary_dict(coefficients=False)[source]

The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent. coefficients=True adds the tidy() table as a list of row dicts.

summary_json(path=None, indent=2, coefficients=False)[source]

The model-level information of summary() as a JSON string (see summary_dict); with path, also written there as UTF-8. Reload with json.loads or json.load.

summary_text()[source]

The summary() report as a string.

tidy()[source]

Coefficient table. p-values use the t distribution with df_t degrees of freedom, or the normal for GLMs, as in pyfixest.

to_pyfixest()[source]

A pyfixest Feols (Feiv for IV) view of this result, for pf.etable, pf.summary, pf.coefplot and pf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, and predict is this result’s own predict.

wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]

Wald test of the linear hypothesis R beta = q, under the current vcov (see with_vcov).

By default the hypothesis is that every coefficient is zero; keep and drop narrow it to some of them (the coefficients of an event study’s leads, say), and R and q state any other.

The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and df_t degrees of freedom, so that for one coefficient the p-value is the one tidy reports; W, to the chi-squared with m. Two differences from pyfixest’s wald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones that df_t does not.

Parameters:
  • R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of coefnames; a 1-d array is one restriction.

  • q (float or array-like, optional) – The m right-hand sides; zero by default.

  • distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose tidy p-values are normal.

  • keep – Without R: test that the coefficients they select are zero (or q), as in confint.

  • drop – Without R: test that the coefficients they select are zero (or q), as in confint.

  • exact_match – Without R: test that the coefficients they select are zero (or q), as in confint.

Returns:

dict – statistic (F or W), pvalue, df1 (m), df2 (df_t for F, None for chi-squared) and distribution.

class diff_stream.BaconResult[source]

Descriptive TWFE decomposition; no separate causal ATT or standard errors.

comparisons()[source]

Two-block comparisons, or full-period dyads when covariate-adjusted.

tidy()[source]

Alias for comparisons().

within_timing()[source]

Within-timing component of a covariate-adjusted decomposition.

The estimate is undefined/null when its weight is zero. Contributions plus the contributions in comparisons() reconstruct the target TWFE.

summary()[source]

Weights, within-type weighted estimates and contributions by type.

summary_json(path=None, *, comparisons=False)[source]

Return JSON and optionally save it to a file.

__init__(*, fml, depvar, twfe_estimate, decomposed_estimate, n_units, n_obs, diagnostics, _table, within_weight=0.0, within_estimate=None, within_contribution=0.0)
class diff_stream.TWFEWeightResult[source]

Descriptive feTR weights and sensitivity summaries; no ATT inference.

Cell storage is optional (keep_cells=True). Use cleanup() or a context manager to release retained temporary files. Reduced summaries survive it.

summary()[source]

Reduced sign counts/sums, weight extrema and population shares.

sensitivity()[source]

Two published sensitivity thresholds with explicit status/conventions.

cells()[source]

Lazy, disk-backed cell table; valid until cleanup().

iter_cells(batch_rows=32768)[source]

Bounded cell frames (ordering across partitions is unspecified).

write_cells(path)[source]

Stream cells to a caller-owned Parquet file that survives cleanup().

__init__(*, fml, twfe_estimate, n_units, n_obs, diagnostics, _summary, _sensitivity, _run=None, _path=None)
class diff_stream.RefitBootstrapResult[source]

Point estimates, refit draws and pointwise bootstrap inference.

No source or fit scratch survives. Failed attempts remain in the ledger and are never redrawn. Inference on successful draws requires allow_incomplete when any attempt failed; such inference is conditional on successful fits.

With original_se (the fit’s standard errors) and _se_draws (each refit’s, reps by coefficients), studentized (bootstrap-t) intervals are available too. A draw whose estimates are finite but whose standard errors are not counts as a failed draw for those intervals.

property se

Sample SD of refitted estimates; refuses incomplete bootstrap runs.

confint(alpha=0.05, *, method='percentile', allow_incomplete=False)[source]

Pointwise percentile/type-7, basic, uncorrected normal, studentized or symmetric studentized intervals.

Normal intervals are point estimate +/- normal critical value times bootstrap SD, without boot.ci’s normal bias correction. Studentized (bootstrap-t) intervals use t* = (b* - b) / se* from each refit: [b - q(1 - alpha/2) se, b - q(alpha/2) se], with q the quantiles of t* and se the fit’s standard error; symmetric ones are b +/- q|t*|(1 - alpha) se. Both need the refits’ standard errors. No simultaneous or BCa intervals are supplied.

draws()[source]

Copy attempted estimates; failed rows are NaN for every coefficient.

standard_error_draws()[source]

Copy each refit’s standard errors (None if the bootstrap kept none).

summary()[source]

Run/sample/failure diagnostics; inference is available through tidy().

__init__(*, fml, estimator, coefnames, beta, diagnostics, _draws, _failures, _warnings, original_se=None, _se_draws=None)
class diff_stream.TrendSensitivityResult[source]

Confidence intervals for a post-treatment effect under restrictions on how far parallel trends may fail, one per value of M.

Attributes:
  • table (polars.DataFrame) – M, lower and upper: the robust confidence interval at each value of M (M-bar for the relative-magnitudes restrictions).

  • original (dict) – The usual interval under exact parallel trends: estimate, se, lower, upper.

  • restriction, bias, monotonicity, ci_method (str or None) – The restriction on the violations and the interval, as passed.

  • alpha (float) – One minus the coverage.

  • target (numpy.ndarray) – The weights l on the post-treatment coefficients: the target is l’tau_post.

  • n_pre, n_post (int) – Pre- and post-treatment coefficients used.

  • pre, post (list) – Their labels (event times or coefficient names), when known.

  • r_names (dict) – The R package’s names for the restriction (Delta) and the interval (method), for comparison with its output.

  • diagnostics (dict) – Grid size, the grid’s bounds for each M and whether it was extended.

property M

The values of M, in order.

property breakdown

The largest M in the grid up to which every robust interval excludes zero: the effect stays significant for violations up to this size. None when the interval at the smallest M already includes zero. It is read off the grid of M values; a finer grid refines it.

summary_dict()[source]

The result as plain Python types (JSON-safe).

summary_text()[source]

A plain-text report.

plot(ax=None, *, title=None)[source]

The robust intervals against M, with the original interval at the left, as in R’s createSensitivityPlot. Needs matplotlib (not a dependency of this package: pip install hdfe-stream[plot]). Draws on ax if given; returns the figure.

__init__(table, original, restriction, ci_method, alpha, target, n_pre, n_post, bias=None, monotonicity=None, pre=<factory>, post=<factory>, r_names=<factory>, diagnostics=<factory>, _grid_accept=<factory>)
classmethod __new__(*args, **kwargs)
exception diff_stream.LowEffectiveSampleWarning[source]

A CS comparison relies on a low effective treated/control sample.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception diff_stream.ReferenceWindowWarning[source]

Estimation uses only dates before the last reference cohort is affected.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception diff_stream.UnimputedObservationsWarning[source]

BJS dropped treated observations whose untreated outcome cannot be imputed.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception diff_stream.ExperimentalWarning[source]

A diff-stream fit uses a method its authors have not developed.

It subclasses hdfe_stream.ExperimentalWarning: filter this class to silence diff-stream’s experimental warnings, or that one for every package built on hdfe-stream.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception diff_stream.ContinuousBaselineWarning[source]

did_dcdh’s standard errors with a continuous first-period treatment may be too small, as the authors note for their continuous option.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception diff_stream.BootstrapFailureWarning[source]

Some refits of a bootstrap failed; inference on the rest needs explicit acknowledgment.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)