Skip to contents

Grabs the underlying data used to construct fixest::iplot, with some added functionality and tweaks for the ggiplot equivalents.

Usage

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
)

Arguments

object

A model object of class fixest or fixest_multi, where the i() operator has been used to construct an interaction, or set of interactions.

.ci_level

A number between 0 and 1 indicating the desired confidence level, Defaults to 0.95.

.keep

Character vector used to subset the coefficients of interest. Passed down to fixest::iplot(..., keep = .keep) and should take the form of an acceptable regular expression.

.drop

Character vector used to subset the coefficients of interest (complement of .keep). Passed down to fixest::iplot(..., drop = .drop) and should take the form of an acceptable regular expression.

.dict

A dictionary (i.e. named character vector or a logical scalar). Used for changing coefficient names. Defaults to the values in getFixest_dict(). See the ?fixest::coefplot documentation for more information. Note: This argument applies dictionary changes directly to the return object for coefplot_data. However, it is ignored for iplot_data, since we want to preserve the numeric ordering for potential event study plots. (And imposing an ordered factor would create its own downstream problems in the case of continuous plot features like ribbons.) Instead, any dictionary replacement for ggiplot is deferred to the actual plot call and applied directly to the labels.

.internal.only.i

Logical variable used for some internal function handling when passing on to coefplot/iplot.

.i.select

Integer scalar, default is 1. In (gg)iplot, used to select which variable created with i() to select. Only used when there are several variables created with i. This is an index, just try increasing numbers to hopefully obtain what you want. Passed down to fixest::iplot(..., i.select = .i.select)

.aggr_es

A keyword string or numeric sequence indicating whether the aggregated mean treatment effects for some subset of the model should be added as a column to the returned data frame. Passed to aggr_es(..., aggregation = "mean").

.group

A list, default is missing. Each element of the list reports the coefficients to be grouped while the name of the element is the group name. Passed down to fixest::coefplot(..., group = .group). Example of valid uses:

  • group=list(group_name="pattern")

  • group=list(group_name=c("var_start", "var_end"))

  • group=list(group_name=1:2)

  • See the Details section of ?fixest::coefplot for more.

.vcov, .cluster, .se

Alternative options for adjusting the standard errors of the model object on the fly. See summary.fixest for details (although note that the "." period prefix should be ignored in the latter's argument documentation). Written here in superseding order; .cluster will only be considered if .vcov is not null, etc.

Value

A data frame consisting of estimate values, confidence intervals, relative x-axis positions, and other aesthetic information needed to draw a ggplot2 object.

Details

This function is a wrapper around fixest::iplot(..., only.params = TRUE), but with various checks and tweaks to better facilitate plotting with ggplot2 and handling of complex object types (e.g. lists of fixest_multi models)

Functions

  • coefplot_data(): Internal function for grabbing and preparing coefplot data

Examples

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