Skip to content

Fix marginal effects plot (with categorical interactions) page #178

@grantmcdermott

Description

@grantmcdermott

The fixest code is all broken here: https://lost-stats.github.io/Presentation/Figures/marginal_effects_plots_for_interactions_with_categorical_variables.html

(Likely due to changes to i() introduced around version 7.0.0).

The solution is something like:

library(fixest)

od = read.csv('https://github.com/LOST-STATS/lost-stats.github.io/raw/source/Presentation/Figures/Data/Marginal_Effects_Plots_For_Interactions_With_Categorical_Variables/organ_donation.csv')

od = 
  within(od, {
    Date = as.Date(paste(substr(Quarter, 3, 7), 
                         as.integer(substr(Quarter, 2, 2))*3-2, 
                         1, 
                         sep = "-"))
    Treated = State == 'California'
})

fmod = feols(Rate ~ i(Date, Treated, ref = "2011-04-01") | State + Date, 
             data = od)

coefplot(fmod)
iplot(fmod)

But stepping back, I actually think we should change the dataset for this page. It requires several tedious data cleaning steps across the different languages and ultimately ends up producing an event study plot because of the time dimension (which is confusing in of itself). Aren't we just looking for something like

mod = lm(mpg ~ factor(vs) * factor(am), mtcars)
summary(mod)
marginaleffects::plot_cap(mod, condition = "am")

? (And obvs the equivalent in other languages)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions