Skip to content

Commit

Permalink
Add a method that returns ATT
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfordham committed Nov 19, 2023
1 parent 07f92a9 commit eed4142
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pysyncon/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eed4142

Please sign in to comment.