Hello,
I am conducting a case control study where I would like to 1:1 match cases to two types of controls (cancer and healthy)
I have successfully matched my cases to cancer controls by age (within 5 years) and gender using the following syntax:
preserve
keep if group_id == 1
tempfile controls
save `controls'
restore
keep if group_id==0
rangejoin age -5 5 using `controls', by(sex)
set seed 1234
gen double shuffle = runiform()
by patientid (shuffle), sort: keep if _n==1
drop shuffle
My questions now are:
1) How do I also match the second group of healthy controls (ie. group_id==2, which no longer appears within my dataset) to my cases? Can it be done within this syntax?
2) Now that the cases and cancer controls appear paired, how do I rearrange my data so that the variables are listed in single column including both cases and cancer controls? Given that the control data now appears beside the case data with _U variables, I don't think this can be done with the reshape command.
Thanks in advance
I am conducting a case control study where I would like to 1:1 match cases to two types of controls (cancer and healthy)
I have successfully matched my cases to cancer controls by age (within 5 years) and gender using the following syntax:
preserve
keep if group_id == 1
tempfile controls
save `controls'
restore
keep if group_id==0
rangejoin age -5 5 using `controls', by(sex)
set seed 1234
gen double shuffle = runiform()
by patientid (shuffle), sort: keep if _n==1
drop shuffle
My questions now are:
1) How do I also match the second group of healthy controls (ie. group_id==2, which no longer appears within my dataset) to my cases? Can it be done within this syntax?
2) Now that the cases and cancer controls appear paired, how do I rearrange my data so that the variables are listed in single column including both cases and cancer controls? Given that the control data now appears beside the case data with _U variables, I don't think this can be done with the reshape command.
Thanks in advance
Comment