/* This is stata code for defining Irritable Bowel Syndrome using administrative data The algorithm is published in Tonelli et al BMC Med Inform Dec Making 2015;15:31 and based on the work in Sands et al Pharmacoepidemiol Drug Saf 2006;15:47-56 1) Specify the file name for the hospitalization data Define the variable names for the ICD-9 codes as hosp_icd9_codeX (X indicating the diagnosis code position) Define the maximum number of ICD-9 diagnosis code position as num_hosp_icd9 Define the variable name for ICD-10 codes as hosp_icd10_codeX (X indicating the diagnosis code position) Define the maximum number of ICD-10 diagnosis code position as num_hosp_icd10 Define the variable name of the hospitalization start date as hosp_start_date Define the variable names of the types of hospitalization as type 2) Specify the file name for the physician claims data Define the variable names for the ICD-9 codes as claim_icd9_codeX (X indicating the diagnosis code position) Define the maximum number of ICD-9 diagnosis code position as num_claim_icd9 Define the variable name of the physician claims date as claim_start_date 3) Specify the directory of the output dataset 4) Create a study cohort which includes the unique patient identifier, the study start and end dates (e.g., when a patient turns 18 until they die or out-migrate) */ * File name and variable names for the hospitalizations dataset global data_hosp = "G:\Open Data\ICDC 2013\ICDC Source\Constant files\hosp94_2013.dta" global hosp_icd9_code = "hosp_icd9dx_code" global num_hosp_icd9 = 16 global hosp_icd10_code = "hosp_icd10dx_code" global num_hosp_icd10 = 25 global hosp_start_date = "start_date" global type = "diag_type" * File names and variable names for the physician claims dataset global data_claim = "G:\Open Data\ICDC 2013\ICDC Source\claims_94_13.dta" global claim_icd9_code = "hlth_dx_icd9x_code_" global num_claim_icd9 = 3 global claim_start_date = "start_date" * Output dataset directory global out_source = "G:\Projects\Phoebe\MM30codes\kidtran" /* Sample program call ICDmm30_ibs cohort akdnid study_start_date study_end_date 'cohort' is the file name of the study cohort 'id' is the unique patient identifier 'study_start_date' is the study start date 'study_end_date' is the study end date */ version 13.1 capture program drop ICDmm30_ibs program ICDmm30_ibs set more off gettoken cohort 0:0 gettoken id 0:0 gettoken study_start_date 0:0 gettoken study_end_date 0:0 use `cohort', clear duplicates drop sort `id', stable save cohort_ibs, replace * Irritable bowel syndrome local ICD9_ibs_in 5641 local ICD9_ibs_ex 153 154 157 1830 1975 1986 2352 2390 555 556 5712 5715 5771 579 local ICD10_ibs_in K58 local ICD10_ibs_ex C18 C19 C20 C21 C25 C56 C785 C796 D017 D019 D371 D372 D373 D374 D375 K50 K51 K702 K703 K740 K742 K746 K860 K861 K90 K912 * One hospitalization use "${data_hosp}" , clear keep `id' ${hosp_start_date} ${hosp_icd9_code}1-${hosp_icd9_code}${num_hosp_icd9} ${hosp_icd10_code}1-${hosp_icd10_code}${num_hosp_icd10} /// ${type}1- ${type}16 ${type}17- ${type}${num_hosp_icd10} recast long ${hosp_start_date}, force sort `id', stable merge n:1 `id' using cohort_ibs keep if _merge==3 drop _merge keep if ${hosp_start_date}>=`study_start_date' & ${hosp_start_date}<=`study_end_date' keep if ${hosp_start_date}>=study_start_date & ${hosp_start_date}<=study_end_date local n=${num_hosp_icd9} forvalues nhos9=1(1)`n' { capture replace ${hosp_icd9_code}`nhos9'= subinstr(${hosp_icd9_code}`nhos9', ".", "",.) } local m=${num_hosp_icd10} forvalues nhos10=1(1)`m' { capture replace ${hosp_icd10_code}`nhos10'= subinstr(${hosp_icd10_code}`nhos10', ".", "",.) } local n=${num_hosp_icd9} foreach k in in ex { gen type_`k'=. gen code_`k'="" foreach i in `ICD9_ibs_`k'' { local len=strlen("`i'") forvalues dx=`n'(-1)1 { capture replace code_`k'="`i'" if substr(${hosp_icd9_code}`dx',1,`len') =="`i'" capture replace type_`k'=${type}`dx' if substr(${hosp_icd9_code}`dx',1,`len') =="`i'" } } local m=${num_hosp_icd10} foreach j in `ICD10_ibs_`k'' { local len=strlen("`j'") forvalues dx=`m'(-1)1 { capture replace code_`k' = "`j'" if substr(${hosp_icd10_code}`dx',1,`len') == "`j'" capture replace type_`k'=${type}`dx' if substr(${hosp_icd10_code}`dx',1,`len')== "`j'" } } } keep if code_in!="" drop if code_ex!="" rename code_in code rename type_in type keep `id' ${hosp_start_date} type code rename ${hosp_start_date} ibs_date sort `id' ibs_date, stable bysort `id': keep if _n==1 gen source="hosp" sort `id' save "${out_source}\ICD_ibs.dta", replace * At least claims in two years use "${data_claim}",clear keep `id' ${claim_start_date} ${claim_icd9_code}1-${claim_icd9_code}${num_claim_icd9} recast long ${claim_start_date}, force sort `id', stable merge n:1 `id' using cohort keep if _merge==3 drop _merge keep if ${claim_start_date}>=`study_start_date' & ${claim_start_date}<=`study_end_date' local n=${num_claim_icd9} forvalues nclaim9=1(1)`n' { capture replace ${claim_icd9_code}`nclaim9'= subinstr(${claim_icd9_code}`nclaim9', ".", "",.) } local n=${num_claim_icd9} foreach k in in ex { gen code_`k'="" foreach i in `ICD9_ibs_`k'' { local len=strlen("`i'") forvalues dx=`n'(-1)1 { capture replace code_`k'="`i'" if substr(${claim_icd9_code}`dx',1,`len') =="`i'" } } } keep if code_in!="" drop if code_ex!="" rename code_in code sort `id' ${claim_start_date}, stable bysort `id': gen claim=1 if ${claim_start_date}[_n+1]<=(${claim_start_date}[_n]+round(365.25*2,1)) keep if claim==1 drop claim bysort `id': keep if _n==1 gen source="claim" keep `id' ${claim_start_date} code source rename ${claim_start_date} ibs_date * Append hospitalizations with claims append using "${out_source}\ICD_ibs.dta" sort `id' ibs_date, stable bysort `id': keep if _n==1 gen ibs=1 keep `id' ibs_date ibs sort `id' ibs_date save "${out_source}\ICD_ibs.dta", replace erase cohort_ibs.dta end