Skip to content

Update difference in difference docs to show TWFE formulation #482

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

Merged
merged 12 commits into from
Jun 6, 2025

Conversation

drbenvincent
Copy link
Collaborator

@drbenvincent drbenvincent commented May 30, 2025

Previously there were 2 models presented. The first was a classic 2x2 fit on just the years immediately pre and post intervention. The second was a fit to all the years worth of data, but the model also added a linear trend term.

We now have a new model (model 2) squeezed in between. This corresponds to the 2x2 DID model but with all years worth of data included. This is also what they show in Mastering Metrics (page 188).

Model 4 is also new and is the two way fixed effects formulation of DID.

NOTE: The fit of model 1 is still problematic - it has divergences. I think this is most likely because the scale of the data is quite far off what is assumed by the (built-in) priors in the linear regression pymc model. I will come back to this once we've got the ability to add custom priors (see #387), and this might actually happen sooner rather than later. So the plan is to come back and fix Model 1 and expand the summary discussion which compares the models.


📚 Documentation preview 📚: https://causalpy--482.org.readthedocs.build/en/482/

@drbenvincent drbenvincent added the documentation Improvements or additions to documentation label May 30, 2025
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.40%. Comparing base (bb7c2bb) to head (ccaf174).
Report is 21 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #482   +/-   ##
=======================================
  Coverage   94.40%   94.40%           
=======================================
  Files          29       29           
  Lines        2075     2075           
=======================================
  Hits         1959     1959           
  Misses        116      116           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@drbenvincent drbenvincent changed the title Updates to the difference in differences docs page (banking example) Update difference in difference docs to show TWFE formulation May 30, 2025
@ostojanovic ostojanovic self-requested a review June 5, 2025 17:08
Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:18Z
----------------------------------------------------------------

I'm not sure if this is not rendering properly in my browser, but I still see {cite:t} and {cite:p} throughout the text.


drbenvincent commented on 2025-06-06T09:54:14Z
----------------------------------------------------------------

Where did you see that? In a local build of the docs? In the remote build on this PR it renders ok https://causalpy--482.org.readthedocs.build/en/482/notebooks/did_pymc_banks.html and on my local build of the docs. You might need to run this? pip install 'causalpy[docs]'

EDIT: Oh, yes if you were looking at reviewnb that does not render the notebook properly, it's relatively crude and doesn't render the citations and references like you get when running it through sphinx

ostojanovic commented on 2025-06-06T17:14:35Z
----------------------------------------------------------------

Yes, it's the ReviewNB issue.

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:19Z
----------------------------------------------------------------

Is this the original paper: https://www.journals.uchicago.edu/doi/10.1086/649603 ? I know you cite the book, but maybe we should also have a link to the original paper? Feel free to do it however you see fit.


drbenvincent commented on 2025-06-06T09:57:19Z
----------------------------------------------------------------

Yep, the existing reference does cite that paper. It also appears in the reference section. So I think there's something wrong with whatever you were looking at?

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:20Z
----------------------------------------------------------------

there's a typo in baseline


drbenvincent commented on 2025-06-06T10:00:37Z
----------------------------------------------------------------

thanks

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:20Z
----------------------------------------------------------------

I think you should have output here, it would make sense for a reader to see the pairplot


drbenvincent commented on 2025-06-06T10:24:13Z
----------------------------------------------------------------

Originally I opted to not show this because it's a bit of a side show and will be fixed in the near future. But now I've displayed the pair plot, but have it collapsed by default, but users will be able to click to view. (viewable only in a proper render of the docs, not here on reviewnb)

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:21Z
----------------------------------------------------------------

Btw, I see these deprecation warnings throughout the notebook. I think we should either suppress them or write a sentence or two on why they happen, so that someone reading the documentation knows why we're ignoring them.


drbenvincent commented on 2025-06-06T10:28:03Z
----------------------------------------------------------------

Sure thing. Running the notebook again just now, those DeprecationWarning's have disappeared. There was a remaining FutureWarning which I've suppressed.

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:22Z
----------------------------------------------------------------

Is the text supposed to be this large?


drbenvincent commented on 2025-06-06T10:29:09Z
----------------------------------------------------------------

This is some stupid rendering of reviewnb - it's not like this in local or remote builds of the docs

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:23Z
----------------------------------------------------------------

I think it would be good to have one or two more sentences on what the two-way fixed effects (TWFE) formulation is, maybe with a link to an article or a paper? Or maybe we have more documentation on it here, in causalpy repository. You already have good technical details, but this would help readers get a more general sense of why you’d want to use it in the first place.

Again, I'm not sure if it's just not rendering properly for me, but I still see the formula as \textcolorsalmon(unit fixed effect)


drbenvincent commented on 2025-06-06T11:08:34Z
----------------------------------------------------------------

Same thing about the formatting and reviewnb.

Good idea - I've added a bite more info and some references. We will likely revisit this topic in more detail (either in this notebook, or in more general docs information) because the DID literature is vast.

Copy link

review-notebook-app bot commented Jun 5, 2025

View / edit / reply to this conversation on ReviewNB

ostojanovic commented on 2025-06-05T18:34:24Z
----------------------------------------------------------------

There's nothing in references. I'm not sure whether you prefer to have links for each term or a bibliography at the end. Either way, it's fine by me, but then maybe you can just delete the headline here if it's not needed.


drbenvincent commented on 2025-06-06T10:35:48Z
----------------------------------------------------------------

This will be reviewnb again.

Copy link
Contributor

@ostojanovic ostojanovic left a comment

Choose a reason for hiding this comment

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

@drbenvincent This looks good! I have made a few comments, mostly formatting and text. Tell me what you think, and then it's ready to go.

Copy link
Collaborator Author

Where did you see that? In a local build of the docs? In the remote build on this PR it renders ok https://causalpy--482.org.readthedocs.build/en/482/notebooks/did_pymc_banks.html


View entire conversation on ReviewNB

Copy link
Collaborator Author

Yep, the existing reference does cite that paper. It also appears in the reference section. So I think there's something wrong with whatever you were looking at?


View entire conversation on ReviewNB

Copy link
Collaborator Author

thanks


View entire conversation on ReviewNB

Copy link
Collaborator Author

Originally I opted to not show this because it's a bit of a side show and will be fixed in the near future. But now I've displayed the pair plot, but have it collapsed by default, but users will be able to click to view. (viewable only in a proper render of the docs, not here on reviewnb)


View entire conversation on ReviewNB

Copy link
Collaborator Author

Sure thing. Running the notebook again just now, those DeprecationWarning's have disappeared. There was a remaining FutureWarning which I've suppressed.


View entire conversation on ReviewNB

Copy link
Collaborator Author

This is some stupid rendering of reviewnb - it's not like this in local or remote builds of the docs


View entire conversation on ReviewNB

Copy link
Collaborator Author

This will be reviewnb again.


View entire conversation on ReviewNB

Copy link
Collaborator Author

Same thing about the formatting and reviewnb.

Good idea - I've added a bite more info and some references. We will likely revisit this topic in more detail (either in this notebook, or in more general docs information) because the DID literature is vast.


View entire conversation on ReviewNB

@drbenvincent
Copy link
Collaborator Author

Thanks for the review @ostojanovic. Many of the issues related to formatting - let me just clarify about that. ReviewNB gives some kind of rendering of the ipynb file. However this is not the same as rendering the docs through sphinx, so it will often bear little resemblance to what the docs will actually look like.

ReviewNB is kind of useful, but when evaluating formatting issues I would take a look at the remote build of the docs. We've got a bot which auto adds a link to remote docs in the initial PR description. Look for the 📚 Documentation preview 📚 bit.

@drbenvincent drbenvincent requested a review from ostojanovic June 6, 2025 11:36
Copy link
Contributor

Yes, it's the ReviewNB issue.


View entire conversation on ReviewNB

Copy link
Contributor

@ostojanovic ostojanovic left a comment

Choose a reason for hiding this comment

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

I think this is good to go!

@ostojanovic ostojanovic merged commit a626c1e into main Jun 6, 2025
9 checks passed
@drbenvincent drbenvincent deleted the did-banks branch June 6, 2025 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants