From eed4142e2bcbed4cd1873067101795ffbfcd4e77 Mon Sep 17 00:00:00 2001 From: Stiofain Fordham <17852477+sdfordham@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:50:32 +0000 Subject: [PATCH] Add a method that returns ATT --- pysyncon/base.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pysyncon/base.py b/pysyncon/base.py index fd03ed1..944be7d 100644 --- a/pysyncon/base.py +++ b/pysyncon/base.py @@ -94,7 +94,7 @@ def path_plot( def _gaps(self, time_period: Optional[IsinArg_t] = None) -> pd.Series: """Calculate the gaps (difference between factual - and estimated conterfactual) + and estimated counterfactual) Parameters ---------- @@ -238,6 +238,34 @@ def summary(self, round: int = 3) -> pd.DataFrame: return pd.concat([treated, synthetic, sample_mean], axis=1).round(round) + def att(self, time_period: IsinArg_t) -> dict[str, float]: + """Computes the average treatment effect on the treated unit (ATT) and + the standard error to the value over the chosen time-period. + + Parameters + ---------- + time_period : Iterable | pandas.Series | dict, optional + Time period to compute the ATT over. + + Returns + ------- + dict + A dictionary with the ATT value and the standard error to the ATT. + + Raises + ------ + ValueError + If there is no weight matrix available + """ + if self.W is None: + raise ValueError("No weight matrix available; fit data first.") + gaps = self._gaps(time_period=time_period) + + att = np.mean(gaps) + se = np.std(gaps, ddof=1) / np.sqrt(len(time_period)) + + return {"att": att.item(), "se": se.item()} + class VanillaOptimMixin: @staticmethod