etwfeToFetwfeDf | R Documentation |
etwfe::etwfe()
to the format required by
fetwfe()
and fetwfe::etwfe()
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()or
etwfe()from the
fetwfe' package. In
particular, it
creates an absorbing‑state treatment dummy that equals 1 from the first treated period onward* and 0 otherwise,
(optionally) drops units that are already treated in the very first
period of the sample (because fetwfe()
removes them internally), and
returns a tidy dataframe whose column names match the arguments that
fetwfe()
/etwfe()
expect.
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")
)
data |
A long-format data.frame that you could already feed to |
yvar |
Character. Column name of the outcome (left-hand side in your |
tvar |
Character. Column name of the time variable that you pass to |
idvar |
Character. Column name of the unit identifier (the variable you would
cluster on, or pass to |
gvar |
Character. Column name of the “first treated” cohort variable passed to |
covars |
Character vector of additional covariate columns to keep (default |
drop_first_period_treated |
Logical. Should units already treated in the very first
sample period be removed? ( |
out_names |
Named list giving the column names that the returned dataframe should have.
The default ( |
A tidy data.frame
with (in this order)
time
integer,
unit
character,
treatment
integer 0/1 absorbing-state dummy,
response
numeric outcome,
any covariates requested in covars
.
Ready to pass straight to fetwfe()
or fetwfe::etwfe()
.
McDermott G (2024). etwfe: Extended Two-Way Fixed Effects. doi:10.32614/CRAN.package.etwfe \Sexpr[results=rd]{tools:::Rd_expr_doi("10.32614/CRAN.package.etwfe")}, R package version 0.5.0, https://CRAN.R-project.org/package=etwfe.
## 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.