I am trying to do a permutation test with yearly panel data. The treatment variable, "treat", has 7 categories. For each year, I want to assign one of the seven treatment types to each unit. The total number of units for each year is given as "N[year]" (e.g., N2020), and I want to assign a treatment type to each 1/7 of "N[year]".
Here is my question: is there a way to tell STATA to get the number of types instead of specifying it myself as below (i.e., (N`i')/7)? Here is part of my code:
levelsof year
global yr = "`r(levels)'"
levelsof treat
global tr = "`r(levels)'"
gen treat_rs = .
gen rand = runiform()
sort year rand
gen serial = .
foreach i of global yr {
local counter = 0
foreach k of global tr {
local end = `counter' + (N`i')/7
qui replace treat_rs = `k' if (serial > `counter' & serial <= `end') & (year == `i' )
local counter = `counter' + (N`i')/7
}
}
Thanks so much!
Related Posts with Counting the number of groups in a permutation test
A little help with summary statisticsHey everyone, Firstly happy Christmas to those who celebrate it and happy holidays too! Back to th…
New version of htmlutil on SSCThanks as always to Kit Baum, a new version of the htmlutil package is now available from SSC. In St…
how to multiply 100 times in bootstrappingHello Statalist, I am currently working on 2 stage bootstrapping command. I already compute 100 y h…
New version of cprdhesutil on SSCThanks once again to Kit Baum, a new version of the cprdhesutil package is now downloadable from SSC…
Interpretation of mitesttransformHi everyone, Can anyone help me interpret the result of my postestimation below. The model estimat…
Subscribe to:
Post Comments (Atom)
0 Response to Counting the number of groups in a permutation test
Post a Comment