d2cml-ai / csdid

CSDID
https://d2cml-ai.github.io/csdid/index.html
MIT License
14 stars 4 forks source link

allow_unbalanced_panel = False is not working #24

Open alexanderquispe opened 1 month ago

alexanderquispe commented 1 month ago
from csdid.att_gt import ATTgt 
import pandas as pd 
# Load the CSV file 
file_path = 'C:/Users/Alexander/Documents/GitHub/csdid/data/cohort_2023.csv' 
data = pd.read_csv(file_path)
# Prepare  the data
data['customer_id_numeric'] = data['customer_id'].astype('category').cat.codes 
# Create an instance of the ATTgt class and fit the model 
out = ATTgt(yname="ln_gms",gname="first.treat", idname="customer_id_numeric",        
     tname="time_period", data=data, allow_unbalanced_panel = False).fit(est_method='ipw', bstrap = True) 
# Display the results 
out.summ_attgt().summary2
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
c:\Users\Alexander\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\indexing.py in _validate_tuple_indexer(self, key)
    903             try:
--> 904                 self._validate_key(k, i)
    905             except ValueError as err:

c:\Users\Alexander\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
   1517         else:
-> 1518             raise ValueError(f"Can only index by location with a [{self._valid_types}]")
   1519 

ValueError: Can only index by location with a [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array]

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
C:\Users\ALEXAN~1\AppData\Local\Temp/ipykernel_24432/3877272001.py in <module>
     10 data['customer_id_numeric'] = data['customer_id'].astype('category').cat.codes
     11 # Create an instance of the ATTgt class and fit the model
---> 12 out = ATTgt(yname="ln_gms",gname="first.treat", idname="customer_id_numeric",        
     13      tname="time_period", data=data, allow_unbalanced_panel = False).fit(est_method='ipw', bstrap = True) 
     14 # Display the results

c:\Users\Alexander\anaconda3\envs\tensorflow\lib\site-packages\csdid\att_gt.py in __init__(self, yname, tname, idname, gname, data, control_group, xformla, panel, allow_unbalanced_panel, clustervar, weights_name, anticipation, cband, biters, alp)
...
--> 906                 raise ValueError(
    907                     "Location based indexing can only have "
    908                     f"[{self._valid_types}] types"

ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?4242d70f-e8c8-4f7f-938c-97ed0d0531c4) or open in a [text editor](command:workbench.action.openLargeOutput?4242d70f-e8c8-4f7f-938c-97ed0d0531c4). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...