Twowayfeweights
|| Stata | R || 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.
Install / Use
/learn @Credible-Answers/TwowayfeweightsREADME
twowayfeweights
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.
Setup
Stata (SSC):
ssc install twowayfeweights, replace
R (CRAN):
install.packages("TwoWayFEWeights")
Vignettes
Syntax
Stata:
twowayfeweights Y G T D [D0], type(string)
[summary_measures test_random_weights(varlist)
controls(varlist) other_treatments(varlist) weight(varlist) path(string)]
R:
twowayfeweights(df, Y, G, T, D, D0 = NULL, type, summary_measures = NULL,
controls = c(), weights = NULL, other_treatments = c(), test_random_weights = c(), path = NULL)
Description
- Y is 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.
- G is a variable identifying each group.
- T is a variable identifying each period.
- D is 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.
- If type(fdTR) is specified in the option type below, then the command requires a fifth argument, D0. D0 is the mean of the treatment in group g and at period t. It should be non-missing at the first period when a group appears in the data (e.g. at t=1 for the groups that are in the data from the beginning), and for all observations for which the first-difference of the group-level mean outcome and treatment are non missing.
Options
- type is a required option that can take four values: feTR, feS, fdTR, fdS. If feTR is specified, the command estimates the weights and sensitivity measures attached to the fixed-effects regression under the common trends assumption. With feS, it estimates the weights and sensitivity measures attached to the fixed-effects regression under common trends and the assumption that groups’ treatment effect does not change over time. With fdTR, it estimates the weights and sensitivity measures attached to the first-difference regression under the common trends assumption. Finally, with fdS it estimates the weights and sensitivity measures attached to the first-difference regression under common trends and the assumption that groups’ treatment effect does not change over time.
- summary_measures displays complementary results from the computation of the weights. 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.
- test_random_weights when this option is specified, the command estimates the correlation between each variable in varlist 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. When other_treatments is specified, the command only reports the correlation between each variable and the weights attached to the main treatment, not the correlations between each variable and the contamination weights attached to the other treatments.
- controls is a list of control variables that are included in the regression. Controls should not vary within each group x period cell, because the results in in de Chaisemartin & D’Haultfoeuille (2020a) apply to two-way fixed effects regressions with group x period level controls. If a control does vary within a group x period cell, the command will replace it by its average value within each group x period cell.
- other_treatments is a list of other treatment variables that are included in the regression. While the results in de Chaisemartin & D’Haultfoeuille (2020a) do not cover two-way fixed effects regressions with several treatments, those in de Chaisemartin & D’Haultfoeuille (2020b) do, so the command follows results from that second paper when other_treatments is specified. This option can only be used when type(feTR) is specified. When it is specified, the command reports the number and sum of positive and negative weights attached to the treatment, but it does not report the summary measures of the regression’s robustness to heterogeneous treatment effects, as these summary measures are no longer applicable when the regression has several treatment variables. The command also reports the weights attached to the other treatments. The weights reported by the command are those in Corollary 1 in de Chaisemartin & D’Haultfoeuille (2020b). See de Chaisemartin & D’Haultfoeuille (2020b) for further details.
- weight: if the regression is weighted, the weight variable can be specified in weight. If type(fdTR) is specified, then the weight variable should be non-missing at the first period when a group appears in the data (e.g. at t=1 for the groups that are in the data from the beginning), and for all observations for which the first-difference of the group-level mean outcome and treatment are non missing.
- path allows the user to specify a path (e.g D:.dta) where a .dta file containing 3 variables (Group, Time, Weight) will be saved. This option allows the user to see the weight attached to each group x time cell. If the other_treatments option is specified, the weights attached to the other treatments are also saved in the .dta file.
FAQ
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.
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, that is, 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, that is, you believe that t
