Curiously, in the almost 20 year use of -ralloc- nobody has ever asked me this.
First, the combination of the treatment allocation file and a patient file was never in the scope of -ralloc-. (However strange that may sound.)
Second, the example file -raltest6.dta- is used by -ralloc- to set the design paramters of the treatment allocation file. It has nothing (directly) to do with patients.
To do what Gaby wishes requires a merging of the -ralloc- produced treatment allocation file and a patient list in, presumably, another stata .dta file. If there are no strata involved, then a straightforward 1:1 sequential merge should do it, with the treatment file as the master file and the patient file as the using file. But I suspect that Gaby will have strata defined, say, hospital and/or agegroup and/or sex.
A challenge here is that we would like to -merge- on the stratum identifiers but this requires a sort on those variables and this will almost certainly disrupt the original treatment allocation order (defined by blocks and sequence within blocks). I believe the best way to cope with this is to disaggregate both the treatment file and the patient file into stratum specific files. As far as the treatment file goes, -ralloc- will do this automatically with the -multif- option. It is not hard to do this with a patient file.
To demonstrate how a scheme might work I offer the following code, based on a small data set.
Code:
/* assume, just as an example:
randomisation schema file is raltest_x.dta
aggregated random treatment allocation file will be randomRx.dta
there are 2 stratum variables (centre and agegrp, with 3 and 2 strata resp.)
stratum specific random allocation files (3x2=6) are produced by ralloc
ralloc command is: ralloc b s t, saving(randomRx) using(raltest_x)
count(freq) idvar(RxID) multif
aggregated patient file name is patient_list.dta
each observation in data file patient_list.dta will have a unique
patient name or identifier and that patient's stratum value(s).
The stratum variable names must be the same as those in the random
treatment allocation file produced by -ralloc-, here, centre and agegrp.
stratum specific patient files will be named pat_list_i_j.dta
*/
** create raltest_x.dta with 3 centres and 2 age groups **
clear
input byte(centre agegrp freq)
1 1 4
1 2 6
2 1 4
2 2 7
3 1 3
3 2 4
end
save raltext_x, replace
** run -ralloc- and create stratum-specific treatment allocation files **
ralloc b s t, saving(randomRx) using(raltest_x) count(freq) idvar(RxID) multif
** create patient_list.dta **
clear
input byte(centre agegrp) str6 name
1 1 "Jim"
1 2 "Mary"
1 1 "Bob"
1 1 "Claire"
2 1 "Tim"
2 2 "Debbie"
3 2 "Claude"
3 1 "Kevin"
3 2 "Dave"
3 1 "Ben"
end
save patient_list, replace
** make some local macros (one for each stratum variable in the patient file) **
summ centre, meanonly
local max_cent = r(max)
summ agegrp, meanonly
local max_age = r(max)
** Make stratum specific data files from the original aggregated patient file **
clear
forvalues i=1/`max_cent' {
forvalues j=1/`max_age' {
use patient_list, clear
d
keep if centre==`i' & agegrp==`j'
l
save pat_`i'_`j', replace
}
}
** merge each stratum specific patient file with its matching treatment file **
** use a sequential merge - original order of observations in randomRx files **
** must NOT be altered by any -merge- that requires a =sort- **
forvalues i=1/`max_cent' {
forvalues j=1/`max_age' {
use randomRx_`i'_`j'
merge 1:1 _n using pat_`i'_`j'
save ranpat_`i'_`j', replace
}
}
** append the stratum specific files back into one aggregated file**
clear
forvalues i=1/`max_cent' {
forvalues j=1/`max_age' {
append using ranpat_`i'_`j'
save ranpat_all, replace
}
}
** now be certain the original allocation sequence has been preserved **
sort b Seq
list
** and you may wish eventually to: -keep if _merge==3-
