Skip to content

#890 - Show how to replicate Stata results #897

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 4 commits into from
May 10, 2025

Conversation

jestover
Copy link
Contributor

@jestover jestover commented May 9, 2025

.qmd file showing how to replicate common Stata results in PyFixest.

Note: I ran each part in both Stata and PyFixest and got the same results everywhere except for fit4 where I show how to get HC3 standard errors. For some reason the HC3 errors in PyFixest and Stata do not match. I haven't had a chance to try to figure out why though.

If you know why, let me know and I can update the example. If not, I can try to figure it out at a later date. In the meantime we can remove that section or add a note that the HC3 standard errors do not match.

.qmd file showing how to replicate common Stata results in PyFixest.

Note: I ran each part in both Stata and PyFixest and got the same results everywhere except for `fit4` where I show how to get HC3 standard errors.  For some reason the HC3 errors in PyFixest and Stata do not match.  I haven't had a chance to try to figure out why though.

If you know why, let me know and I can update the example.  If not, I can try to figure it out at a later date.  In the meantime we can remove that section or add a note that the HC3 standard errors do not match.
Copy link

codecov bot commented May 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Flag Coverage Δ
core-tests 80.35% <ø> (ø)
tests-extended ?
tests-vs-r 47.10% <ø> (ø)

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

see 6 files with indirect coverage changes

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

@s3alfisc
Copy link
Member

s3alfisc commented May 9, 2025

For some reason the HC3 errors in PyFixest and Stata do not match. I haven't had a chance to try to figure out why though.

This is just a suspicion, but it might be that we might have to set ssc(adj = False, cluster_adj = True) for HC3 - this seems to be the canonical correction. Snippet below from the Zeileis at al Various Versatile Covariances paper:
image

If that is it, I'd say we update the PR, if not, I would leave it in and just state that HC3 does not match. Best to be transparent I think?

@s3alfisc
Copy link
Member

s3alfisc commented May 9, 2025

General comment on the PR - looks very good, thanks! Do you think it would be a lot of work to add the Stata output to the code chunk as commented out text? So that readers could directly compare the Stata and R outputs?

@s3alfisc
Copy link
Member

s3alfisc commented May 9, 2025

pre-commit.ci autofix

@s3alfisc
Copy link
Member

s3alfisc commented May 9, 2025

@all-contributors please add @jestover for docs

Copy link
Contributor

@s3alfisc

I've put up a pull request to add @jestover! 🎉

pre-commit-ci bot and others added 2 commits May 9, 2025 19:37
You were correct about the HC3 needing ssc(adj = False)!  Also, I liked the idea about adding the Stata output, so I have done that as well.
@jestover
Copy link
Contributor Author

You were correct on HC3 correction, so that is fixed and I have added the Stata output which should make it so people can follow along without having to replicate everything themselves.

@s3alfisc
Copy link
Member

pre-commit.ci autofix

Copy link
Member

@s3alfisc s3alfisc left a comment

Choose a reason for hiding this comment

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

Perfect, looks great. Thanks so much @jestover!

which includes a section on
[Coming from Stata](https://aeturrell.github.io/coding-for-economists/coming-from-stata.html),
or [Tidy Finance with Python](https://www.tidy-finance.org/python/) by Christopher
Scheuch, Stefan Voigt, Patrick Weiss, and Christoph Frey.
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 could link the stata2r project here as well and note that fixest syntax almost exaclty matches pyfixest?

@s3alfisc s3alfisc merged commit 3b8bde1 into py-econometrics:master May 10, 2025
5 checks passed
@s3alfisc
Copy link
Member

Looks great, link here: https://py-econometrics.github.io/pyfixest/stata-2-pyfixest.html =)

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