Skip to content

Commit

Permalink
Merge pull request #11 from schrimpf/fix_amin
Browse files Browse the repository at this point in the history
fix for pandas.aggregate changing name of created variable
  • Loading branch information
bernardodionisi committed Dec 9, 2023
2 parents 63b4bc2 + 3013a73 commit 9e429e5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions differences/tools/panel_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ def __set__(self, instance, data):
)

# for each entity-event_date,
# create the start (amin) and end (amax) of the panel for the corresponding entity
# create the start (_min_time) and end (_max_time) of the panel for the corresponding entity
cohort_data = cohort_data[cohort_info_list].join(
data.groupby(entity_name)[time_name].agg([np.min, np.max])
data
.groupby(entity_name)[time_name]
.agg(['min', 'max'])
.set_axis(labels=['_min_time', '_max_time'], axis=1)
)

# ----------- pre-process cohorts / data -------------------
Expand Down Expand Up @@ -330,7 +333,7 @@ def pre_process_treated_before(

# entities whose event happened BEFORE the start of their time
treated_before = cohort_data.loc[
lambda x: x[cohort_name] <= x["amin"]
lambda x: x[cohort_name] <= x["_min_time"]
].index.unique()

if len(treated_before):
Expand All @@ -357,12 +360,12 @@ def pre_process_treated_after(
"""drops event dates that come after the end of the panel (for the entity)"""

# entities whose event happened AFTER the end of their time
bool_after_end = cohort_data[cohort_name] > cohort_data["amax"]
bool_after_end = cohort_data[cohort_name] > cohort_data["_max_time"]

# shouldn't this be [cohort - anticipation] ?
# line 85: https://github.com/bcallaway11/did/blob/master/R/pre_process_did.R
# bool_after_end = (cohort_data[cohort_name] -
# anticipation > cohort_data['amax'])
# anticipation > cohort_data['_max_time'])

n_entities_after_end = np.sum(bool_after_end) # number of entities
if n_entities_after_end:
Expand Down

0 comments on commit 9e429e5

Please sign in to comment.