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
Weighted adjacency matrixHi all, I am struggling with something similar to the original poster. I am using Stata 15 and have …
Can I run a Pseudo-Poisson Maximum Likelihood in panel data when not using a Gravity Model? What is the STATA command?I want to run the Pseudo-Poisson Maximum Likelihood (PPML) in a panel data framework as my dependent…
Calculating the expected return of Eurostoxx 50 with STATA (Event Study)Hello everyone, currently I am working on an event study with the Eurostoxx 50 Index as underlying m…
How can I get return list of estat endogenous after a 2sls?Hello,everyone.I want to define results of extat endogenous to be a local.But I find that I can't ge…
How to test whether difference in differences is statistically significant without regression?Dear all, I have two groups and have tested whether the mean of my variable of interest is signific…
Subscribe to:
Post Comments (Atom)
0 Response to Counting the number of groups in a permutation test
Post a Comment