I have performed age-sex matched case-control study with 1:2 ratio. However, I have a problem facing with matching. I have performed the following but could not get the result
se "D:\Academics\Research\Cardio metabolic risk factor\cardio-metabolic.dta", clear
set seed 1234 // OR YOUR FAVORITE SEED
// GENERATE AGE GROUPS (MODIFY LIMITS AS APPROPRIATE TO DATA)
gen byte age_group = 1 if inrange(age, 18, 23)
replace age_group = 2 if inrange(age, 24, 29)
replace age_group = 3 if inrange(age, 30, 35)
replace age_group = 4 if inrange(age, 36, 41)
replace age_group = 5 if inrange(age, 42, 47)
replace age_group = 6 if inrange(age, 48, 53)
replace age_group = 7 if inrange(age, 54, 59)
replace age_group = 8 if inrange(age, 60, 65)
replace age_group = 9 if inrange(age, 66, 71)
replace age_group = 10 if inrange(age, 72, 77)
replace age_group = 11 if inrange(age, 77, .)
gen double shuffle = runiform() // TO RANDOMIZE MATCH SELECTIONS
// FORM A FILE OF CONTROLS ONLY
preserve
keep if case_control==0
// ASSIGN A PRIORITY FOR MATCHING WITHIN EACH AGE_GROUP SEX COMBINATION
// IN BATCHES OF (UP TO) FOUR
rename gender sex
by age_group sex (shuffle), sort: gen int priority = floor((_n-1)/2) + 1
drop shuffle
// RENAME VARIABLES TO AVOID CLASH
rename * control_*
foreach x in age_group sex priority {
rename control_`x' `x'
}
tempfile controls
save `controls'
// NOW MAKE A FILE OF CASES
restore
keep if case_control==1
// AGAIN PRIORITIZE FOR MATCHING
rename gender sex
by age_group sex (shuffle), sort: gen int priority = _n
drop shuffle
// MERGE WITH CONTROLS
merge 1:m age_group sex priority using `controls', keep(master match)
se "D:\Academics\Research\Cardio metabolic risk factor\cardio-metabolic.dta", clear
set seed 1234 // OR YOUR FAVORITE SEED
// GENERATE AGE GROUPS (MODIFY LIMITS AS APPROPRIATE TO DATA)
gen byte age_group = 1 if inrange(age, 18, 23)
replace age_group = 2 if inrange(age, 24, 29)
replace age_group = 3 if inrange(age, 30, 35)
replace age_group = 4 if inrange(age, 36, 41)
replace age_group = 5 if inrange(age, 42, 47)
replace age_group = 6 if inrange(age, 48, 53)
replace age_group = 7 if inrange(age, 54, 59)
replace age_group = 8 if inrange(age, 60, 65)
replace age_group = 9 if inrange(age, 66, 71)
replace age_group = 10 if inrange(age, 72, 77)
replace age_group = 11 if inrange(age, 77, .)
gen double shuffle = runiform() // TO RANDOMIZE MATCH SELECTIONS
// FORM A FILE OF CONTROLS ONLY
preserve
keep if case_control==0
// ASSIGN A PRIORITY FOR MATCHING WITHIN EACH AGE_GROUP SEX COMBINATION
// IN BATCHES OF (UP TO) FOUR
rename gender sex
by age_group sex (shuffle), sort: gen int priority = floor((_n-1)/2) + 1
drop shuffle
// RENAME VARIABLES TO AVOID CLASH
rename * control_*
foreach x in age_group sex priority {
rename control_`x' `x'
}
tempfile controls
save `controls'
// NOW MAKE A FILE OF CASES
restore
keep if case_control==1
// AGAIN PRIORITIZE FOR MATCHING
rename gender sex
by age_group sex (shuffle), sort: gen int priority = _n
drop shuffle
// MERGE WITH CONTROLS
merge 1:m age_group sex priority using `controls', keep(master match)
Comment