DifferenceInDifferences#
- class causalpy.experiments.diff_in_diff.DifferenceInDifferences[source]#
A class to analyse data from Difference in Difference settings.
Note
There is no pre/post intervention data distinction for DiD, we fit all the data available.
- Parameters:
data (pd.DataFrame) – A pandas dataframe.
formula (str) – A statistical model formula.
time_variable_name (str) – Name of the data column for the time variable.
group_variable_name (str) – Name of the data column for the group variable.
post_treatment_variable_name (str, optional) – Name of the data column indicating post-treatment period. Defaults to “post_treatment”.
model (PyMCModel or RegressorMixin, optional) – A PyMC model for difference in differences. Defaults to None.
Example
>>> import causalpy as cp >>> df = cp.load_data("did") >>> seed = 42 >>> result = cp.DifferenceInDifferences( ... df, ... formula="y ~ 1 + group*post_treatment", ... time_variable_name="t", ... group_variable_name="group", ... model=cp.pymc_models.LinearRegression( ... sample_kwargs={ ... "target_accept": 0.95, ... "random_seed": seed, ... "progressbar": False, ... } ... ), ... )
Methods
DifferenceInDifferences.__init__(data, ...)Generate a decision-ready summary of causal effects.
DifferenceInDifferences.fit(*args, **kwargs)DifferenceInDifferences.get_plot_data(*args, ...)Recover the data of an experiment along with the prediction and causal impact information.
Abstract method for recovering plot data.
Abstract method for recovering plot data.
DifferenceInDifferences.plot(*args, **kwargs)Plot the model.
Ask the model to print its coefficients.
DifferenceInDifferences.summary([round_to])Print summary of main results and model coefficients.
Attributes
idataReturn the InferenceData object of the model.
supports_bayessupports_olslabels- __init__(data, formula, time_variable_name, group_variable_name, post_treatment_variable_name='post_treatment', model=None, **kwargs)[source]#
- classmethod __new__(*args, **kwargs)#