*! version 1.0 16 Jun 2023
help xtrantreat

Title

xtrantreat -- randomizing a treatment variable in a panel dataset

Syntax

xtrantreat varname , method({1|2|3}) [id(panelvar) time(timevar) ranunitnum(int) rantimescope(t_min t_max) generate(newvar)]

Description

xtrantreat randomizes a treatment variable (a dummy variable specifed by varname) in a panel dataset.
A typical scenario of application is in implementing mixed placebo test for difference-in-differences (DID) models. xtrantreat converts a treatment variable to a fake treatment variable where both treatment units and times are randomized.
The random assignment process can be specified by the options ranunitnum(int), rantimescope(t_min t_max) and method({1|2|3}),
where method({1|2|3}) corresponds to three different ways of randomizing the treatment variable.

Options

id(panelvar) specifies panelvar as the panel variable of the dataset, which is used to identify the units (individuals) in the panel dataset.
If id(panelvar) is not specified, xtset must be used to declear a panel variable before implementing xtrantreat.

time(timevar) specifies timevar as the time variable of the panel dataset.
If time(timevar) is not specified, xtset must be used to declear a time variable before implementing xtrantreat.

ranunitnum(int) specifies the number of units randomly selected as fake treatment units.
If ranunitnum(int) is not specified, int defaults to the actual number of treatment units in the sample.
All units in the sample have the same probability of being randomly selected as fake treatment units.

rantimescope(t_min t_max) specifies the range within which fake treatment times are randomly selected.
All periods within the range of t_min to t_max have the same probability of being randomly assigned as a fake treatment time via a uniform distribution on this range.

For the standard DID design, if rantimescope(t_min t_max) is not specified, t_min and t_max default to the second period and the last period in the sample respectively.

For the staggered DID design, if rantimescope(t_min t_max) is not specified, t_min defaults to the earliest treatment time (or the first period in the sample, whichever is larger), and t_max defaults to the latest treatment time in the sample. Another possible choice is for users to set t_min and t_max as the first period and the last period in the sample respectively.

method({1|2|3}) specifies one of the following three methods for generating the fake treatment variable.

method(1) is suitable for implementing mixed placebo test for standard DID models with synchronized adoption.
Using method(1), a certain number of fake treatment units is randomly selected, which are then assigned a same fake treatment time randomly chosen.
The number of fake treatment units and the range of fake treatment times are specified by the options ranunitnum(int) and rantimescope(t_min t_max) respectively.

method(2) and method(3) are suitable for implementing mixed placebo test for staggered DID models with staggered adoption, where 2 and 3 correponds to the unrestricted version and the restricted version, respectively.
method(2) (the unrestricted version) randomly selects a fake treatment time for each unit, without maintaining the original cohort structure (i.e., how many units in each cohort).
The number of fake treatment units and the range of fake treatment times are specified by the options ranunitnum(int) and rantimescope(t_min t_max) respectively.
On the other hand, method(3) (the restricted version) maintains the cohort structure. Specifically, suppose the treatment times in the sample consist of t_1, t_2,...,t_G, and the correponding cohorts contain N_1, N_2,...,N_G units respectively.
We randomly partition all units in the sample into G cohorts containing N_1, N_2,...,N_G units respectively, then randomly assign G different treatment times from rantimescope(t_min t_max) to these cohorts as their fake treatment times.
Note that the range of fake treatment times specified by the options rantimescope(t_min t_max) must be greater than or equal to the number of periods in the actual treatment variable.

generate(newvar) specifies a new variable named newvar to store the transformed version of varname. If generate(newvar) is not specified, the transformed version of varname will replace the original varname.

Example: the impact of bank deregulation on income inequality (Beck et al., 2010)

. use bbb.dta, clear

. xtset statefip wrkyr

. global cov gsp_pc_growth prop_blacks prop_dropouts prop_female_headed unemploymentrate

. xtreg log_gini _intra $cov i.wrkyr, fe r

. local tr_eff = _b[_intra]

. capture program drop InSpacePlaceboTest

. program define InSpacePlaceboTest, rclass

. preserve

. xtrantreat _intra, method(2)

. xtreg log_gini _intra $cov i.wrkyr, fe r

. return scalar pbo_eff = _b[_intra]

. end

. simulate pbo_eff = r(pbo_eff), seed(1) reps(500): InSpacePlaceboTest

. graph twoway (histogram pbo_eff) (kdensity pbo_eff)

Resources

didplacebo implements placebo tests for estimating difference-in-differences (DID) models

xtshuffle shuffles a variable in a panel dataset blockwise along the dimension of the panel variable

tofirsttreat converts a treatment variable in a panel dataset from a dummy variable to a variable specifying the first treatment period

Reference

Beck, T., Levine, R., and Levkov, A. 2010. Big bad banks? The winners and losers from bank deregulation in the United States. Journal of Finance 65(5): 1637-1667.

Chen, Q., Qi, J., and Yan, G. 2023. didplacebo: Implementing placebo tests for difference-in-differences estimations. Shandong University working paper.

Author

Qiang Chen, Shandong University, CN

www.econometrics-stata.com

qiang2chen2@126.com

Ji Qi, Shandong University, CN

miracle4556@163.com

Guanpeng Yan (correponding author), Shandong University of Finance and Economics, CN

guanpengyan@yeah.net