Title

flexpaneldid - Causal analysis of treatments with varying start dates and durations

Syntax

flexpaneldid depvar,
id(varname)
treatment(varname)
time(varname)
prepdataset(string)

statmatching(con(varlist) cat(varlist)) [ties radius(float)]

cemmatching(varname1 [(cutpoints1)] [varname2 [(cutpoints2)]...] [k2k])

outcometimerelstart(integer) outcometimerelend(integer)

[outcomedev(integer [integer]) test didmodel outcomemissing]

options

id(varname) name of the panel id variable

treatment(varname) name of the treatment variable

time(varname) name of the time variable

prepdataset(filename) filename where preprocessed dataset is stored

Distance metric
statmatching() use statistical distance function for matching

or

cemmatching() use Coarsened Exact Matching cem

Outcome development
outcometimerelstart() end of observed outcome development related to treatment start

or

outcometimerelend() end of observed outcome development related to treatment end

outcomedev(int [int]) pre treatment outcome level[development] is included in the matching

test quality tests after matching

didmodel robustness checks on standard two-way DID model

outcomemissing disables a check if depvar is observable for the defined outcome development period

Description

flexpaneldid is a Stata package for causal analysis of treatments with varying start dates and varying treatment durations within panel data with more than two observation times. It consists of two commands based on each other,
flexpaneldid_preprocessing and
flexpaneldid. In
flexpaneldid_preprocessing, the original data set is rearranged in that individual selection groups for every treated unit are created which contain all potential controls. The result of this preprocessing is a temporary dataset with information that are crucial for the use of flexpaneldid.

Based on the temporary data set,
flexpaneldid estimates the average treatment effect for the treated. For this step, different matching approaches are available. Additionally, quality and robustness checks can be conducted.

The flexpaneldid package requires the installation of the Stata ado-files psmatch2, pstest and cem, which are used in the flexpaneldid command.

If you want to be able to replicate your results you should set seed before calling flexpaneldid.

Arguments

Main

depvar variable defines the analyzed outcome; input must be numerical.

id(varname) uniquely identifies objects in the panel dataset. The variable must be an integer or string.

treatment(varname) contains the variable defining the treatment. Input must be in 0-1 format.

IMPORTANT NOTE: The variable must equal to one for the whole treatment phase. In case of repeated treatments for one unit (identified by a unique id), the repeated treatments are handled as one treatment phase.

time(varname) identifies the time information in the panel. Input must be an integer indicating an absolute time, e. g. year, month, quarter.

IMPORTANT NOTE: If the data contain only information in date-format, this information must be converted into an integer.

prepdataset(string) specifies the path where the preprocessing data set is stored. The information in this data is crucial for the use of the flexpaneldid.

Options

One of the following two options for the distance metric for matching must be selected:

statmatching(con(varlist) cat(varlist) indicates that a statistical distance function is used for matching. The variable names included in con(varlist) indicate the continuous matching variables, which must be numerical variables;
cat(varlist) contains the categorical variables, which must be integers.

The default matching algorithm is a nearest neighbor matching with replacement (and refers to psmatch2, neighbor(1) pscore(statistical distance)). Alternatively, one can chose between the options ties
and
radius(float). Option ties means that if more than one nontreated is the best partner for a treated observation, the counterfactual outcome is constructed using all nontreated with equal distance. Option radius(float) indicates that all nontreated within the defined radius are used to construct the counterfactual outcome. The defined radius must be a float number in the range between 0 and 1.

cemmatching(varname1 [(cutpoints1)] [varname2 [(cutpoints2)] ... ]) indicates that the Coarsened Exact Matching will be executed. Like in the cem command, including cutpoints for the matching variables is possible, either formats
(#integer)
or
(numlist) are allowed. Using option k2k creates matched strata with equal numbers of treated and controls.

See Blackwell et al. (2009) for more details on the cem command.

The command enables the user to define the period of outcome development that should be compared between treated and controls. (The starting point of the observed development coincides to the start of the treatment.)
One of the two options must be selected:

outcometimerelstart(integer) is a relative time specification that defines the end of the outcome development in relation to the treatment start. In case of repeated treatments, the relative time refers to the start of the first treatment.

IMPORTANT NOTE: The dimension of the parameter in parentheses depends on the dimension that is defined for time.

For example, outcometimerelstart(3) means we observe the outcome development from the individual treatment start to three years after the start of the treatment, if the dimension of the time variable is years.

outcometimerelend(integer) is a relative time specification that defines the end of the outcome development in relation to the treatment end. In case of repeated treatments, the relative time refers to the end of the last treatment.

IMPORTANT NOTE: The dimension of the parameter in parentheses depends on the dimension that is defined for time.

For example, outcometimerelend(2) means we compare the outcome development from the treatment start to two years after the treatment is finished, if the dimension of the time variable is years.

There are two possibilities for considering the pre-treatment outcome in the matching process:

outcomedev(integer) selects the level value of the outcome at a time defined in relation to the treatment start.
outcomedev(integer integer) defines the outcome development, the two integers give the start and the end of the development in relation to the treatment start.

IMPORTANT NOTES: The dimension of the parameter in parentheses depends on the dimension that is defined for time.
Both parameters are required to be integer <= 0. For example,
outcomedev(-3 -1) means the outcome development from three to one year(s) before the individual treatment starts is considered for matching, if the dimension of the time variable is years.
outcomedev(-3) considers the outcome level three years before treatment starts as additional matching variable.

test executes quality tests after matching. The tests conducted in pstest and quantile-quantile plots are presented.
Further tests are presented depending on the matching process that is selected: For
cemmatching() additionally the overall imbalance measure L1 and univariate imbalance measures are displayed. For
statmatching(), KS-tests for continuous variables and chi-square tests for the categorical variables are executed in addition.

didmodel is an option for robustness checks on the basis of a standard two-way DID model. The first model mimics the 2x2 case (two groups and two observation times) in a fixed effects model, namely the treatment start and the end of the defined period of outcome development. The second model is a canonical fixed effects DID model with standard errors allowing for intragroup correlations. The observation period is trimmed at the defined end of the outcome development. (Both models are estimated using xtreg. The exact specification of the models is given in the output.)

IMPORTANT NOTE: Since both models are based on the assumption of homogeneous effects, they should be used as robustness checks only, but not as standalone estimations.

outcomemissing disables a (default) check if the
depvar is observable for the defined period of outcome development before matching is performed. Disabling the check will result in the best control group in terms of comparability, but will reduce the sample size for the estimation.

Output

id id variable as defined in id() option

treated dummy variable, 1 if id is treated, else 0

first_treatment first treatment time of treated and it's matched control

last_treatment last treatment time of treated and it's matched control

nt_multi_select number of assignments for multiple assigned controls; for controls assigned only once, this variable contains a missing

time time variable as defined in time() option

outcome outcome variable as defined in depvar

panel_id panel identifier for internal use

post_treat_dummy dummy variable indicating the observations after treatment

post_treat_dummy_rel_time variable indicating relative time after treatment

Stored reslts

flexpaneldid saves the following in r():

Scalars

r(num_treated) number of unique treated

r(num_controls) number of unique controls

r(num_mean_matches) mean number of controls per treated

r(mean_dif_treated) mean development of depvar for the treated

r(mean_dif_controls) mean development of depvar for the controls

r(did) mean difference in depvar development between treated and controls

r(se) AI robust standard error

r(z) z-value

r(p) p-value

Strings

r(outcome_var) varname of depvar

r(estimator) estimator

r(metric) distance metric

Example

Preprocessing

. use flexpaneldid_example_data.dta, clear

. flexpaneldid_preprocessing, id(cusip) treatment(treatment) time(year) matchvars(employ stckpr rnd sales return pats_cat rndstck_cat rndflt_cat) matchtimerel(-1) matchvarsexact(sic_cat) prepdataset("preprocessed_data.dta") replace

flexpaneldid

. use flexpaneldid_example_data.dta, clear

. flexpaneldid patents, id(cusip) treatment(treatment) time(year) statmatching(con(employ stckpr rnd sales) cat(pats_cat rndstck_cat)) outcometimerelstart(3) outcomedev(-2 -1) test prepdataset("preprocessed_data.dta")

Also see

flexpaneldid_preprocessing, psmatch2, cem

Authors

Eva Dettmann, Halle Institute for Economic Research (IWH), eva.dettmann@iwh-halle.de

Alexander Giebler, Halle Institute for Economic Research (IWH), alexander.giebler@iwh-halle.de

Antje Weyh, Institute for Employment Research (IAB), antje.weyh@iab.de

References

Blackwell, M.; Iacus, S.; King, G.; Porro, G. (2009): cem: Coarsened exact matching in Stata. The Stata Journal 9 (4), pp. 524-546.

Leuven, E.; Sianesi, B. (2003): PSMATCH2: Stata module to perform full Mahalanobis and propensity score matching, common support graphing, and covariate imbalance testing. Techinical report, University of Oslo.

http://ideas.repec.org/c/boc/bocode/s432001.html

Thanks for citing the toolbox as follows

E. Dettmann, A. Giebler and A. Weyh. (2020). flexpaneldid. A Stata toolbox for causal analysis with varying treatment time and duration.

https://ideas.repec.org/p/zbw/iwhdps/32020.html