etwfeToFetwfeDf {fetwfe}R Documentation

Convert data prepared for etwfe::etwfe() to the format required by fetwfe() and fetwfe::etwfe()

Description

etwfeToFetwfeDf() reshapes and renames a panel dataset that is already formatted for etwfe::etwfe() (McDermott 2024) so that it can be passed directly to fetwfe()oretwfe()⁠from the⁠fetwfe' package. In particular, it

Usage

etwfeToFetwfeDf(
  data,
  yvar,
  tvar,
  idvar,
  gvar,
  covars = character(0),
  drop_first_period_treated = TRUE,
  out_names = list(time = "time_var", unit = "unit_var", treatment = "treatment",
    response = "response")
)

Arguments

data

A long-format data.frame that you could already feed to etwfe().

yvar

Character. Column name of the outcome (left-hand side in your fml).

tvar

Character. Column name of the time variable that you pass to etwfe() as tvar.

idvar

Character. Column name of the unit identifier (the variable you would cluster on, or pass to etwfe(..., ivar = idvar) if you were using unit FEs).

gvar

Character. Column name of the “first treated” cohort variable passed to etwfe() as gvar. Must be 0 for never-treated units, or the (strictly positive) first treated period.

covars

Character vector of additional covariate columns to keep (default character(0)).

drop_first_period_treated

Logical. Should units already treated in the very first sample period be removed? (fetwfe() will drop them internally anyway, but doing it here keeps the returned dataframe clean.) Default TRUE.

out_names

Named list giving the column names that the returned dataframe should have. The default (time, unit, treatment, y) matches the arguments usually supplied to fetwfe(). Do not change the names of this list – only the values – and keep all four.

Value

A tidy data.frame with (in this order)

References

McDermott G (2024). etwfe: Extended Two-Way Fixed Effects. doi:10.32614/CRAN.package.etwfe doi:10.32614/CRAN.package.etwfe, R package version 0.5.0, https://CRAN.R-project.org/package=etwfe.

Examples

## toy example ---------------------------------------------------------------
## Not run: 
library(did)  # provides the mpdta example dataframe
data(mpdta)

head(mpdta)

tidy_df <- etwfeToFetwfeDf(
  data  = mpdta,
  yvar = "lemp",
  tvar = "year",
  idvar = "countyreal",
  gvar = "first.treat",
  covars = c("lpop"))

head(tidy_df)


## End(Not run)
## Now you can call fetwfe()  ------------------------------------------------
# res <- fetwfe(
#   pdata      = tidy_df,
#   time_var   = "time_var",
#   unit_var   = "unit_var",
#   treatment  = "treatment",
#   response   = "response",
#   covs       = c("lpop"))


[Package fetwfe version 1.5.0 Index]