The procedure is as follows.
1. Assign the treatment variable (did) to matrix D. This locks in the treatment vector irrespective of sorting.
2. Within a loop, create a uniform random number (rand) that is used for sorting by cross section (id = cid). It takes two steps.
3. Bring back in the treatment vector D and assign it as the false treatment (did_temp1).
4. Get the rejection statistic (10%) from r(table).
5. Exit the loop and get the mean rejection rate.
Notes: y is the dependent variable. $X is a vector of regressors. year is the time dimension. I'm using Stata 15.1/MP4, but nothing here appears restricted to later versions.
Code:
mkmat did, matrix(D)
matrix R = J(100,1,.)
forv i = 1/100 {
capture drop rand
capture drop did_temp1
qui g rand = runiform()
qui bysort cid: replace rand = rand[1]
qui sort rand year
qui svmat D, names(did_temp)
qui xtreg y did_temp1 $X i.year , fe cluster(cid)
matrix R[`i',1]=el(r(table),4,1)<0.1
}
capture drop res1
svmat R, names(res)
summ res1
It could be cleaned up a bit if I could get a descriptive statistic on a column of a matrix, but I can't find anyway to do that in Stata.
0 Response to Randomized Inference for Panel Data
Post a Comment