grantmcdermott / ggfixest

Dedicated ggplot2 methods for fixest model objects
http://grantmcdermott.com/ggfixest/
43 stars 7 forks source link

Overlaying multiple CI-levels #2

Closed simonheb closed 2 years ago

simonheb commented 2 years ago

Great work, Grant!

Is there a straightforward way to overlay two different CIs here (I was thinking 99%-CI blue, 95%-CI lighter blue, ...)?

A bit like here: image (from: https://www.pnas.org/content/118/15/e2024399118)

grantmcdermott commented 2 years ago

Hi Simon,

Sorry for being slow with this.

There isn't an automatic way of getting overlays unless upstream changes are made to fixest::iplot. The TL;DR version is that this package calls fixest::iplot(est, only.params = TRUE) under the hood to generate the data.frame(s) that ultimately get passed to the ggplot call. Currently, fixest::iplot only accepts a scalar ci_level argument, so we're stuck with that.

Having said that... it shouldn't be too hard to implement a manual loop on our end if a user inputs multiple CI levels. I need to finish setting and proctoring exams, and also want to tackle #1 first. But I'll think on this, since I agree it's a useful feature. Thanks for the suggestion.

grantmcdermott commented 2 years ago

@simonheb you should be able to do this now if you grab the latest dev version. Examples below. Thanks for the prompt!

library(ggiplot)
#> Loading required package: ggplot2
library(fixest)

est_did = feols(y ~ x1 + i(period, treat, 5) | id+period, base_did)

ggiplot(est_did, geom_style = "errorbar", 
                ci_level = c(.8, .95))

ggiplot(est_did, geom_style = "ribbon", pt.pch = NA, 
                ci_level = c(.8, .95))

est_twfe = feols(y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | 
                                    id + year, base_stagg)
est_sa20 = feols(y ~ x1 + sunab(year_treated, year) | 
                                    id + year, base_stagg)
ggiplot(list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20),
                main = 'Staggered treatment', ref.line = -1, pt.pch = NA,
                geom_style = "ribbon",
                multi_style = 'facet', 
                ci_level = c(.8, .95))

Created on 2022-06-17 by the reprex package (v2.0.1)