attgtToFetwfeDf | R Documentation |
att_gt()
to a dataframe suitable for fetwfe()
/ etwfe()
attgtToFetwfeDf()
reshapes and renames a panel dataset that is already
formatted for did::att_gt()
(Callaway and Sant'Anna 2021) 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.
attgtToFetwfeDf(
data,
yname,
tname,
idname,
gname,
covars = character(0),
drop_first_period_treated = TRUE,
out_names = list(time = "time_var", unit = "unit_var", treatment = "treatment",
response = "response")
)
data |
A |
yname |
Character scalar. Name of the outcome column. |
tname |
Character scalar. Name of the time variable (numeric or
integer). This becomes |
idname |
Character scalar. Name of the unit identifier. Converted to
character and returned as |
gname |
Character scalar. Name of the group variable holding the first period of treatment. Values must be 0 for never‑treated, or a positive integer representing the first treated period. |
covars |
Character vector of additional covariate column names to carry
through (default |
drop_first_period_treated |
Logical. If |
out_names |
A named list giving the column names to use in the
resulting dataframe. Defaults are |
A data.frame
with columns time
, unit
, treatment
, y
, and any
covariates requested in covars
, ready to be fed to
fetwfe()
/etwfe()
. All required columns are of the correct type:
time
is integer, unit
is character, treatment
is integer 0/1, and
y
is numeric.
Callaway, Brantly and Pedro H.C. Sant'Anna. "Difference-in- Differences with Multiple Time Periods." Journal of Econometrics, Vol. 225, No. 2, pp. 200-230, 2021. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.jeconom.2020.12.001")}, https://arxiv.org/abs/1803.09015.
## toy example ---------------------------------------------------------------
## Not run:
library(did) # provides the mpdta example dataframe
data(mpdta)
head(mpdta)
tidy_df <- attgtToFetwfeDf(
data = mpdta,
yname = "lemp",
tname = "year",
idname = "countyreal",
gname = "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.