d2cml-ai / csdid

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

NameError: name 't' is not defined in compute_att_gt.py #11

Closed achinmay17 closed 1 year ago

achinmay17 commented 1 year ago

't' is called in snippet from line 80 in compute_att_gt.py. However, its not defined earlier.

      if not never_treated:
        n1 = data[gname] == 0
        n2 = (data[gname] > (tlist[np.max([t, pret]) + tfac]) + anticipation)
        n3 = np.where(data[gname] != glist[g], True, False)
        row_eval = n1 | n2 & n3
        data = data.assign(C = 1 * row_eval)

I see a commneted line 58 where it was defined (but not commented). If I uncomment that and run it, I get the indexing error on the dataframe.

The issue is only arising when we use control_group = 'notyettreated'.

alexanderquispe commented 1 year ago

Improper Variable Naming in Python Function Creation

Incorrect naming of variables when creating a function in Python.

  1. Testing in Jupyter Book:

    • Originally, tests were being carried out in a Jupyter Book environment using the variables t and g (following the R code). This means that the results obtained in this environment were based on the t and g variables.
  2. Variable renaming in the code:

    • Later, in an attempt to simplify the code, the variable t was renamed to t_i (omitting to rename the variable in some instances).
  3. Difference in results:

    • However, this renaming did not go as expected. The code began to produce results that were different from those obtained previously.
  4. Renaming in the final code:

    • Then, in the final code (outside of the Jupyter Book environment), the variable t was renamed to t_i, which seems to have caused problems in the consistency of the results.
  5. Correction

    • In the end, the solution was to rename the variables from t back to t_i, to avoid the error that the variable is used but was not declared.