Skip to content

DID: Prettier and Unified Coefficient Names for DiD Methods #407

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

Open
s3alfisc opened this issue Apr 28, 2024 · 4 comments · May be fixed by #838
Open

DID: Prettier and Unified Coefficient Names for DiD Methods #407

s3alfisc opened this issue Apr 28, 2024 · 4 comments · May be fixed by #838
Assignees
Labels
good first issue Good for newcomers

Comments

@s3alfisc
Copy link
Member

s3alfisc commented Apr 28, 2024

Context

Currently, the coefficient names of the DiD methods follow formulaic standard naming, which is very verbose.

Here is an example:

import pyfixest as pf
fit = pf.feols("Y ~ i(f1, X1, ref = 1)", data = pf.get_data())
fit.coef().head()
# C(f1, contr.treatment(base=1))[T.0.0]:X1   -1.069505
# C(f1, contr.treatment(base=1))[T.2.0]:X1   -1.803860
# C(f1, contr.treatment(base=1))[T.3.0]:X1   -1.529129
# C(f1, contr.treatment(base=1))[T.4.0]:X1   -2.039220

The lpdid function does better:

import pandas as pd
from pyfixest.did.estimation import lpdid, did2s

url = "https://raw.githubusercontent.com/s3alfisc/pyfixest/master/pyfixest/did/data/df_het.csv"
df_het = pd.read_csv(url)

lpdid_df = lpdid(
    df_het,
    yname="dep_var",
    idname="unit",
    tname="year",
    gname="g",
    vcov={"CRV1": "state"},
    pre_window=-20,
    post_window=20,
    att=False
)

lpdid_df.tidy().head()

image

while did2s produces

fit_did2s = did2s(
    df_het,
    yname="dep_var",
    first_stage="~ 0 | unit + year",
    second_stage="~i(rel_year, ref=-1.0)",
    treatment="treat",
    cluster="state",
)

fit_did2s.tidy().head()

image

For ATTs, we get

image

To Do

  • Rename the regression coefficients from DID models (event_study, DID2s, lpdid), e.g. rename C(f1, contr.treatment(base=1))[T.0.0]:X1 to f1::0::X1, etc.
@s3alfisc s3alfisc added the good first issue Good for newcomers label Apr 28, 2024
@s3alfisc s3alfisc changed the title Prettier and Unified Coefficient Names for DiD Methods DID: Prettier and Unified Coefficient Names for DiD Methods May 30, 2024
@asteves
Copy link
Contributor

asteves commented Jun 19, 2024

I can take this.

@s3alfisc
Copy link
Member Author

Very cool! I've assigned this to you =) Let me know if I can help you in any way!

@escherpf
Copy link
Contributor

escherpf commented Feb 7, 2025

@s3alfisc: this would indeed be a nice enhancement. I'm currently having difficulty applying the delta method with these event study coefficient names in the marginaleffects package (it's obviously also partly an issue with marginaleffects).

@s3alfisc
Copy link
Member Author

s3alfisc commented Feb 8, 2025

What's the exact problem with marginal effects? Always curious to see what people actually do with PyFixest + marginal effects =)

Does it help if you rename the event study coefs with the helper function we've set up for it? You can use if eg as

from pyfixest.report.utils import rename_event_study_coefs

fit_dynamic_twfe.iplot(
    coord_flip=False,
    title="Event Study",
    figsize=[1200, 400],
    yintercept=0,
    xintercept=13.5,
    labels=rename_event_study_coefs(fit_dynamic_twfe._coefnames),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants