I am selecting 20 controls per case matched by GP, but I am struggling to specify the eligibility criteria for controls "upon selection". To clarify, controls should NOT be less than 15 years of age AT "index" date and should have NOT transferred out of practice BEFORE the index date. These are the command I am using successfully but I don't know how to modify them to fulfil the eligibility criteria of controls at the time of event occurrence:

stset right, failure(suicide) origin(enter) enter(left)
set seed 563476
save cohort

forval i=1/777 { // 777 is a maximum practice id,
use cohort, clear
keep if pracid==`i'
qui tab suicide
if r(r)==2 {
sttocc, n(20)
save temp/matched`i' //, replace
}
}

use temp/matched1, clear
forval i=2/777 {
capture append using temp/matched`i'
save matched, replace
}
I do have the variable lists for dates of births (dob) and for transfer out of practice date(tod) before running the loop, but the index date (index) for matched pairs only occurs AFTER running the sttocc command.