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
Instrument set from initial period regressionHi I am running af 2sls model with panel data where I on average have 6 observation for each indivi…
Estimation of the same survival models converges sometimes and sometimes doesn'tI estimate survival models. However, the model converges sometimes and sometimes it doesn't even tho…
Cluster by firmHi- does clustering by firm has any impact on coefficient (or on Constant)? I read it reduces coeffi…
Saving first-stage F-statistic with -ivprobit, twostep-I am running -ivprobit, twostep first- and want to capture the first-stage F-statistic. The e(return…
Gravity model estimation using PPML with fixed effectsHello All, I'm trying to estimate GVC trade flows in a gravity model, using the PPML method. My dep…
Subscribe to:
Post Comments (Atom)
0 Response to Counting the number of groups in a permutation test
Post a Comment