From c0c25903139984d8d49209f528c2a13e6b3d1217 Mon Sep 17 00:00:00 2001 From: Julian Blank Date: Tue, 20 Aug 2024 11:21:44 -0700 Subject: [PATCH] Bugfix: Only create aggregate data frame when scale is available --- azcausal/estimators/panel/vdid.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azcausal/estimators/panel/vdid.py b/azcausal/estimators/panel/vdid.py index e52f513..7404ba6 100644 --- a/azcausal/estimators/panel/vdid.py +++ b/azcausal/estimators/panel/vdid.py @@ -358,9 +358,10 @@ def vdid_panel(dx, keys, targets, time, unit, fillna=None, **kwargs): .assign(delta_treat=lambda dx: dx['post_treat'] - dx['pre_treat']) .assign(did=lambda dx: dx['delta_treat'] - dx['delta_contr']) ) - - dte['cum_agg'] = dte['avg_agg'] * dte['scale'] - dte['pct_agg'] = dte['avg_agg'].div(dte['cf'].abs() / 100, axis='index') + if 'scale' in dte: + dte['cum_agg'] = dte['avg_agg'] * dte['scale'] + if 'cf' in dte: + dte['pct_agg'] = dte['avg_agg'].div(dte['cf'].abs() / 100, axis='index') return dte