Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing outcome plot for panelview function #581

Merged
merged 52 commits into from
Oct 3, 2024

Conversation

rafimikail
Copy link
Contributor

@rafimikail rafimikail commented Aug 14, 2024

Hi @s3alfisc , this will be the PR for Issue #582 to enhance panelview to be able to do outcome plot.

I still need to finalize this by doing sanity check on the results and might also need to add the run tests in test_visualize.py, I will update you once its complete

@rafimikail rafimikail changed the title Adding outcome plot for panelview function Implementing outcome plot for panelview function Aug 14, 2024
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

Attention: Patch coverage is 92.59259% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyfixest/did/visualize.py 92.59% 4 Missing ⚠️
Flag Coverage Δ
core-tests 77.28% <92.59%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyfixest/did/visualize.py 93.22% <92.59%> (-6.78%) ⬇️

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@s3alfisc
Copy link
Member

Hi @rafimikail , thanks a lot! I have added an example to the DiD notebook =) Looks already quite good! Next steps would be to add docstrings, tests, and make sure that the subsamp and sort_by_cohort arguments work as intended?

@rafimikail
Copy link
Contributor Author

Hi @s3alfisc , i have finished the development, changes i made:

  • Adding option to specify unit for outcome plot
  • Adding xlim and ylim when plotting the outcome plot
  • Fixing the collapse_to_cohort for outcome plot
  • Adding test
  • Adding docstring
  • Adding specify unit and collapse_to_cohort for outcome plot on the documentation

I would appreciate it if you could review this when you have a moment. Thank you!

@s3alfisc
Copy link
Member

Awesome, thank you Rafi! Will review this tomorrow!

@s3alfisc
Copy link
Member

Plots look fabulous at first sight!

@rafimikail
Copy link
Contributor Author

Hi @s3alfisc , i have added it to the docs as well as fixed the code so it passed the ruff when committing, kindly have a check again, Thanks!

f.colorbar(cax) if legend else None
ax.set_xlabel(xlab) if xlab else None
ax.set_ylabel(ylab) if ylab else None
if type == "outcome" and outcome:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we raise an informative error message when a user specifies type = "outcome" but does not provide an outcome variable?

I.e. we could do

if type == "outcome" and not outcome: 
   raise ValueError("You specified ... but ...")

We would then also add a test in test_error_warnings.py

ax.set_xlabel(xlab) if xlab else None
ax.set_ylabel(ylab) if ylab else None
if type == "outcome" and outcome:
if units_to_plot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the units_to_plot argument, I would say that we should not allow subsampling and aggregation, right? Because if a user specifies specific units, does it make sense to still aggregate them / to subsample from them? (I think you could maybe argue for the first?). Still I would rather restrict this behavior.

data_pivot = data_pivot.sample(subsamp)
if collapse_to_cohort:

def get_treatment_start(x: pd.DataFrame) -> pd.Timestamp:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can be more explicit here? E.g. change to

treat_bool = x[treat]
return x.iloc[treat_bool, time].min()

@s3alfisc s3alfisc merged commit 6fc50b4 into py-econometrics:master Oct 3, 2024
1 check was pending
@s3alfisc
Copy link
Member

s3alfisc commented Oct 3, 2024

Hi @rafimikail , lots of confusion about this one, but the main outcome is that it's merged!

@s3alfisc
Copy link
Member

s3alfisc commented Oct 3, 2024

Thank you!

@rafimikail rafimikail deleted the outcome_plot branch December 7, 2024 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants