SyntheticControlMethods icon indicating copy to clipboard operation
SyntheticControlMethods copied to clipboard

Type Error when using DiffSynth

Open DarioLandwehr opened this issue 2 years ago • 3 comments

Hi, I tried using the DiffSynth class. However, I get a "Type Error: incompatible index of inserted column with frame index" when instantiating it. This occurs both when I am using my own data and when I am using the replication data from Abadie et al. (2015) that you also use in your guide. The code is the exact same as in the example for the replication data. I also tried using the normal Synth on the same datasets wich converges without any errors.

Any suggestions or similar experiences?

DarioLandwehr avatar Jun 02 '23 11:06 DarioLandwehr

I receive the same exact error, haven't figured out a workaround -would really appreciate any guidance here

ew2631 avatar Jun 06 '24 23:06 ew2631

same issues #28

PG408 avatar Oct 27 '24 12:10 PG408

I find the the solution,just modify "difference_data" funtion in DiffSynth class, in main.py code ,blow

        #Compute difference of outcome variable
        temp = modified_dataset.groupby(data.id)[data.outcome_var]
        temp = temp.apply(lambda unit: unit.interpolate(method='linear', limit_direction="both")).diff()
        temp = pd.DataFrame(temp).reset_index()
       
        temp.columns = [data.id, 'index', data.outcome_var]
        temp = temp.set_index('index').sort_index()
        
        modified_dataset[data.outcome_var] = temp[data.outcome_var]
        # modified_dataset[data.outcome_var] = modified_dataset.groupby(data.id)[data.outcome_var].apply(
        #                                     lambda unit: unit.interpolate(method='linear', limit_direction="both")).diff()
        #For covariates
        for col in data.covariates:
            #Fill in missing values using unitwise linear interpolation
            temp2 = modified_dataset.groupby(data.id)[col]
            temp2 = temp2.apply(lambda unit: unit.interpolate(method='linear', limit_direction="both"))
            temp2 = pd.DataFrame(temp2).reset_index()
            temp2.columns = [data.id, 'index', col]
            temp2 = temp2.set_index('index').sort_index()
            modified_dataset[col] = temp2[col]
            # modified_dataset[col] = modified_dataset.groupby(data.id)[col].apply(
            #                         lambda unit: unit.interpolate(method='linear', limit_direction="both"))
            

PG408 avatar Oct 27 '24 14:10 PG408