*! version 1.0 16 Jun 2023
help xtshuffle

Title

xtshuffle -- shuffling a variable in a panel dataset blockwise along the dimension of panel variable

Syntax

xtshuffle varname [, id(panelvar) time(timevar) generate(newvarname)]

Description

xtshuffle shuffles the variable varname in a panel dataset blockwise along the dimension of panel variable.
A typical scenario of application is in implementing in-space placebo test for difference-in-differences (DID) models.
In that case, the treatment variable is randomly shuffled blockwise to generate fake treatment units, whereas the treatment times are kept the same.
Note that xtshuffle is applicable to both the standard DID design with synchronized adoption and the staggered DID design with staggered adoption.

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

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

generate(newvarname) specifies a new variable named newvarname to store the shuffled version of varname.
If generate(newvarname) is not specified, the shuffled version of varname replaces 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

. xtshuffle _intra

. 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

xtrantreat randomizes a treatment variable in a panel dataset

tofirsttreat converts a treatment variable 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