Hi all,
i am new to this and i need to know if the commands i am using are correct to continue with the study
.
what i am trying to do is to do the randomization for some nurseries from different governorates. I should be randomizing the list of nurseries by infrastructure (whether the nursery has a kitchen or not) and by size (total number of children). this is the code i wrote:
xtile nursery_size = total_children, n(3) // assigning tertiles of nursery size
egen strata = group(nursery_size kitchen_binary )
gen nursery_id = _n // _n = the row number of the nursery in the dataset
set seed 9450 // setting the seed for reproducibility based on the timing now
gen rand = runiform() //shuffling the list before the group assignment
sort strata rand // nurseries wihtin the same stratum stay together but they are shuffled randomly within the stratum. //assigning 15 nurseries per treatment arm within each stratum. each treatment group is assigned based on the nursery's position (_n) in each stratum relative to the total number (_N) of nurseries in each stratum.
gen treatment_group = .
bysort strata (rand): replace treatment_group = 1 if _n <= _N/4 // Fortified sandwich (first 25%)
bysort strata (rand): replace treatment_group = 2 if _n > _N/4 & _n <= _N/2 // Fortified sandwich + BCC (in first half but not first 25%)
bysort strata (rand): replace treatment_group = 3 if _n > _N/2 & _n <= 3*_N/4 // Hot meals (between 50% and 75% of the stratum)
bysort strata (rand): replace treatment_group = 0 if _n > 3*_N/4 // Control (last 25%)
drop rand
does this code make any sense? or should it be edited? would highly appreciate it if someone can help
i am new to this and i need to know if the commands i am using are correct to continue with the study

what i am trying to do is to do the randomization for some nurseries from different governorates. I should be randomizing the list of nurseries by infrastructure (whether the nursery has a kitchen or not) and by size (total number of children). this is the code i wrote:
xtile nursery_size = total_children, n(3) // assigning tertiles of nursery size
egen strata = group(nursery_size kitchen_binary )
gen nursery_id = _n // _n = the row number of the nursery in the dataset
set seed 9450 // setting the seed for reproducibility based on the timing now
gen rand = runiform() //shuffling the list before the group assignment
sort strata rand // nurseries wihtin the same stratum stay together but they are shuffled randomly within the stratum. //assigning 15 nurseries per treatment arm within each stratum. each treatment group is assigned based on the nursery's position (_n) in each stratum relative to the total number (_N) of nurseries in each stratum.
gen treatment_group = .
bysort strata (rand): replace treatment_group = 1 if _n <= _N/4 // Fortified sandwich (first 25%)
bysort strata (rand): replace treatment_group = 2 if _n > _N/4 & _n <= _N/2 // Fortified sandwich + BCC (in first half but not first 25%)
bysort strata (rand): replace treatment_group = 3 if _n > _N/2 & _n <= 3*_N/4 // Hot meals (between 50% and 75% of the stratum)
bysort strata (rand): replace treatment_group = 0 if _n > 3*_N/4 // Control (last 25%)
drop rand
does this code make any sense? or should it be edited? would highly appreciate it if someone can help
Comment