smmargins.DiDResult¶
- class smmargins.DiDResult(cells: MarginsResult, simple_effects: MarginsResult, did: MarginsResult, joint: MarginsResult)¶
Bundle of results from
Margins.did().Holds the four cell predictions, the two simple effects, the difference-in-differences estimate, and a joint result that contains all three contrasts with their shared covariance.
- Parameters:
cells (MarginsResult) – The four adjusted predictions.
simple_effects (MarginsResult) – Group effect evaluated at each level of the condition.
did (MarginsResult) – The single difference-in-differences estimate.
joint (MarginsResult) – All three contrasts (2 simple effects + DiD) sharing joint vcov, useful if you want to jointly test e.g.
simple_effects = did = 0.
- cells¶
- Type:
- simple_effects¶
- Type:
- did¶
- Type:
- joint¶
- Type:
Examples
Use the bundle to grab whichever piece you want:
res = M.did("group", "preexist_Y", group_levels=["A", "B"], condition_levels=[0, 1]) print(res) # full report (cells + effects + DiD) res.cells.summary() # 4-row table for plotting res.simple_effects.estimate # 2 group-effects, one per Y level res.did.estimate # the single DiD on the response scale res.joint.vcov # 3x3 covariance for joint Wald tests
Runnable smoke test:
>>> import numpy as np, pandas as pd, statsmodels.formula.api as smf >>> from smmargins import Margins >>> rng = np.random.default_rng(0) >>> df = pd.DataFrame({ ... "treat": rng.integers(0, 2, 200), ... "post": rng.integers(0, 2, 200), ... }) >>> df["y"] = (df["treat"] + df["post"] + 0.5 * df["treat"] * df["post"] ... + rng.standard_normal(200)) >>> res = Margins(smf.ols("y ~ treat * post", df).fit()).did("treat", "post") >>> res.cells.estimate.shape (4,) >>> res.simple_effects.estimate.shape (2,) >>> res.did.estimate.shape (1,) >>> res.joint.vcov.shape (3, 3)
- __init__(cells: MarginsResult, simple_effects: MarginsResult, did: MarginsResult, joint: MarginsResult)¶
Methods
__init__(cells, simple_effects, did, joint)summary()Return the full DiD summary as one concatenated DataFrame.