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
Is difference in differences appropriate here?Here is the situation: There was an intervention T. I am interested in how this intervention change…
just-identified IV with ivlasso and multiple endogenous variablesDear Statalist I would like to estimate an IV regression with a high-dimensional set of controls us…
robust ANOVA for non-normal dataDear Statalist friends, I am unexperienced with most statistical methods and Stata and I need some …
Formula to standardize a variable without "gen" and "egen"Hello, I am a French student who is starting to work with Stata 16, and I need to find a formulatio…
Convert Single String Variable to Many Binary VariablesI have a variable for U.S. states that includes 01, 02, 03, ... , 50, 51, and these are all strings …
Subscribe to:
Post Comments (Atom)
0 Response to Counting the number of groups in a permutation test
Post a Comment