I'm using the following STATA code for randomization
use data, clear
version 12
set seed 2846895
isid id
sort id
gen random = runiform()
bysort branch: gen st_size = _N
sort branch random
by branch: gen st_index = _n
gen treatment = 0
replace treatment = 1 if st_index <= st_size/2
My dataset has a variable branch with three categories each having 15, 15 and 14 observations. My code works fine, the only problem is that it doesn't equally divide treatment and control for my categories. Is there any way I can ensure that either my randomization returns equal treatment and control for 14 or the control group gets one more than the treatment?
Thanks!
use data, clear
version 12
set seed 2846895
isid id
sort id
gen random = runiform()
bysort branch: gen st_size = _N
sort branch random
by branch: gen st_index = _n
gen treatment = 0
replace treatment = 1 if st_index <= st_size/2
My dataset has a variable branch with three categories each having 15, 15 and 14 observations. My code works fine, the only problem is that it doesn't equally divide treatment and control for my categories. Is there any way I can ensure that either my randomization returns equal treatment and control for 14 or the control group gets one more than the treatment?
Thanks!
Comment