View source: R/twowayfeweights.R
twowayfeweights | R Documentation |
Estimates the weights and measure of robustness to treatment effect heterogeneity attached to two-way fixed effects regressions.
twowayfeweights(
data,
Y,
G,
T,
D,
type = c("feTR", "feS", "fdTR", "fdS"),
D0 = NULL,
summary_measures = FALSE,
controls = NULL,
weights = NULL,
other_treatments = NULL,
test_random_weights = NULL,
path = NULL
)
data |
A data frame or data matrix. |
Y |
Character string. The dependent variable in the regression. Y is the level of the outcome if one wants to estimate the weights attached to the fixed-effects regression, and Y is the first difference of the outcome if one wants to estimate the weights attached to the first-difference regression. Required. |
G |
Character string. The variable identifying each group. Required. |
T |
Character string. The variable identifying each period. Required. |
D |
Character string. The treatment variable in the regression. D is the level of the treatment if one wants to estimate the weights attached to the fixed-effects regression, and D is the first difference of the treatment if one wants to estimate the weights attached to the first-difference regression. Required. |
type |
Character string. The type of estimation strategy. Can take one of four different values, each defining a unique combination of regression strategy (either fixed-effects or first-difference) and inference assumption (either common trends on its own or common trends plus an additional assumption about treatment stability over time).
|
D0 |
Character string. If |
summary_measures |
Logical. Should the complementary results from the computation of the weights be displayed? Specifically, the option outputs: (i) the point estimate of the coefficient on the D variable from a TWFE regression, (ii) the minimum value of the standard deviation of the ATEs compatible with the coefficient from the TWFE regression and ATE across all treated (g,t) cells being equal to zero, (iii) the minimum value of the standard deviation of the ATEs compatible with the coefficient from the TWFE regression and ATE across all treated (g,t) cells having different signs (this is computed only if the sum of negative weights is different from 0). See the FAQ section for other details. |
controls |
Character string(s). An optional vector of control variables that are included in the regression. Controls should not vary within each groupperiod cell, because the results in in de Chaisemartin & D'Haultfoeuille (2020a) apply to two-way fixed effects regressions with group×period level controls. If a control does vary within a group×period cell, the command will replace it by its average value within each groupperiod cell. |
weights |
Character string. Specifies a column name in the input data
that replaces the default weighting scheme. If the regression is weighted,
the weight variable can be specified in weight. If |
other_treatments |
Character string(s). An optional vector of other
treatment variables that are included in the regression. Note that this
option can only be used when |
test_random_weights |
Character string(s). An optional vector that, when specified, will cause the function to estimate the correlation between each variable in the vector and the weights. Testing if those correlations significantly differ from zero is a way to assess whether the weights are as good as randomly assigned to groups and time periods. |
path |
File path for saving the results in a valid csv file that containing 3 variables (Group, Time, Weight). This option allows the user to see the weight attached to each group*time cell. If the other_treatments option is specified, the weights attached to the other treatments are also saved. |
This function estimates the weights attached to the two-way fixed effects regressions studied in de Chaisemartin & D'Haultfoeuille (2020a), as well as summary measures of these regressions' robustness to heterogeneous treatment effects.
A list object with an additional "twowayfeweights" class attribute to enable bespoke print (and other) methods. Included among the slots of the returned list object is a data frame containing the weights attached to each group*time cell.
Q. How can one interpret the summary measures of the regression's robustness to heterogeneous treatment effects?
When the two-way fixed effects regression has only one treatment variable, the command reports two summary measures of the robustness of the treatment coefficient beta to treatment heterogeneity across groups and over time. The first one is defined in point (i) of Corollary 1 in de Chaisemartin & D'Haultfoeuille (2020a). It corresponds to the minimal value of the standard deviation of the treatment effect across the treated groups and time periods under which beta and the average treatment effect on the treated (ATT) could be of opposite signs. When that number is large, this means that beta and the ATT can only be of opposite signs if there is a lot of treatment effect heterogeneity across groups and time periods. When that number is low, this means that beta and the ATT can be of opposite signs even if there is not a lot of treatment effect heterogeneity across groups and time periods. The second summary measure is defined in point (ii) of Corollary 1 in de Chaisemartin & D'Haultfoeuille (2020a). It corresponds to the minimal value of the standard deviation of the treatment effect across the treated groups and time periods under which beta could be of a different sign than the treatment effect in all the treated group and time periods.
Q. How can I tell if the first summary measure is high or low?
Assume that the first summary measure is equal to x. How can you tell if x is a low or a high amount of treatment effect heterogeneity? This is not an easy question to answer, but here is one possibility. Let us assume that the treatment effects of (g,t) cells are drawn from a uniform distribution. Then, to have that the mean of that distribution is 0 while its standard deviation is x, the treatment effects should be uniformly distributed on the [-sqrt(3)x,sqrt(3)x]
interval. Then, you can ask yourself: is it reasonable to assume that some (g,t) cells have a treatment effect as large as sqrt(3)x
, while other cells have a treatment effect as low as -sqrt(3)x
? If the answer is negative (you think that it is not reasonable to assume that the treatment effect will exceed the +/-sqrt(3)x
bounds for some (g,t) cells), this means that the uniform distribution of treatment effects compatible with an ATT of 0 and a standard deviation of x seems implausible to you. Then, you can consider that the command's first summary measure is high, and that it is unlikely that beta and the ATT are of a different sign. Conversely, if the answer is positive (you believe that the treatment effect might exceed the bounds for some (g,t) cells), it may not be unlikely that beta and the ATT are of a different sign.
The previous sensitivity exercise assumes that treatment effects follow a uniform distribution. You may find it more reasonable to assume that they are, say, normally distributed. Then you can conduct the following, similar exercise. If the treatment effects of (g,t) cells are drawn from a normal distribution with mean 0 and standard deviation x normal distribution, 95\
Q. How can I tell if the second summary measure is high or low?
Assume that the second summary measure is equal to x. To fix ideas, let us assume that beta>0. Let us assume that the treatment effects of (g,t) cells are drawn from a uniform distribution. Then, one could have that those effects are all negative, with a standard deviation equal to x, for instance if they are uniformly drawn from the [-2sqrt(3)x,0]
. Then, you can ask yourself: is it reasonable to assume that some (g,t) cells have a treatment effect as low as -2sqrt(3)x
? If the answer is negative (you are not willing to assume that some (g,t) cells have a treatment effect lower than -2sqrt(3)x)
, this means that the uniform distribution of treatment effects compatible with sign reversal and a standard deviation of x seems implausible to you. Then, you can consider that the command's second summary measure is high, and that sign reversal is unlikely. If the treatment effects of (g,t) cells are all negative, they cannot follow a normal distribution, so we do not discuss that possibility here.
de Chaisemartin, C and D'Haultfoeuille, X (2020a). American Economic Review, vol. 110, no. 9. Two-Way Fixed Effects Estimators with Heterogeneous Treatment Effects.
de Chaisemartin, C and D'Haultfoeuille, X (2020b). Two-way fixed effects regressions with several treatments.
# The following example is based on data from F. Vella and M. Verbeek (1998),
# "Whose Wages Do Unions Raise? A Dynamic Model of Unionism and Wage Rate
# Determination for Young Men".
# Results and further details about the estimation below can be found in
# Section V.C of de Chaisemartin & D'Haultfoeuille (2020a).
# Run the following lines to download the dataset in your local working
# directory and load it to your R environment:
repo = "chaisemartinPackages/twowayfeweights/main"
file = "wagepan_twfeweights.dta"
url = paste("https://raw.githubusercontent.com", repo, file, sep = "/")
wagepan = haven::read_dta(url)
# The default `type = "feTR"` estimation strategy uses a fixed-effects
# strategy under the assumption that parallel trends holds.
twowayfeweights(
wagepan, # input data
"lwage", "nr", "year", "union", # Y, G, T, & D
type = "feTR", # estimation type ("feTR" is the default)
summary_measures = TRUE, # show summary measures (optional)
test_random_weights = "educ" # check randonmess of weights (optional)
)
# The next line performs the same exercise using first differences of outcome
# and treatment:
twowayfeweights(
wagepan,
"diff_lwage", "nr", "year", "diff_union", # Y & D changed to differenced versions
type = "fdTR", # changed
D0 = "union", # added (D0 is req'd for type="fdTR")
summary_measures = TRUE,
test_random_weights = "educ"
)
# Please note that the number of negative weights could be different from Section
# V.C. of de Chaisemartin and D'Haultfoeuille (2020a) due to rounding errors that
# affected older versions of the commands.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.