Documentation

Documentation for TwoWayFEWeights.jl

TwoWayFEWeights.twowayfeweightsMethod

Estimation of the weights attached to the two-way fixed effects regressions.

Estimates the weights and measure of robustness to treatment effect heterogeneity attached to two-way fixed effects regressions.

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.

Returns an object of type "twowayfeweights", which is a wrapper of the OrderedCollections.OrderedDict type. This wrapper allows for a custom Base.show() method. Included among the slots of the returned list object is a data frame containing the weights attached to each group*time cell.

Arguments

  • 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).

    • "feTR" (the default): Fixed-effects regression under the common trends assumption.
    • "feS": Fixed-effects regression under common trends and the assumption that groups' treatment effect does not change over time.
    • "fdTR": First-difference regression under the common trends assumption.
    • "fdS": First-difference regression under common trends and the assumption that groups' treatment effect does not change over time.
  • D0 Character string. If type = "fdTR" is specified above, then the function 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.

  • 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 of the original R package 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.

  • 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 type = "feTR" is specified above. 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. 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.

  • 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 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.

  • 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.

source
Base.showMethod

A print method for twowayfeweights objects. Printed display of twowayfeweights objects.

For the definition of the twowayfeweights struct, go see "twowayfeweights_struct".
source
TwoWayFEWeights.fn_ctrl_renameMethod
fn_ctrl_rename(x)

Rename variables by writing "ctrl" at their beginning. The `fnctrlrenamefunction is the equivalent of the originalfnctrlrename` function, defined in the original R code such as: fnctrlrename <- function(x) paste("ctrl", x, sep="")

source
TwoWayFEWeights.fn_random_weight_renameMethod
fn_random_weight_rename(x)

Rename a vector of variables by putting "RW" in front of them. The `fnrandomweightrenamefunction is the equivalent of the originalfnrandomweightrename` function, defined in the original R code such as: fnrandomweightrename <- function(x) paste("RW", x, sep="_")

source
TwoWayFEWeights.fn_treatment_weight_renameMethod
fn_treatment_weight_rename(x)

Rename a vector of variables by putting "weight" in front of them. The `fntreatmentweightrenamefunction is the equivalent of the originalfntreatmentweightrename` function, defined in the original R code such as: fntreatmentweightrename <- function(x) paste("weight_", x, sep = "")

source
TwoWayFEWeights.get_controls_renameMethod
get_controls_rename(controls)

Rename a vector of variable names by writing "ctrl" in front of them. The `getcontrolsrenamefunction is the equivalent of the originalgetcontrolsrename` function, defined in the original R code as: getcontrolsrename <- function(controls) unlist(lapply(controls, fnctrl_rename))

source
TwoWayFEWeights.get_random_weight_renameMethod
get_random_weight_rename(x)

Rename a vector of variables by putting "RW" in front of them. The `fnrandomweightrenamefunction is the equivalent of the originalfnrandomweightrename` function, defined in the original R code such as: # getrandomweightrename <- function(ws) unlist(lapply(ws, fnrandomweight_rename))

source
TwoWayFEWeights.get_treatments_renameMethod
get_treatments_rename(treatments)

Rename a vector of variables by putting "OT" in front of them. The `gettreatmentsrenamefunction is the equivalent of the originalgettreatmentsrename` function, defined in the original R code such as: gettreatmentsrename <- function(treatments) {unlist(lapply(treatments, fntreatment_rename))}

source
TwoWayFEWeights.twowayfeweights_resultMethod

Internal workhorse function for creating the return object of a twowayfeweights() call.

@param dat A data frame, as per the return object from twowayfeweights_calculate(). @param beta Coefficient value of the treatment variable ("D"), again as per the return object of twowayfeweights_calculate(). @param controls A vector indicating the column names of random weights. @param treatments A vector indicating the column names of other treatments. @returns A list. @details This function is normally run directly after twowayfeweights_calculate(). @importFrom magrittr %>% @noRd

source
TwoWayFEWeights.twowayfeweights_transformMethod

function twowayfeweights_transform(; df::DataFrames.DataFrame, controls::Union{String, Vector{String}}, weights::Union{String, Vector{String}, Nothing}, treatments::Union{String, Vector{String}, Nothing})

Internal function.

source