diff --git a/index.html b/index.html index bee9db3..c60467a 100644 --- a/index.html +++ b/index.html @@ -206,8 +206,8 @@

Developers

Dev status

diff --git a/pkgdown.yml b/pkgdown.yml index 076be95..3877234 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: ggiplot: ggiplot.html -last_built: 2023-12-12T16:44Z +last_built: 2023-12-12T17:39Z urls: reference: http://grantmcdermott.com/ggiplot/reference article: http://grantmcdermott.com/ggiplot/articles diff --git a/reference/iplot_data.html b/reference/iplot_data.html index 12ad6e7..41d4e89 100644 --- a/reference/iplot_data.html +++ b/reference/iplot_data.html @@ -153,11 +153,11 @@

Arguments?fixest::coefplot for more.

+valid uses:

.vcov, .cluster, .se
diff --git a/search.json b/search.json index 8a35620..470b9cf 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-1-vanilla-twfe","dir":"Articles","previous_headings":"","what":"Example 1: Vanilla TWFE","title":"Comparing ggiplot with iplot","text":"Let’s compare (base) iplot ggiplot default plots. small differences, certainly producing basic plot. get even closer original, specify use errorbar(s) rather (ggiplot’s default ) pointrange(s). Many arguments iplot carry ggiplot . deliberate, since want reduce cognitive overhead switching two plotting methods. example, can join points using pt.join = TRUE argument. ggiplot defaults slightly different cases, may require less arguments depending want . example, Unlike base iplot, multiple confidence interval levels supported. works ribbons . Another new feature (.e. unsupported base iplot) adding aggregated post- /pre-treatment effects plots. ’s example builds previous plot, adding mean post-treatment effect.","code":"data(base_did) est_did = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did) iplot(est_did) ggiplot(est_did) ggiplot(est_did, geom = 'errorbar') iplot(est_did, pt.join = TRUE) ggiplot(est_did, pt.join = TRUE, geom_style = 'errorbar') # iplot(est_did, pt.join = TRUE, ci.lty = 0, ci.width = 0, ci.fill = TRUE) iplot( est_did, pt.join = TRUE, ci.lty = 0, ci.width = 0, ci.fill = TRUE, ci.fill.par = list(col = 'black', alpha = 0.3) ) ggiplot(est_did, geom_style = 'ribbon') ggiplot(est_did, geom_style = 'ribbon', pt.pch = NA, col = 'orange') #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. ggiplot(est_did, ci_level = c(.8, .95)) ggiplot( est_did, ci_level = c(.8, .95), aggr_eff = \"post\", aggr_eff.par = list(col = \"orange\") # default col is grey )"},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-2-multiple-estimation-i","dir":"Articles","previous_headings":"","what":"Example 2: Multiple estimation (i)","title":"Comparing ggiplot with iplot","text":"’ll demonstrate multiple estimation functionality using staggered treatment example (comparing vanilla TWFE Sun-Abraham estimator) fixest introductory vignette. , comparison, base iplot original. Note add legend manually. ’s ggiplot version. don’t name list models defaults something sensible. One nice thing ggplot2 API makes changing multiplot figures simple. example, don’t like presentation “dodged” models single frame, ’s easy facet instead using multi_style = 'facet' argument.","code":"data(base_stagg) est_twfe = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg ) est_sa20 = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg ) iplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) legend( 'topleft', col = c(1, 2), pch = c(20, 17), legend = c('TWFE', 'Sun & Abraham (2020)') ) ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) ggiplot( list(est_twfe, est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE, multi_style = 'facet' )"},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-3-multiple-estimation-ii","dir":"Articles","previous_headings":"","what":"Example 3: Multiple estimation (ii)","title":"Comparing ggiplot with iplot","text":"area ggiplot shines complex multiple estimation cases, lists fixest_multi objects. illustrate, let’s add split variable (group) staggered dataset. Now re-run two regressions earlier, splitting sample generate fixest_multi objects. iplot ggiplot fine single fixest_multi object (although remember manually add legend former) However, iplot complains combine list several fixest_multi objects. contrast, ggiplot works… … even better use faceting instead dodged errorbars. Let’s use opportunity construct fancy plot invokes additional arguments ggplot theming.","code":"base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~ grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, base_stagg_grp, split = ~ grp ) iplot(est_twfe_grp, ref.line = -1, main = 'Staggered treatment: TWFE') legend('topleft', col = c(1, 2), pch = c(20, 17), legend = c('Evens', 'Odds')) ggiplot(est_twfe_grp, ref.line = -1, main = 'Staggered treatment: TWFE') iplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split mutli-sample' ) #> The degrees of freedom for the t distribution could not be deduced. Using a Normal distribution instead. #> Note that you can provide the argument `df.t` directly. #> Error in coefplot_prms(object = object, ..., sd = sd, ci_low = ci_low, : The first element of 'object' raises and error: #> Error in nb * sd : non-numeric argument to binary operator ggiplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split mutli-sample' ) ggiplot( list(\"TWFE\" = est_twfe_grp, \"Sun & Abraham (2020)\" = est_sa20_grp), ref.line = -1, main = \"Staggered treatment: Split mutli-sample\", xlab = \"Time to treatment\", multi_style = \"facet\", geom_style = \"ribbon\", facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = \"HersheySans\"), plot.title = element_text(hjust = 0.5), legend.position = \"none\" ) )"},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"on-theming-and-scale-adjustments","dir":"Articles","previous_headings":"Asides","what":"On theming and scale adjustments","title":"Comparing ggiplot with iplot","text":"Setting theme inside ggiplot call optional strictly necessary, since ggplot2 API allows programmatic updating existing plots. E.g. etc.","code":"last_plot() + labs(caption = 'Note: Super fancy plot brought to you by ggiplot') last_plot() + theme_grey() + theme(legend.position = 'none') + scale_fill_brewer(palette = 'Set1', aesthetics = c('colour', 'fill')) #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale."},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"on-dictionaries","dir":"Articles","previous_headings":"Asides","what":"On dictionaries","title":"Comparing ggiplot with iplot","text":"Dictionaries work similarly iplot. Simple example: can either set dictionary directly plot call… … , set globally using setFixest_dict macro.","code":"base_did$letter = letters[base_did$period] est_letters = feols(y ~ x1 + i(letter, treat, 'e') | id+letter, base_did) # Dictionary for capitalising the letters dict = LETTERS[1:10]; names(dict) = letters[1:10] ggiplot(est_letters) # No dictionary ggiplot(est_letters, dict = dict) setFixest_dict(dict) ggiplot(est_letters) setFixest_dict() # reset"},{"path":"http://grantmcdermott.com/ggiplot/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Grant McDermott. Author, maintainer. Laurent Berge. Contributor.","code":""},{"path":"http://grantmcdermott.com/ggiplot/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"McDermott G (2023). ggfixest: Dedicated ggplot2 methods fixest objects. R package version 0.0.3.9001, http://grantmcdermott.com/ggfixest/.","code":"@Manual{, title = {ggfixest: Dedicated ggplot2 methods for fixest objects}, author = {Grant McDermott}, year = {2023}, note = {R package version 0.0.3.9001}, url = {http://grantmcdermott.com/ggfixest/}, }"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"ggfixest","dir":"","previous_headings":"","what":"Dedicated ggplot2 methods for fixest objects","title":"Dedicated ggplot2 methods for fixest objects","text":"ggfixest package provides dedicated ggplot2 plotting methods fixest objects. Specifically, provides drop-“gg” equivalents latter’s coefplot iplot base plotting functions. goal ggfixest produce nice looking coefficient plots interaction plots—including event study plots—minimal effort scope customization.","code":""},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Dedicated ggplot2 methods for fixest objects","text":"package yet CRAN, can installed R-universe:","code":"install.packages(\"ggfixest\", repos = \"https://grantmcdermott.r-universe.dev\")"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"quickstart","dir":"","previous_headings":"","what":"Quickstart","title":"Dedicated ggplot2 methods for fixest objects","text":"package website provides number examples help documentation. (Also available typing ?ggcoefplot ?ggiplot R console.) quickstart examples whet appetite. Start loading ggfixest packages. Note automatically loaded ggplot2 fixest required dependencies. package name suggests, ggfixest supports fixest model objects.1","code":"library(ggfixest) #> Loading required package: ggplot2 #> Loading required package: fixest"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"coefficient-plots","dir":"","previous_headings":"Quickstart","what":"Coefficient plots","title":"Dedicated ggplot2 methods for fixest objects","text":"Use ggcoefplot draw basic coefficient plots. plot call output look familiar regular fixest users. Like base equivalent, ggcoefplot can heavily customized contains various shortcuts common operations. example, can use regex control coefficient grouping logic.","code":"est = feols( Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width + Species, data = iris ) # coefplot(est) ## base version ggcoefplot(est) ## this package ggcoefplot(est, group = list(Sepal = \"^^Sepal.\", Species = \"^^Species\"))"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"event-study-plots","dir":"","previous_headings":"Quickstart","what":"Event study plots","title":"Dedicated ggplot2 methods for fixest objects","text":"ggiplot function special case ggocoefplot plots coefficients factor levels interactions (specifically, created operator). especially useful producing event study plots difference--differences () setup. , plot call output look familiar regular fixest users. note ggiplot supports several features available base iplot version. example, plotting multiple confidence intervals aggregate treatments effects. can get quite fancy, combining lists complex multiple estimation objects custom themes, . ggiplot examples comparisons base counterpart, see detailed vignette package homepage (, typing vignette(\"ggiplot\") R console).","code":"est_did = feols(y ~ x1 + i(period, treat, 5) | id+period, base_did) # iplot(est_did) ## base version ggiplot(est_did) ## this package ggiplot( est_did, ci_level = c(.8, .95), aggr_eff = \"post\", aggr_eff.par = list(col = \"orange\") ) base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg_grp, split = ~grp ) ggiplot( list(\"TWFE\" = est_twfe_grp, \"Sun & Abraham (2020)\" = est_sa20_grp), ref.line = -1, main = \"Staggered treatment: Split mutli-sample\", xlab = \"Time to treatment\", multi_style = \"facet\", geom_style = \"ribbon\", facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = \"HersheySans\"), plot.title = element_text(hjust = 0.5), legend.position = \"none\" ) )"},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":null,"dir":"Reference","previous_headings":"","what":"Aggregates event-study treatment effects. — aggr_es","title":"Aggregates event-study treatment effects. — aggr_es","text":"Aggregates post- (/pre-) treatment effects \"event-study\" estimation, also known dynamic difference--differences (DDiD) model. event-study estimated using fixest package, provides specialised () operator class models. default, function return average post-treatment effect (.e. across multiple periods). However, can also return cumulative post-treatment effect can used aggregate pre-treatment effects . heart, aggr_es() convenience wrapper around marginaleffects::hypotheses(), used perform underlying joint hypothesis test.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Aggregates event-study treatment effects. — aggr_es","text":"","code":"aggr_es( object, rhs = 0, period = \"post\", aggregation = c(\"mean\", \"cumulative\"), abbr_term = TRUE, ... )"},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Aggregates event-study treatment effects. — aggr_es","text":"object model object class fixest, () operator used facilitate \"event-study\" design. See Examples. rhs Numeric. null hypothesis value. Defaults 0. period Keyword string numeric sequence. group periods aggregating? Can either one three convenience strings---.e., \"post\" (default), \"prep\", \"\"---numeric sequence matches subset periods data (e.g. 6:8). aggregation Character string. aggregation type. Either \"mean\" (default) \"cumulative\". abbr_term Logical. leading \"term\" column return data frame abbreviated? default TRUE. FALSE, term column retain full hypothesis test string per usual marginaleffects(). Note information retained attribute return object, regardless. ... Additional arguments passed marginaleffects::hypotheses().","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Aggregates event-study treatment effects. — aggr_es","text":"\"tidy\" data frame aggregated (pre /post) treatment effects, plus inferential information standard errors, confidence intervals, etc. Potentially useful information underlying hypothesis test also provided attribute. See Examples.","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Aggregates event-study treatment effects. — aggr_es","text":"","code":"library(ggfixest) ## Will load fixest too est = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did) # Default hypothesis test is a null mean post-treatment effect (post_mean = aggr_es(est)) #> term estimate std.error statistic p.value s.value #> 1: post-treatment (mean) 3.906554 0.8598576 4.543257 5.539159e-06 17.4619 #> conf.low conf.high #> 1: 2.221264 5.591844 # The underlying hypothesis is saved as an attribute attributes(post_mean)[\"hypothesis\"] #> $ #> NULL #> # Other hypothesis and aggregation options aggr_es(est, aggregation = \"cumulative\") # cumulative instead of mean effects #> term estimate std.error statistic p.value #> 1: post-treatment (cumulative) 19.53277 4.299288 4.543257 5.539158e-06 #> s.value conf.low conf.high #> 1: 17.4619 11.10632 27.95922 aggr_es(est, period = \"pre\") # pre period instead of post #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -1.179871 0.8561964 -1.378037 0.1681917 2.571821 #> conf.low conf.high #> 1: -2.857985 0.4982434 aggr_es(est, period = \"both\") # pre & post periods separately #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -1.179871 0.8561964 -1.378037 1.681917e-01 2.571821 #> 2: post-treatment (mean) 3.906554 0.8598576 4.543257 5.539159e-06 17.461902 #> conf.low conf.high #> 1: -2.857985 0.4982434 #> 2: 2.221264 5.5918440 aggr_es(est, period = 6:8) # specific subset of periods #> term estimate std.error statistic p.value s.value #> 1: periods6:8-treatment (mean) 2.731705 0.9299503 2.937474 0.003308975 8.2394 #> conf.low conf.high #> 1: 0.9090361 4.554374 aggr_es(est, rhs = -1, period = \"pre\") # pre period with H0 value of 1 #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -0.1798707 0.8561964 -0.2100811 0.8336044 0.2625653 #> conf.low conf.high #> 1: -1.857985 1.498243 # Etc."},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":null,"dir":"Reference","previous_headings":"","what":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"Draws ggplot2 equivalents fixest::coefplot fixest::iplot. \"gg\" versions best recycle arguments plotting logic original base counterparts. also support additional features via ggplot2 API infrastructure. overall goal remains original functions. wit: ggcoefplot plots results estimations (coefficients confidence intervals). function ggiplot restricts output variables created , either interactions factors raw factors.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"","code":"ggcoefplot( object, geom_style = c(\"pointrange\", \"errorbar\"), multi_style = c(\"dodge\", \"facet\"), facet_args = NULL, theme = NULL, ... ) ggiplot( object, geom_style = c(\"pointrange\", \"errorbar\", \"ribbon\"), multi_style = c(\"dodge\", \"facet\"), aggr_eff = NULL, aggr_eff.par = list(col = \"grey50\", lwd = 1, lty = 1), facet_args = NULL, theme = NULL, ... )"},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"object model object class fixest fixest_multi, list thereof. geom_style Character string. One c('pointrange', 'errorbar', 'ribbon') describing preferred geometric representation coefficients. Note ribbon plots supported ggcoefplot, since guarantee continuous relationship among coefficients. multi_style Character string. One c('dodge', 'facet'), defining multi-model objects presented. facet_args list arguments passed ggplot::fact_wrap(). E.g. facet_args = list(ncol = 2, scales = 'free_y'). used multi_style = 'facet'. theme ggplot2 theme. Defaults theme_linedraw() minor adjustments, centered plot title. Can also defined existing ggiplot object redefine theme elements. See examples. ... Arguments passed , equivalent , corresponding fixest::coefplot/fixest::iplot arguments. Note require list objects. Currently used : keep drop subsetting variables using regular expressions. fixest::iplot help page includes detailed examples, generally work expect. One useful regexp trick worth mentioning briefly event studies many pre-/post-periods drop = \"[[:digit:]]{2}\". cause plot zoom around single digit pre-/post-periods. group list indicating variables group . element list reports coefficients grouped name element group name. element list can either: ) character vector length 1, ii) length 2, iii) numeric vector. Special patterns \"^^var_start\" can used appealing plotting, group labels separated subsidiary labels. can especially useful plotting interaction terms. See Details section fixest::coefplot information. .select Integer scalar, default 1. ggiplot, used select variable created () select. used several variables created . See Details section fixest::iplot information. main, xlab, ylab setting plot title, x- y-axis labels, respectively. zero zero.par defining adjusting zero line. example, zero.par = list(col = 'orange'). ref.line ref.line.par defining adjusting vertical reference line. example, ref.line.par = list(col = 'red', lty = 4). pt.pch pt.join overriding default point estimate shapes joining , respectively. col manually defining line, point, ribbon colours. ci_level changing desired confidence level (default = 0.95). Note multiple levels allowed, e.g. ci_level = c(0.8, 0.95). ci.width changing width extremities confidence intervals. used geom_style = \"errorbar\" (multiple CI levels requested default pointrange style). default value 0.2. ci.fill.par changing confidence interval fill. used geom_style = \"ribbon\" currently affects alpha (transparency) channel. example, can make CI band lighter ci.fill.par = list(alpha = 0.2) (default alpha 0.3). dict dictionary overriding coefficient names. vcov, cluster se alternative options adjusting standard errors model object(s) fly. See summary.fixest details. Written superseding order; cluster considered vcov null, etc. aggr_eff keyword string numeric sequence, indicating whether mean treatment effects subset model displayed part plot. example, \"post\" keyword means mean post-treatment effect plotted alongside individual period effects. Passed aggr_es; see function's documentation valid options. aggr_eff.par List. Parameters aggregated treatment effect line, plotted. default values col = 'gray50', lwd = 1, lty = 1.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"ggplot2 object.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"functions generally try mimic functionality (appropriate) arguments fixest::coefplot fixest::iplot closely possible. However, leveraging ggplot2 API infrastructure, able support complex plot arrangements ---box difficult achieve using base coefplot/iplot alternatives.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"ggiplot(): function plots results estimations (coefficients confidence intervals). function ggiplot restricts output variables created , either interactions factors raw factors.","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"","code":"library(ggfixest) ## # Author note: The examples that follow deliberately follow the original # examples from the coefplot/iplot help pages. A few \"gg-\" specific # features are sprinkled within, with the final set of examples in # particular highlighting unique features of this package. # # Example 1: Basic use and stacking two sets of results on the same graph # # Estimation on Iris data with one fixed-effect (Species) est = feols(Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width | Species, iris) ggcoefplot(est) # Show multiple CIs ggcoefplot(est, ci_level = c(0.8, 0.95)) # By default, fixest model standard errors are clustered by the first fixed # effect (here: Species). # But we can easily switch to \"regular\" standard-errors est_std = summary(est, se = \"iid\") # You can plot both results at once in the same plot frame... ggcoefplot(list(\"Clustered\" = est, \"IID\" = est_std)) # ... or as separate facets ggcoefplot(list(\"Clustered\" = est, \"IID\" = est_std), multi_style = \"facet\") + theme(legend.position = \"none\") # # Example 2: Interactions # # Now we estimate and plot the \"yearly\" treatment effects data(base_did) base_inter = base_did # We interact the variable 'period' with the variable 'treat' est_did = feols(y ~ x1 + i(period, treat, 5) | id + period, base_inter) # In the estimation, the variable treat is interacted # with each value of period but 5, set as a reference # ggcoefplot will show all the coefficients: ggcoefplot(est_did) # Note that the grouping of the coefficients is due to 'group = \"auto\"' # If you want to keep only the coefficients # created with i() (ie the interactions), use ggiplot ggiplot(est_did) # We can see that the graph is different from before: # - only interactions are shown, # - the reference is present, # => this is fully flexible ggiplot(est_did, ci_level = c(0.8, 0.95)) ggiplot(est_did, ref.line = FALSE, pt.join = TRUE, geom_style = \"errorbar\") ggiplot(est_did, geom_style = \"ribbon\", col = \"orange\") #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. # etc # We can also use a dictionary to replace label values. The dicionary should # take the form of a named vector or list, e.g. c(\"old_lab1\" = \"new_lab1\", ...) # Let's create a \"month\" variable all_months = c(\"aug\", \"sept\", \"oct\", \"nov\", \"dec\", \"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\") # Turn into a dictionary by providing the old names # Note the implication that treatment occured here in December (5 month in our series) dict = all_months; names(dict) = 1:12 # Pass our new dictionary to our ggiplot call ggiplot(est_did, pt.join = TRUE, geom_style = \"errorbar\", dict = dict) # # What if the interacted variable is not numeric? # let's re-use our all_months vector from the previous example, but add it # directly to the dataset base_inter$period_month = all_months[base_inter$period] # The new estimation est = feols(y ~ x1 + i(period_month, treat, \"oct\") | id+period, base_inter) # Since 'period_month' of type character, iplot/coefplot both sort it ggiplot(est) # To respect a plotting order, use a factor base_inter$month_factor = factor(base_inter$period_month, levels = all_months) est = feols(y ~ x1 + i(month_factor, treat, \"oct\") | id + period, base_inter) ggiplot(est) # dict -> c(\"old_name\" = \"new_name\") dict = all_months; names(dict) = 1:12; dict #> 1 2 3 4 5 6 7 8 9 10 11 #> \"aug\" \"sept\" \"oct\" \"nov\" \"dec\" \"jan\" \"feb\" \"mar\" \"apr\" \"may\" \"jun\" #> 12 #> \"jul\" ggiplot(est_did, dict = dict) # # Example 3: Setting defaults # # The customization logic of ggcoefplot/ggiplot works differently than the # original base fixest counterparts, so we don't have \"gg\" equivalents of # setFixest_coefplot and setFixest_iplot. However, you can still invoke some # global fixest settings like setFixest_dict(). SImple example: base_inter$letter = letters[base_inter$period] est_letters = feols(y ~ x1 + i(letter, treat, 'e') | id+letter, base_inter) # Set global dictionary for capitalising the letters dict = LETTERS[1:10]; names(dict) = letters[1:10] setFixest_dict(dict) ggiplot(est_letters) setFixest_dict() # reset # # Example 4: group + cleaning # # You can use the argument group to group variables # You can further use the special character \"^^\" to clean # the beginning of the coef. name: particularly useful for factors est = feols(Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width + Species, iris) # No grouping: ggcoefplot(est) # now we group by Sepal and Species ggcoefplot(est, group = list(Sepal = \"Sepal\", Species = \"Species\")) # now we group + clean the beginning of the names using the special character ^^ ggcoefplot(est, group = list(Sepal = \"^^Sepal.\", Species = \"^^Species\")) # # Example 5: Some more ggcoefplot/ggiplot extras # # We'll demonstrate using the staggered treatment example from the # introductory fixest vignette. data(base_stagg) 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, data = base_stagg ) # Plot both regressions in a faceted plot ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) # So far that's no different than base iplot (automatic legend aside). But an # area where ggiplot shines is in complex multiple estimation cases, such as # lists of fixest_multi objects. To illustrate, let's add a split variable # (group) to our staggered dataset. base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') # Now re-run our two regressions from earlier, but splitting the sample to # generate fixest_multi objects. est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~ grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg_grp, split = ~ grp ) # ggiplot combines the list of multi-estimation objects without a problem... ggiplot(list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split multi-sample') # ... but is even better when we use facets instead of dodged errorbars. # Let's use this an opportunity to construct a fancy plot that invokes some # additional arguments and ggplot theming. ggiplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split multi-sample', xlab = 'Time to treatment', multi_style = 'facet', geom_style = 'ribbon', facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = 'HersheySans'), plot.title = element_text(hjust = 0.5), legend.position = 'none' ) ) # # Aside on theming and scale adjustments # # Setting the theme inside the `ggiplot()` call is optional and not strictly # necessary, since the ggplot2 API allows programmatic updating of existing # plots. E.g. last_plot() + labs(caption = 'Note: Super fancy plot brought to you by ggiplot') last_plot() + theme_grey() + theme(legend.position = 'none') + scale_fill_brewer(palette = 'Set1', aesthetics = c(\"colour\", \"fill\")) #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. # etc. #' @export"},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":null,"dir":"Reference","previous_headings":"","what":"Internal function for grabbing and preparing iplot data — iplot_data","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"Grabs underlying data used construct fixest::iplot, added functionality tweaks ggiplot equivalents.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"","code":"iplot_data( object, .ci_level = 0.95, .keep = NULL, .drop = NULL, .dict = fixest::getFixest_dict(), .internal.only.i = TRUE, .i.select = 1, .aggr_es = NULL, .group = \"auto\", .vcov = NULL, .cluster = NULL, .se = NULL ) coefplot_data( object, .ci_level = 0.95, .keep = NULL, .drop = NULL, .group = \"auto\", .dict = fixest::getFixest_dict(), .internal.only.i = FALSE, .i.select = 1, .aggr_es = \"none\", .vcov = NULL, .cluster = NULL, .se = NULL )"},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"object model object class fixest fixest_multi, () operator used construct interaction, set interactions. .ci_level number 0 1 indicating desired confidence level, Defaults 0.95. .keep Character vector used subset coefficients interest. Passed fixest::iplot(..., keep = .keep) take form acceptable regular expression. .drop Character vector used subset coefficients interest (complement .keep). Passed fixest::iplot(..., drop = .drop) take form acceptable regular expression. .dict dictionary (.e. named character vector logical scalar). Used changing coefficient names. Defaults values getFixest_dict(). See ?fixest::coefplot documentation information. Note: argument applies dictionary changes directly return object coefplot_data. However, ignored iplot_data, since want preserve numeric ordering potential event study plots. (imposing ordered factor create downstream problems case continuous plot features like ribbons.) Instead, dictionary replacement ggiplot deferred actual plot call applied directly labels. .internal..Logical variable used internal function handling passing coefplot/iplot. ..select Integer scalar, default 1. (gg)iplot, used select variable created () select. used several variables created . index, just try increasing numbers hopefully obtain want. Passed fixest::iplot(..., .select = ..select) .aggr_es keyword string numeric sequence indicating whether aggregated mean treatment effects subset model added column returned data frame. Passed aggr_es(..., aggregation = \"mean\"). .group list, default missing. element list reports coefficients grouped name element group name. Passed fixest::coefplot(..., group = .group). Example valid uses: ⁠group=list(group_name=\\\"pattern\\\")⁠, ⁠group=list(group_name=c(\\\"var_start\\\", \\\"var_end\\\"))⁠, ⁠group=list(group_name=1:2)) See Details section ?fixest::coefplot . .vcov, .cluster, .se Alternative options adjusting standard errors model object fly. See summary.fixest details (although note \".\" period prefix ignored latter's argument documentation). Written superseding order; .cluster considered .vcov null, etc.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"data frame consisting estimate values, confidence intervals, relative x-axis positions, aesthetic information needed draw ggplot2 object.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"function wrapper around fixest::iplot(..., .params = TRUE), various checks tweaks better facilitate plotting ggplot2 handling complex object types (e.g. lists fixest_multi models)","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"coefplot_data(): Internal function grabbing preparing coefplot data","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"","code":"library(fixest) est_did = feols(y ~ x1 + i(period, treat, 5) | id+period, data = base_did) iplot(est_did, only.params = TRUE) # The \"base\" version #> $prms #> estimate ci_low ci_high estimate_names estimate_names_raw is_ref x id #> 1 -1.403045 -3.604020 0.7979286 1 period::1:treat FALSE 1 1 #> 2 -1.247511 -3.414542 0.9195208 2 period::2:treat FALSE 2 1 #> 3 -0.273206 -2.467576 1.9211637 3 period::3:treat FALSE 3 1 #> 4 -1.795721 -3.952502 0.3610605 4 period::4:treat FALSE 4 1 #> 5 0.000000 0.000000 0.0000000 5 period::5:treat TRUE 5 1 #> 6 0.784452 -1.254207 2.8231114 6 period::6:treat FALSE 6 1 #> 7 3.598897 1.415176 5.7826183 7 period::7:treat FALSE 7 1 #> 8 3.811766 1.338739 6.2847934 8 period::8:treat FALSE 8 1 #> 9 4.731426 2.556528 6.9063241 9 period::9:treat FALSE 9 1 #> 10 6.606229 4.384980 8.8274781 10 period::10:treat FALSE 10 1 #> y #> 1 -1.403045 #> 2 -1.247511 #> 3 -0.273206 #> 4 -1.795721 #> 5 0.000000 #> 6 0.784452 #> 7 3.598897 #> 8 3.811766 #> 9 4.731426 #> 10 6.606229 #> #> $is_iplot #> [1] TRUE #> #> $at #> [1] 1 2 3 4 5 6 7 8 9 10 #> #> $labels #> [1] 1 2 3 4 5 6 7 8 9 10 #> iplot_data(est_did) # The wrapper provided by this package #> estimate ci_low ci_high estimate_names estimate_names_raw is_ref x id #> 1 -1.403045 -3.604020 0.7979286 1 period::1:treat FALSE 1 1 #> 2 -1.247511 -3.414542 0.9195208 2 period::2:treat FALSE 2 1 #> 3 -0.273206 -2.467576 1.9211637 3 period::3:treat FALSE 3 1 #> 4 -1.795721 -3.952502 0.3610605 4 period::4:treat FALSE 4 1 #> 5 0.000000 0.000000 0.0000000 5 period::5:treat TRUE 5 1 #> 6 0.784452 -1.254207 2.8231114 6 period::6:treat FALSE 6 1 #> 7 3.598897 1.415176 5.7826183 7 period::7:treat FALSE 7 1 #> 8 3.811766 1.338739 6.2847934 8 period::8:treat FALSE 8 1 #> 9 4.731426 2.556528 6.9063241 9 period::9:treat FALSE 9 1 #> 10 6.606229 4.384980 8.8274781 10 period::10:treat FALSE 10 1 #> y lhs ci_level #> 1 -1.403045 y 0.95 #> 2 -1.247511 y 0.95 #> 3 -0.273206 y 0.95 #> 4 -1.795721 y 0.95 #> 5 0.000000 y 0.95 #> 6 0.784452 y 0.95 #> 7 3.598897 y 0.95 #> 8 3.811766 y 0.95 #> 9 4.731426 y 0.95 #> 10 6.606229 y 0.95 # Illustrative fixest_multi case, where the sample has been split by odd and # even ID numbers. est_split = feols(y ~ x1 + i(period, treat, 5) | id+period, data = base_did, split = ~id%%2) iplot(est_split, only.params = TRUE) # The \"base\" version #> $prms #> estimate ci_low ci_high x id estimate_names estimate_names_raw #> 1 1.4239576 -1.3045751 4.1524903 0.9 1 1 period::1:treat #> 2 -4.1291547 -7.4736493 -0.7846601 1.1 2 1 period::1:treat #> 3 1.6931989 -1.1969846 4.5833824 1.9 1 2 period::2:treat #> 4 -4.1353019 -7.3187406 -0.9518632 2.1 2 2 period::2:treat #> 5 3.0439521 0.2877701 5.8001340 2.9 1 3 period::3:treat #> 6 -3.4897091 -6.6219675 -0.3574507 3.1 2 3 period::3:treat #> 7 -0.8667871 -3.9007876 2.1672135 3.9 1 4 period::4:treat #> 8 -2.6458897 -5.7808659 0.4890866 4.1 2 4 period::4:treat #> 9 0.0000000 0.0000000 0.0000000 4.9 1 5 period::5:treat #> 10 0.0000000 0.0000000 0.0000000 5.1 2 5 period::5:treat #> 11 3.8181620 0.8977637 6.7385603 5.9 1 6 period::6:treat #> 12 -2.2626440 -5.0075306 0.4822427 6.1 2 6 period::6:treat #> 13 5.1642678 2.0371025 8.2914332 6.9 1 7 period::7:treat #> 14 2.0828305 -1.0531952 5.2188562 7.1 2 7 period::7:treat #> 15 5.2338735 1.9703239 8.4974231 7.9 1 8 period::8:treat #> 16 2.4826394 -1.2915459 6.2568247 8.1 2 8 period::8:treat #> 17 7.0979736 3.8974384 10.2985089 8.9 1 9 period::9:treat #> 18 2.4385390 -0.3566843 5.2337622 9.1 2 9 period::9:treat #> 19 9.5453455 6.3242498 12.7664413 9.9 1 10 period::10:treat #> 20 3.6267443 0.5712362 6.6822524 10.1 2 10 period::10:treat #> is_ref y #> 1 FALSE 1.4239576 #> 2 FALSE -4.1291547 #> 3 FALSE 1.6931989 #> 4 FALSE -4.1353019 #> 5 FALSE 3.0439521 #> 6 FALSE -3.4897091 #> 7 FALSE -0.8667871 #> 8 FALSE -2.6458897 #> 9 TRUE 0.0000000 #> 10 TRUE 0.0000000 #> 11 FALSE 3.8181620 #> 12 FALSE -2.2626440 #> 13 FALSE 5.1642678 #> 14 FALSE 2.0828305 #> 15 FALSE 5.2338735 #> 16 FALSE 2.4826394 #> 17 FALSE 7.0979736 #> 18 FALSE 2.4385390 #> 19 FALSE 9.5453455 #> 20 FALSE 3.6267443 #> #> $is_iplot #> [1] TRUE #> #> $at #> [1] 1 2 3 4 5 6 7 8 9 10 #> #> $labels #> [1] 1 2 3 4 5 6 7 8 9 10 #> iplot_data(est_split) # The wrapper provided by this package #> id estimate ci_low ci_high x #> 1 sample.var: id%%2; sample: 0 1.4239576 -1.3045751 4.1524903 1 #> 2 sample.var: id%%2; sample: 0 1.6931989 -1.1969846 4.5833824 2 #> 3 sample.var: id%%2; sample: 0 3.0439521 0.2877701 5.8001340 3 #> 4 sample.var: id%%2; sample: 0 -0.8667871 -3.9007876 2.1672135 4 #> 5 sample.var: id%%2; sample: 0 0.0000000 0.0000000 0.0000000 5 #> 6 sample.var: id%%2; sample: 0 3.8181620 0.8977637 6.7385603 6 #> 7 sample.var: id%%2; sample: 0 5.1642678 2.0371025 8.2914332 7 #> 8 sample.var: id%%2; sample: 0 5.2338735 1.9703239 8.4974231 8 #> 9 sample.var: id%%2; sample: 0 7.0979736 3.8974384 10.2985089 9 #> 10 sample.var: id%%2; sample: 0 9.5453455 6.3242498 12.7664413 10 #> 11 sample.var: id%%2; sample: 1 -4.1291547 -7.4736493 -0.7846601 1 #> 12 sample.var: id%%2; sample: 1 -4.1353019 -7.3187406 -0.9518632 2 #> 13 sample.var: id%%2; sample: 1 -3.4897091 -6.6219675 -0.3574507 3 #> 14 sample.var: id%%2; sample: 1 -2.6458897 -5.7808659 0.4890866 4 #> 15 sample.var: id%%2; sample: 1 0.0000000 0.0000000 0.0000000 5 #> 16 sample.var: id%%2; sample: 1 -2.2626440 -5.0075306 0.4822427 6 #> 17 sample.var: id%%2; sample: 1 2.0828305 -1.0531952 5.2188562 7 #> 18 sample.var: id%%2; sample: 1 2.4826394 -1.2915459 6.2568247 8 #> 19 sample.var: id%%2; sample: 1 2.4385390 -0.3566843 5.2337622 9 #> 20 sample.var: id%%2; sample: 1 3.6267443 0.5712362 6.6822524 10 #> estimate_names estimate_names_raw is_ref y lhs sample ci_level #> 1 1 period::1:treat FALSE 1.4239576 y 0 0.95 #> 2 2 period::2:treat FALSE 1.6931989 y 0 0.95 #> 3 3 period::3:treat FALSE 3.0439521 y 0 0.95 #> 4 4 period::4:treat FALSE -0.8667871 y 0 0.95 #> 5 5 period::5:treat TRUE 0.0000000 y 0 0.95 #> 6 6 period::6:treat FALSE 3.8181620 y 0 0.95 #> 7 7 period::7:treat FALSE 5.1642678 y 0 0.95 #> 8 8 period::8:treat FALSE 5.2338735 y 0 0.95 #> 9 9 period::9:treat FALSE 7.0979736 y 0 0.95 #> 10 10 period::10:treat FALSE 9.5453455 y 0 0.95 #> 11 1 period::1:treat FALSE -4.1291547 y 1 0.95 #> 12 2 period::2:treat FALSE -4.1353019 y 1 0.95 #> 13 3 period::3:treat FALSE -3.4897091 y 1 0.95 #> 14 4 period::4:treat FALSE -2.6458897 y 1 0.95 #> 15 5 period::5:treat TRUE 0.0000000 y 1 0.95 #> 16 6 period::6:treat FALSE -2.2626440 y 1 0.95 #> 17 7 period::7:treat FALSE 2.0828305 y 1 0.95 #> 18 8 period::8:treat FALSE 2.4826394 y 1 0.95 #> 19 9 period::9:treat FALSE 2.4385390 y 1 0.95 #> 20 10 period::10:treat FALSE 3.6267443 y 1 0.95"},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/news/index.html","id":"new-features-0-0-3-9001","dir":"Changelog","previous_headings":"","what":"New features","title":"ggfixest 0.0.3.9001 (development version)","text":"aggr_es function now supports numeric sequences aggregating specific subset periods, addition existing keyword strings like “pre” “post”. functionality also passes higher order plotting functions call aggr_es hood. example, ggiplot(est, aggr_eff = 6:8). (#33) Users can now adjust standard errors model objects --fly plot time, passing appropriate argument, e.g. ggcoefplot(est, vcov = \"hc1\"). --fly adjustments done via summary.fixest, effect just passing adjusted object directly, e.g. ggcoefplot(summary(est, vcov = \"hc1\")). However, may prove convenient simultaneously adjusting list multiple models, e.g.  ggcoefplot(list(est1, est2, est3), vcov = \"hc1\"). (#35)","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/news/index.html","id":"breaking-change-0-0-3","dir":"Changelog","previous_headings":"","what":"Breaking change","title":"ggfixest 0.0.3","text":"package name changed ggfixest (#29).","code":""}] +[{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-1-vanilla-twfe","dir":"Articles","previous_headings":"","what":"Example 1: Vanilla TWFE","title":"Comparing ggiplot with iplot","text":"Let’s compare (base) iplot ggiplot default plots. small differences, certainly producing basic plot. get even closer original, specify use errorbar(s) rather (ggiplot’s default ) pointrange(s). Many arguments iplot carry ggiplot . deliberate, since want reduce cognitive overhead switching two plotting methods. example, can join points using pt.join = TRUE argument. ggiplot defaults slightly different cases, may require less arguments depending want . example, Unlike base iplot, multiple confidence interval levels supported. works ribbons . Another new feature (.e. unsupported base iplot) adding aggregated post- /pre-treatment effects plots. ’s example builds previous plot, adding mean post-treatment effect.","code":"data(base_did) est_did = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did) iplot(est_did) ggiplot(est_did) ggiplot(est_did, geom = 'errorbar') iplot(est_did, pt.join = TRUE) ggiplot(est_did, pt.join = TRUE, geom_style = 'errorbar') # iplot(est_did, pt.join = TRUE, ci.lty = 0, ci.width = 0, ci.fill = TRUE) iplot( est_did, pt.join = TRUE, ci.lty = 0, ci.width = 0, ci.fill = TRUE, ci.fill.par = list(col = 'black', alpha = 0.3) ) ggiplot(est_did, geom_style = 'ribbon') ggiplot(est_did, geom_style = 'ribbon', pt.pch = NA, col = 'orange') #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. ggiplot(est_did, ci_level = c(.8, .95)) ggiplot( est_did, ci_level = c(.8, .95), aggr_eff = \"post\", aggr_eff.par = list(col = \"orange\") # default col is grey )"},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-2-multiple-estimation-i","dir":"Articles","previous_headings":"","what":"Example 2: Multiple estimation (i)","title":"Comparing ggiplot with iplot","text":"’ll demonstrate multiple estimation functionality using staggered treatment example (comparing vanilla TWFE Sun-Abraham estimator) fixest introductory vignette. , comparison, base iplot original. Note add legend manually. ’s ggiplot version. don’t name list models defaults something sensible. One nice thing ggplot2 API makes changing multiplot figures simple. example, don’t like presentation “dodged” models single frame, ’s easy facet instead using multi_style = 'facet' argument.","code":"data(base_stagg) est_twfe = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg ) est_sa20 = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg ) iplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) legend( 'topleft', col = c(1, 2), pch = c(20, 17), legend = c('TWFE', 'Sun & Abraham (2020)') ) ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) ggiplot( list(est_twfe, est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE, multi_style = 'facet' )"},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"example-3-multiple-estimation-ii","dir":"Articles","previous_headings":"","what":"Example 3: Multiple estimation (ii)","title":"Comparing ggiplot with iplot","text":"area ggiplot shines complex multiple estimation cases, lists fixest_multi objects. illustrate, let’s add split variable (group) staggered dataset. Now re-run two regressions earlier, splitting sample generate fixest_multi objects. iplot ggiplot fine single fixest_multi object (although remember manually add legend former) However, iplot complains combine list several fixest_multi objects. contrast, ggiplot works… … even better use faceting instead dodged errorbars. Let’s use opportunity construct fancy plot invokes additional arguments ggplot theming.","code":"base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~ grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, base_stagg_grp, split = ~ grp ) iplot(est_twfe_grp, ref.line = -1, main = 'Staggered treatment: TWFE') legend('topleft', col = c(1, 2), pch = c(20, 17), legend = c('Evens', 'Odds')) ggiplot(est_twfe_grp, ref.line = -1, main = 'Staggered treatment: TWFE') iplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split mutli-sample' ) #> The degrees of freedom for the t distribution could not be deduced. Using a Normal distribution instead. #> Note that you can provide the argument `df.t` directly. #> Error in coefplot_prms(object = object, ..., sd = sd, ci_low = ci_low, : The first element of 'object' raises and error: #> Error in nb * sd : non-numeric argument to binary operator ggiplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split mutli-sample' ) ggiplot( list(\"TWFE\" = est_twfe_grp, \"Sun & Abraham (2020)\" = est_sa20_grp), ref.line = -1, main = \"Staggered treatment: Split mutli-sample\", xlab = \"Time to treatment\", multi_style = \"facet\", geom_style = \"ribbon\", facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = \"HersheySans\"), plot.title = element_text(hjust = 0.5), legend.position = \"none\" ) )"},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"on-theming-and-scale-adjustments","dir":"Articles","previous_headings":"Asides","what":"On theming and scale adjustments","title":"Comparing ggiplot with iplot","text":"Setting theme inside ggiplot call optional strictly necessary, since ggplot2 API allows programmatic updating existing plots. E.g. etc.","code":"last_plot() + labs(caption = 'Note: Super fancy plot brought to you by ggiplot') last_plot() + theme_grey() + theme(legend.position = 'none') + scale_fill_brewer(palette = 'Set1', aesthetics = c('colour', 'fill')) #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale."},{"path":"http://grantmcdermott.com/ggiplot/articles/ggiplot.html","id":"on-dictionaries","dir":"Articles","previous_headings":"Asides","what":"On dictionaries","title":"Comparing ggiplot with iplot","text":"Dictionaries work similarly iplot. Simple example: can either set dictionary directly plot call… … , set globally using setFixest_dict macro.","code":"base_did$letter = letters[base_did$period] est_letters = feols(y ~ x1 + i(letter, treat, 'e') | id+letter, base_did) # Dictionary for capitalising the letters dict = LETTERS[1:10]; names(dict) = letters[1:10] ggiplot(est_letters) # No dictionary ggiplot(est_letters, dict = dict) setFixest_dict(dict) ggiplot(est_letters) setFixest_dict() # reset"},{"path":"http://grantmcdermott.com/ggiplot/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Grant McDermott. Author, maintainer. Laurent Berge. Contributor.","code":""},{"path":"http://grantmcdermott.com/ggiplot/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"McDermott G (2023). ggfixest: Dedicated ggplot2 methods fixest objects. R package version 0.0.3.9001, http://grantmcdermott.com/ggfixest/.","code":"@Manual{, title = {ggfixest: Dedicated ggplot2 methods for fixest objects}, author = {Grant McDermott}, year = {2023}, note = {R package version 0.0.3.9001}, url = {http://grantmcdermott.com/ggfixest/}, }"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"ggfixest","dir":"","previous_headings":"","what":"Dedicated ggplot2 methods for fixest objects","title":"Dedicated ggplot2 methods for fixest objects","text":"ggfixest package provides dedicated ggplot2 plotting methods fixest objects. Specifically, provides drop-“gg” equivalents latter’s coefplot iplot base plotting functions. goal ggfixest produce nice looking coefficient plots interaction plots—including event study plots—minimal effort scope customization.","code":""},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Dedicated ggplot2 methods for fixest objects","text":"package yet CRAN, can installed R-universe:","code":"install.packages(\"ggfixest\", repos = \"https://grantmcdermott.r-universe.dev\")"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"quickstart","dir":"","previous_headings":"","what":"Quickstart","title":"Dedicated ggplot2 methods for fixest objects","text":"package website provides number examples help documentation. (Also available typing ?ggcoefplot ?ggiplot R console.) quickstart examples whet appetite. Start loading ggfixest packages. Note automatically loaded ggplot2 fixest required dependencies. package name suggests, ggfixest supports fixest model objects.1","code":"library(ggfixest) #> Loading required package: ggplot2 #> Loading required package: fixest"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"coefficient-plots","dir":"","previous_headings":"Quickstart","what":"Coefficient plots","title":"Dedicated ggplot2 methods for fixest objects","text":"Use ggcoefplot draw basic coefficient plots. plot call output look familiar regular fixest users. Like base equivalent, ggcoefplot can heavily customized contains various shortcuts common operations. example, can use regex control coefficient grouping logic.","code":"est = feols( Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width + Species, data = iris ) # coefplot(est) ## base version ggcoefplot(est) ## this package ggcoefplot(est, group = list(Sepal = \"^^Sepal.\", Species = \"^^Species\"))"},{"path":"http://grantmcdermott.com/ggiplot/index.html","id":"event-study-plots","dir":"","previous_headings":"Quickstart","what":"Event study plots","title":"Dedicated ggplot2 methods for fixest objects","text":"ggiplot function special case ggocoefplot plots coefficients factor levels interactions (specifically, created operator). especially useful producing event study plots difference--differences () setup. , plot call output look familiar regular fixest users. note ggiplot supports several features available base iplot version. example, plotting multiple confidence intervals aggregate treatments effects. can get quite fancy, combining lists complex multiple estimation objects custom themes, . ggiplot examples comparisons base counterpart, see detailed vignette package homepage (, typing vignette(\"ggiplot\") R console).","code":"est_did = feols(y ~ x1 + i(period, treat, 5) | id+period, base_did) # iplot(est_did) ## base version ggiplot(est_did) ## this package ggiplot( est_did, ci_level = c(.8, .95), aggr_eff = \"post\", aggr_eff.par = list(col = \"orange\") ) base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg_grp, split = ~grp ) ggiplot( list(\"TWFE\" = est_twfe_grp, \"Sun & Abraham (2020)\" = est_sa20_grp), ref.line = -1, main = \"Staggered treatment: Split mutli-sample\", xlab = \"Time to treatment\", multi_style = \"facet\", geom_style = \"ribbon\", facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = \"HersheySans\"), plot.title = element_text(hjust = 0.5), legend.position = \"none\" ) )"},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":null,"dir":"Reference","previous_headings":"","what":"Aggregates event-study treatment effects. — aggr_es","title":"Aggregates event-study treatment effects. — aggr_es","text":"Aggregates post- (/pre-) treatment effects \"event-study\" estimation, also known dynamic difference--differences (DDiD) model. event-study estimated using fixest package, provides specialised () operator class models. default, function return average post-treatment effect (.e. across multiple periods). However, can also return cumulative post-treatment effect can used aggregate pre-treatment effects . heart, aggr_es() convenience wrapper around marginaleffects::hypotheses(), used perform underlying joint hypothesis test.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Aggregates event-study treatment effects. — aggr_es","text":"","code":"aggr_es( object, rhs = 0, period = \"post\", aggregation = c(\"mean\", \"cumulative\"), abbr_term = TRUE, ... )"},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Aggregates event-study treatment effects. — aggr_es","text":"object model object class fixest, () operator used facilitate \"event-study\" design. See Examples. rhs Numeric. null hypothesis value. Defaults 0. period Keyword string numeric sequence. group periods aggregating? Can either one three convenience strings---.e., \"post\" (default), \"prep\", \"\"---numeric sequence matches subset periods data (e.g. 6:8). aggregation Character string. aggregation type. Either \"mean\" (default) \"cumulative\". abbr_term Logical. leading \"term\" column return data frame abbreviated? default TRUE. FALSE, term column retain full hypothesis test string per usual marginaleffects(). Note information retained attribute return object, regardless. ... Additional arguments passed marginaleffects::hypotheses().","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Aggregates event-study treatment effects. — aggr_es","text":"\"tidy\" data frame aggregated (pre /post) treatment effects, plus inferential information standard errors, confidence intervals, etc. Potentially useful information underlying hypothesis test also provided attribute. See Examples.","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/aggr_es.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Aggregates event-study treatment effects. — aggr_es","text":"","code":"library(ggfixest) ## Will load fixest too est = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did) # Default hypothesis test is a null mean post-treatment effect (post_mean = aggr_es(est)) #> term estimate std.error statistic p.value s.value #> 1: post-treatment (mean) 3.906554 0.8598576 4.543257 5.539159e-06 17.4619 #> conf.low conf.high #> 1: 2.221264 5.591844 # The underlying hypothesis is saved as an attribute attributes(post_mean)[\"hypothesis\"] #> $ #> NULL #> # Other hypothesis and aggregation options aggr_es(est, aggregation = \"cumulative\") # cumulative instead of mean effects #> term estimate std.error statistic p.value #> 1: post-treatment (cumulative) 19.53277 4.299288 4.543257 5.539158e-06 #> s.value conf.low conf.high #> 1: 17.4619 11.10632 27.95922 aggr_es(est, period = \"pre\") # pre period instead of post #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -1.179871 0.8561964 -1.378037 0.1681917 2.571821 #> conf.low conf.high #> 1: -2.857985 0.4982434 aggr_es(est, period = \"both\") # pre & post periods separately #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -1.179871 0.8561964 -1.378037 1.681917e-01 2.571821 #> 2: post-treatment (mean) 3.906554 0.8598576 4.543257 5.539159e-06 17.461902 #> conf.low conf.high #> 1: -2.857985 0.4982434 #> 2: 2.221264 5.5918440 aggr_es(est, period = 6:8) # specific subset of periods #> term estimate std.error statistic p.value s.value #> 1: periods6:8-treatment (mean) 2.731705 0.9299503 2.937474 0.003308975 8.2394 #> conf.low conf.high #> 1: 0.9090361 4.554374 aggr_es(est, rhs = -1, period = \"pre\") # pre period with H0 value of 1 #> term estimate std.error statistic p.value s.value #> 1: pre-treatment (mean) -0.1798707 0.8561964 -0.2100811 0.8336044 0.2625653 #> conf.low conf.high #> 1: -1.857985 1.498243 # Etc."},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":null,"dir":"Reference","previous_headings":"","what":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"Draws ggplot2 equivalents fixest::coefplot fixest::iplot. \"gg\" versions best recycle arguments plotting logic original base counterparts. also support additional features via ggplot2 API infrastructure. overall goal remains original functions. wit: ggcoefplot plots results estimations (coefficients confidence intervals). function ggiplot restricts output variables created , either interactions factors raw factors.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"","code":"ggcoefplot( object, geom_style = c(\"pointrange\", \"errorbar\"), multi_style = c(\"dodge\", \"facet\"), facet_args = NULL, theme = NULL, ... ) ggiplot( object, geom_style = c(\"pointrange\", \"errorbar\", \"ribbon\"), multi_style = c(\"dodge\", \"facet\"), aggr_eff = NULL, aggr_eff.par = list(col = \"grey50\", lwd = 1, lty = 1), facet_args = NULL, theme = NULL, ... )"},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"object model object class fixest fixest_multi, list thereof. geom_style Character string. One c('pointrange', 'errorbar', 'ribbon') describing preferred geometric representation coefficients. Note ribbon plots supported ggcoefplot, since guarantee continuous relationship among coefficients. multi_style Character string. One c('dodge', 'facet'), defining multi-model objects presented. facet_args list arguments passed ggplot::fact_wrap(). E.g. facet_args = list(ncol = 2, scales = 'free_y'). used multi_style = 'facet'. theme ggplot2 theme. Defaults theme_linedraw() minor adjustments, centered plot title. Can also defined existing ggiplot object redefine theme elements. See examples. ... Arguments passed , equivalent , corresponding fixest::coefplot/fixest::iplot arguments. Note require list objects. Currently used : keep drop subsetting variables using regular expressions. fixest::iplot help page includes detailed examples, generally work expect. One useful regexp trick worth mentioning briefly event studies many pre-/post-periods drop = \"[[:digit:]]{2}\". cause plot zoom around single digit pre-/post-periods. group list indicating variables group . element list reports coefficients grouped name element group name. element list can either: ) character vector length 1, ii) length 2, iii) numeric vector. Special patterns \"^^var_start\" can used appealing plotting, group labels separated subsidiary labels. can especially useful plotting interaction terms. See Details section fixest::coefplot information. .select Integer scalar, default 1. ggiplot, used select variable created () select. used several variables created . See Details section fixest::iplot information. main, xlab, ylab setting plot title, x- y-axis labels, respectively. zero zero.par defining adjusting zero line. example, zero.par = list(col = 'orange'). ref.line ref.line.par defining adjusting vertical reference line. example, ref.line.par = list(col = 'red', lty = 4). pt.pch pt.join overriding default point estimate shapes joining , respectively. col manually defining line, point, ribbon colours. ci_level changing desired confidence level (default = 0.95). Note multiple levels allowed, e.g. ci_level = c(0.8, 0.95). ci.width changing width extremities confidence intervals. used geom_style = \"errorbar\" (multiple CI levels requested default pointrange style). default value 0.2. ci.fill.par changing confidence interval fill. used geom_style = \"ribbon\" currently affects alpha (transparency) channel. example, can make CI band lighter ci.fill.par = list(alpha = 0.2) (default alpha 0.3). dict dictionary overriding coefficient names. vcov, cluster se alternative options adjusting standard errors model object(s) fly. See summary.fixest details. Written superseding order; cluster considered vcov null, etc. aggr_eff keyword string numeric sequence, indicating whether mean treatment effects subset model displayed part plot. example, \"post\" keyword means mean post-treatment effect plotted alongside individual period effects. Passed aggr_es; see function's documentation valid options. aggr_eff.par List. Parameters aggregated treatment effect line, plotted. default values col = 'gray50', lwd = 1, lty = 1.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"ggplot2 object.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"functions generally try mimic functionality (appropriate) arguments fixest::coefplot fixest::iplot closely possible. However, leveraging ggplot2 API infrastructure, able support complex plot arrangements ---box difficult achieve using base coefplot/iplot alternatives.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"ggiplot(): function plots results estimations (coefficients confidence intervals). function ggiplot restricts output variables created , either interactions factors raw factors.","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/ggcoefplot.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Draw coefficient plots and interaction plots from fixest regression\nobjects. — ggcoefplot","text":"","code":"library(ggfixest) ## # Author note: The examples that follow deliberately follow the original # examples from the coefplot/iplot help pages. A few \"gg-\" specific # features are sprinkled within, with the final set of examples in # particular highlighting unique features of this package. # # Example 1: Basic use and stacking two sets of results on the same graph # # Estimation on Iris data with one fixed-effect (Species) est = feols(Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width | Species, iris) ggcoefplot(est) # Show multiple CIs ggcoefplot(est, ci_level = c(0.8, 0.95)) # By default, fixest model standard errors are clustered by the first fixed # effect (here: Species). # But we can easily switch to \"regular\" standard-errors est_std = summary(est, se = \"iid\") # You can plot both results at once in the same plot frame... ggcoefplot(list(\"Clustered\" = est, \"IID\" = est_std)) # ... or as separate facets ggcoefplot(list(\"Clustered\" = est, \"IID\" = est_std), multi_style = \"facet\") + theme(legend.position = \"none\") # # Example 2: Interactions # # Now we estimate and plot the \"yearly\" treatment effects data(base_did) base_inter = base_did # We interact the variable 'period' with the variable 'treat' est_did = feols(y ~ x1 + i(period, treat, 5) | id + period, base_inter) # In the estimation, the variable treat is interacted # with each value of period but 5, set as a reference # ggcoefplot will show all the coefficients: ggcoefplot(est_did) # Note that the grouping of the coefficients is due to 'group = \"auto\"' # If you want to keep only the coefficients # created with i() (ie the interactions), use ggiplot ggiplot(est_did) # We can see that the graph is different from before: # - only interactions are shown, # - the reference is present, # => this is fully flexible ggiplot(est_did, ci_level = c(0.8, 0.95)) ggiplot(est_did, ref.line = FALSE, pt.join = TRUE, geom_style = \"errorbar\") ggiplot(est_did, geom_style = \"ribbon\", col = \"orange\") #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. # etc # We can also use a dictionary to replace label values. The dicionary should # take the form of a named vector or list, e.g. c(\"old_lab1\" = \"new_lab1\", ...) # Let's create a \"month\" variable all_months = c(\"aug\", \"sept\", \"oct\", \"nov\", \"dec\", \"jan\", \"feb\", \"mar\", \"apr\", \"may\", \"jun\", \"jul\") # Turn into a dictionary by providing the old names # Note the implication that treatment occured here in December (5 month in our series) dict = all_months; names(dict) = 1:12 # Pass our new dictionary to our ggiplot call ggiplot(est_did, pt.join = TRUE, geom_style = \"errorbar\", dict = dict) # # What if the interacted variable is not numeric? # let's re-use our all_months vector from the previous example, but add it # directly to the dataset base_inter$period_month = all_months[base_inter$period] # The new estimation est = feols(y ~ x1 + i(period_month, treat, \"oct\") | id+period, base_inter) # Since 'period_month' of type character, iplot/coefplot both sort it ggiplot(est) # To respect a plotting order, use a factor base_inter$month_factor = factor(base_inter$period_month, levels = all_months) est = feols(y ~ x1 + i(month_factor, treat, \"oct\") | id + period, base_inter) ggiplot(est) # dict -> c(\"old_name\" = \"new_name\") dict = all_months; names(dict) = 1:12; dict #> 1 2 3 4 5 6 7 8 9 10 11 #> \"aug\" \"sept\" \"oct\" \"nov\" \"dec\" \"jan\" \"feb\" \"mar\" \"apr\" \"may\" \"jun\" #> 12 #> \"jul\" ggiplot(est_did, dict = dict) # # Example 3: Setting defaults # # The customization logic of ggcoefplot/ggiplot works differently than the # original base fixest counterparts, so we don't have \"gg\" equivalents of # setFixest_coefplot and setFixest_iplot. However, you can still invoke some # global fixest settings like setFixest_dict(). SImple example: base_inter$letter = letters[base_inter$period] est_letters = feols(y ~ x1 + i(letter, treat, 'e') | id+letter, base_inter) # Set global dictionary for capitalising the letters dict = LETTERS[1:10]; names(dict) = letters[1:10] setFixest_dict(dict) ggiplot(est_letters) setFixest_dict() # reset # # Example 4: group + cleaning # # You can use the argument group to group variables # You can further use the special character \"^^\" to clean # the beginning of the coef. name: particularly useful for factors est = feols(Petal.Length ~ Petal.Width + Sepal.Length + Sepal.Width + Species, iris) # No grouping: ggcoefplot(est) # now we group by Sepal and Species ggcoefplot(est, group = list(Sepal = \"Sepal\", Species = \"Species\")) # now we group + clean the beginning of the names using the special character ^^ ggcoefplot(est, group = list(Sepal = \"^^Sepal.\", Species = \"^^Species\")) # # Example 5: Some more ggcoefplot/ggiplot extras # # We'll demonstrate using the staggered treatment example from the # introductory fixest vignette. data(base_stagg) 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, data = base_stagg ) # Plot both regressions in a faceted plot ggiplot( list('TWFE' = est_twfe, 'Sun & Abraham (2020)' = est_sa20), main = 'Staggered treatment', ref.line = -1, pt.join = TRUE ) # So far that's no different than base iplot (automatic legend aside). But an # area where ggiplot shines is in complex multiple estimation cases, such as # lists of fixest_multi objects. To illustrate, let's add a split variable # (group) to our staggered dataset. base_stagg_grp = base_stagg base_stagg_grp$grp = ifelse(base_stagg_grp$id %% 2 == 0, 'Evens', 'Odds') # Now re-run our two regressions from earlier, but splitting the sample to # generate fixest_multi objects. est_twfe_grp = feols( y ~ x1 + i(time_to_treatment, treated, ref = c(-1, -1000)) | id + year, data = base_stagg_grp, split = ~ grp ) est_sa20_grp = feols( y ~ x1 + sunab(year_treated, year) | id + year, data = base_stagg_grp, split = ~ grp ) # ggiplot combines the list of multi-estimation objects without a problem... ggiplot(list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split multi-sample') # ... but is even better when we use facets instead of dodged errorbars. # Let's use this an opportunity to construct a fancy plot that invokes some # additional arguments and ggplot theming. ggiplot( list('TWFE' = est_twfe_grp, 'Sun & Abraham (2020)' = est_sa20_grp), ref.line = -1, main = 'Staggered treatment: Split multi-sample', xlab = 'Time to treatment', multi_style = 'facet', geom_style = 'ribbon', facet_args = list(labeller = labeller(id = \\(x) gsub(\".*: \", \"\", x))), theme = theme_minimal() + theme( text = element_text(family = 'HersheySans'), plot.title = element_text(hjust = 0.5), legend.position = 'none' ) ) # # Aside on theming and scale adjustments # # Setting the theme inside the `ggiplot()` call is optional and not strictly # necessary, since the ggplot2 API allows programmatic updating of existing # plots. E.g. last_plot() + labs(caption = 'Note: Super fancy plot brought to you by ggiplot') last_plot() + theme_grey() + theme(legend.position = 'none') + scale_fill_brewer(palette = 'Set1', aesthetics = c(\"colour\", \"fill\")) #> Scale for colour is already present. #> Adding another scale for colour, which will replace the existing scale. # etc. #' @export"},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":null,"dir":"Reference","previous_headings":"","what":"Internal function for grabbing and preparing iplot data — iplot_data","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"Grabs underlying data used construct fixest::iplot, added functionality tweaks ggiplot equivalents.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"","code":"iplot_data( object, .ci_level = 0.95, .keep = NULL, .drop = NULL, .dict = fixest::getFixest_dict(), .internal.only.i = TRUE, .i.select = 1, .aggr_es = NULL, .group = \"auto\", .vcov = NULL, .cluster = NULL, .se = NULL ) coefplot_data( object, .ci_level = 0.95, .keep = NULL, .drop = NULL, .group = \"auto\", .dict = fixest::getFixest_dict(), .internal.only.i = FALSE, .i.select = 1, .aggr_es = \"none\", .vcov = NULL, .cluster = NULL, .se = NULL )"},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"object model object class fixest fixest_multi, () operator used construct interaction, set interactions. .ci_level number 0 1 indicating desired confidence level, Defaults 0.95. .keep Character vector used subset coefficients interest. Passed fixest::iplot(..., keep = .keep) take form acceptable regular expression. .drop Character vector used subset coefficients interest (complement .keep). Passed fixest::iplot(..., drop = .drop) take form acceptable regular expression. .dict dictionary (.e. named character vector logical scalar). Used changing coefficient names. Defaults values getFixest_dict(). See ?fixest::coefplot documentation information. Note: argument applies dictionary changes directly return object coefplot_data. However, ignored iplot_data, since want preserve numeric ordering potential event study plots. (imposing ordered factor create downstream problems case continuous plot features like ribbons.) Instead, dictionary replacement ggiplot deferred actual plot call applied directly labels. .internal..Logical variable used internal function handling passing coefplot/iplot. ..select Integer scalar, default 1. (gg)iplot, used select variable created () select. used several variables created . index, just try increasing numbers hopefully obtain want. Passed fixest::iplot(..., .select = ..select) .aggr_es keyword string numeric sequence indicating whether aggregated mean treatment effects subset model added column returned data frame. Passed aggr_es(..., aggregation = \"mean\"). .group list, default missing. element list reports coefficients grouped name element group name. Passed fixest::coefplot(..., group = .group). Example valid uses: group=list(group_name=\"pattern\") group=list(group_name=c(\"var_start\", \"var_end\")) group=list(group_name=1:2) See Details section ?fixest::coefplot . .vcov, .cluster, .se Alternative options adjusting standard errors model object fly. See summary.fixest details (although note \".\" period prefix ignored latter's argument documentation). Written superseding order; .cluster considered .vcov null, etc.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"data frame consisting estimate values, confidence intervals, relative x-axis positions, aesthetic information needed draw ggplot2 object.","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"function wrapper around fixest::iplot(..., .params = TRUE), various checks tweaks better facilitate plotting ggplot2 handling complex object types (e.g. lists fixest_multi models)","code":""},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"functions","dir":"Reference","previous_headings":"","what":"Functions","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"coefplot_data(): Internal function grabbing preparing coefplot data","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/reference/iplot_data.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Internal function for grabbing and preparing iplot data — iplot_data","text":"","code":"library(fixest) est_did = feols(y ~ x1 + i(period, treat, 5) | id+period, data = base_did) iplot(est_did, only.params = TRUE) # The \"base\" version #> $prms #> estimate ci_low ci_high estimate_names estimate_names_raw is_ref x id #> 1 -1.403045 -3.604020 0.7979286 1 period::1:treat FALSE 1 1 #> 2 -1.247511 -3.414542 0.9195208 2 period::2:treat FALSE 2 1 #> 3 -0.273206 -2.467576 1.9211637 3 period::3:treat FALSE 3 1 #> 4 -1.795721 -3.952502 0.3610605 4 period::4:treat FALSE 4 1 #> 5 0.000000 0.000000 0.0000000 5 period::5:treat TRUE 5 1 #> 6 0.784452 -1.254207 2.8231114 6 period::6:treat FALSE 6 1 #> 7 3.598897 1.415176 5.7826183 7 period::7:treat FALSE 7 1 #> 8 3.811766 1.338739 6.2847934 8 period::8:treat FALSE 8 1 #> 9 4.731426 2.556528 6.9063241 9 period::9:treat FALSE 9 1 #> 10 6.606229 4.384980 8.8274781 10 period::10:treat FALSE 10 1 #> y #> 1 -1.403045 #> 2 -1.247511 #> 3 -0.273206 #> 4 -1.795721 #> 5 0.000000 #> 6 0.784452 #> 7 3.598897 #> 8 3.811766 #> 9 4.731426 #> 10 6.606229 #> #> $is_iplot #> [1] TRUE #> #> $at #> [1] 1 2 3 4 5 6 7 8 9 10 #> #> $labels #> [1] 1 2 3 4 5 6 7 8 9 10 #> iplot_data(est_did) # The wrapper provided by this package #> estimate ci_low ci_high estimate_names estimate_names_raw is_ref x id #> 1 -1.403045 -3.604020 0.7979286 1 period::1:treat FALSE 1 1 #> 2 -1.247511 -3.414542 0.9195208 2 period::2:treat FALSE 2 1 #> 3 -0.273206 -2.467576 1.9211637 3 period::3:treat FALSE 3 1 #> 4 -1.795721 -3.952502 0.3610605 4 period::4:treat FALSE 4 1 #> 5 0.000000 0.000000 0.0000000 5 period::5:treat TRUE 5 1 #> 6 0.784452 -1.254207 2.8231114 6 period::6:treat FALSE 6 1 #> 7 3.598897 1.415176 5.7826183 7 period::7:treat FALSE 7 1 #> 8 3.811766 1.338739 6.2847934 8 period::8:treat FALSE 8 1 #> 9 4.731426 2.556528 6.9063241 9 period::9:treat FALSE 9 1 #> 10 6.606229 4.384980 8.8274781 10 period::10:treat FALSE 10 1 #> y lhs ci_level #> 1 -1.403045 y 0.95 #> 2 -1.247511 y 0.95 #> 3 -0.273206 y 0.95 #> 4 -1.795721 y 0.95 #> 5 0.000000 y 0.95 #> 6 0.784452 y 0.95 #> 7 3.598897 y 0.95 #> 8 3.811766 y 0.95 #> 9 4.731426 y 0.95 #> 10 6.606229 y 0.95 # Illustrative fixest_multi case, where the sample has been split by odd and # even ID numbers. est_split = feols(y ~ x1 + i(period, treat, 5) | id+period, data = base_did, split = ~id%%2) iplot(est_split, only.params = TRUE) # The \"base\" version #> $prms #> estimate ci_low ci_high x id estimate_names estimate_names_raw #> 1 1.4239576 -1.3045751 4.1524903 0.9 1 1 period::1:treat #> 2 -4.1291547 -7.4736493 -0.7846601 1.1 2 1 period::1:treat #> 3 1.6931989 -1.1969846 4.5833824 1.9 1 2 period::2:treat #> 4 -4.1353019 -7.3187406 -0.9518632 2.1 2 2 period::2:treat #> 5 3.0439521 0.2877701 5.8001340 2.9 1 3 period::3:treat #> 6 -3.4897091 -6.6219675 -0.3574507 3.1 2 3 period::3:treat #> 7 -0.8667871 -3.9007876 2.1672135 3.9 1 4 period::4:treat #> 8 -2.6458897 -5.7808659 0.4890866 4.1 2 4 period::4:treat #> 9 0.0000000 0.0000000 0.0000000 4.9 1 5 period::5:treat #> 10 0.0000000 0.0000000 0.0000000 5.1 2 5 period::5:treat #> 11 3.8181620 0.8977637 6.7385603 5.9 1 6 period::6:treat #> 12 -2.2626440 -5.0075306 0.4822427 6.1 2 6 period::6:treat #> 13 5.1642678 2.0371025 8.2914332 6.9 1 7 period::7:treat #> 14 2.0828305 -1.0531952 5.2188562 7.1 2 7 period::7:treat #> 15 5.2338735 1.9703239 8.4974231 7.9 1 8 period::8:treat #> 16 2.4826394 -1.2915459 6.2568247 8.1 2 8 period::8:treat #> 17 7.0979736 3.8974384 10.2985089 8.9 1 9 period::9:treat #> 18 2.4385390 -0.3566843 5.2337622 9.1 2 9 period::9:treat #> 19 9.5453455 6.3242498 12.7664413 9.9 1 10 period::10:treat #> 20 3.6267443 0.5712362 6.6822524 10.1 2 10 period::10:treat #> is_ref y #> 1 FALSE 1.4239576 #> 2 FALSE -4.1291547 #> 3 FALSE 1.6931989 #> 4 FALSE -4.1353019 #> 5 FALSE 3.0439521 #> 6 FALSE -3.4897091 #> 7 FALSE -0.8667871 #> 8 FALSE -2.6458897 #> 9 TRUE 0.0000000 #> 10 TRUE 0.0000000 #> 11 FALSE 3.8181620 #> 12 FALSE -2.2626440 #> 13 FALSE 5.1642678 #> 14 FALSE 2.0828305 #> 15 FALSE 5.2338735 #> 16 FALSE 2.4826394 #> 17 FALSE 7.0979736 #> 18 FALSE 2.4385390 #> 19 FALSE 9.5453455 #> 20 FALSE 3.6267443 #> #> $is_iplot #> [1] TRUE #> #> $at #> [1] 1 2 3 4 5 6 7 8 9 10 #> #> $labels #> [1] 1 2 3 4 5 6 7 8 9 10 #> iplot_data(est_split) # The wrapper provided by this package #> id estimate ci_low ci_high x #> 1 sample.var: id%%2; sample: 0 1.4239576 -1.3045751 4.1524903 1 #> 2 sample.var: id%%2; sample: 0 1.6931989 -1.1969846 4.5833824 2 #> 3 sample.var: id%%2; sample: 0 3.0439521 0.2877701 5.8001340 3 #> 4 sample.var: id%%2; sample: 0 -0.8667871 -3.9007876 2.1672135 4 #> 5 sample.var: id%%2; sample: 0 0.0000000 0.0000000 0.0000000 5 #> 6 sample.var: id%%2; sample: 0 3.8181620 0.8977637 6.7385603 6 #> 7 sample.var: id%%2; sample: 0 5.1642678 2.0371025 8.2914332 7 #> 8 sample.var: id%%2; sample: 0 5.2338735 1.9703239 8.4974231 8 #> 9 sample.var: id%%2; sample: 0 7.0979736 3.8974384 10.2985089 9 #> 10 sample.var: id%%2; sample: 0 9.5453455 6.3242498 12.7664413 10 #> 11 sample.var: id%%2; sample: 1 -4.1291547 -7.4736493 -0.7846601 1 #> 12 sample.var: id%%2; sample: 1 -4.1353019 -7.3187406 -0.9518632 2 #> 13 sample.var: id%%2; sample: 1 -3.4897091 -6.6219675 -0.3574507 3 #> 14 sample.var: id%%2; sample: 1 -2.6458897 -5.7808659 0.4890866 4 #> 15 sample.var: id%%2; sample: 1 0.0000000 0.0000000 0.0000000 5 #> 16 sample.var: id%%2; sample: 1 -2.2626440 -5.0075306 0.4822427 6 #> 17 sample.var: id%%2; sample: 1 2.0828305 -1.0531952 5.2188562 7 #> 18 sample.var: id%%2; sample: 1 2.4826394 -1.2915459 6.2568247 8 #> 19 sample.var: id%%2; sample: 1 2.4385390 -0.3566843 5.2337622 9 #> 20 sample.var: id%%2; sample: 1 3.6267443 0.5712362 6.6822524 10 #> estimate_names estimate_names_raw is_ref y lhs sample ci_level #> 1 1 period::1:treat FALSE 1.4239576 y 0 0.95 #> 2 2 period::2:treat FALSE 1.6931989 y 0 0.95 #> 3 3 period::3:treat FALSE 3.0439521 y 0 0.95 #> 4 4 period::4:treat FALSE -0.8667871 y 0 0.95 #> 5 5 period::5:treat TRUE 0.0000000 y 0 0.95 #> 6 6 period::6:treat FALSE 3.8181620 y 0 0.95 #> 7 7 period::7:treat FALSE 5.1642678 y 0 0.95 #> 8 8 period::8:treat FALSE 5.2338735 y 0 0.95 #> 9 9 period::9:treat FALSE 7.0979736 y 0 0.95 #> 10 10 period::10:treat FALSE 9.5453455 y 0 0.95 #> 11 1 period::1:treat FALSE -4.1291547 y 1 0.95 #> 12 2 period::2:treat FALSE -4.1353019 y 1 0.95 #> 13 3 period::3:treat FALSE -3.4897091 y 1 0.95 #> 14 4 period::4:treat FALSE -2.6458897 y 1 0.95 #> 15 5 period::5:treat TRUE 0.0000000 y 1 0.95 #> 16 6 period::6:treat FALSE -2.2626440 y 1 0.95 #> 17 7 period::7:treat FALSE 2.0828305 y 1 0.95 #> 18 8 period::8:treat FALSE 2.4826394 y 1 0.95 #> 19 9 period::9:treat FALSE 2.4385390 y 1 0.95 #> 20 10 period::10:treat FALSE 3.6267443 y 1 0.95"},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/news/index.html","id":"new-features-0-0-3-9001","dir":"Changelog","previous_headings":"","what":"New features","title":"ggfixest 0.0.3.9001 (development version)","text":"aggr_es function now supports numeric sequences aggregating specific subset periods, addition existing keyword strings like “pre” “post”. functionality also passes higher order plotting functions call aggr_es hood. example, ggiplot(est, aggr_eff = 6:8). (#33) Users can now adjust standard errors model objects --fly plot time, passing appropriate argument, e.g. ggcoefplot(est, vcov = \"hc1\"). --fly adjustments done via summary.fixest, effect just passing adjusted object directly, e.g. ggcoefplot(summary(est, vcov = \"hc1\")). However, may prove convenient simultaneously adjusting list multiple models, e.g.  ggcoefplot(list(est1, est2, est3), vcov = \"hc1\"). (#35)","code":""},{"path":[]},{"path":"http://grantmcdermott.com/ggiplot/news/index.html","id":"breaking-change-0-0-3","dir":"Changelog","previous_headings":"","what":"Breaking change","title":"ggfixest 0.0.3","text":"package name changed ggfixest (#29).","code":""}]