***------------------------------- GOUT CODE FILES /* clear cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" AURUM_gout_code_list AURUM_gout_code_list_23 */ ************------------------------- INSHEETING PATIENT FILE clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Patient" import delimited "RP_Febu_16112023_Extract_Patient_001.txt", stringcols(_all) gen month = 1 gen day = 1 destring yob, replace gen dob = mdy(month, day, yob) format dob %td drop month day acceptable cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" save "patient.dta", replace use "patient.dta", clear ************------------------------- INSHEETING PRACTICE FILE clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Practice" import delimited "RP_Febu_16112023_Extract_Practice_001.txt", stringcols(_all) ************------------------------- INSHEETING OBSERVATION FILES clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" forvalues i=1/9 { import delimited "RP_Febu_16112023_Extract_Observation_00`i'.txt", stringcols(_all) sort patid obsdate gen x=1 if obsdate=="null" drop if x==1 drop x cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" save "00`i'.dta", replace clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" forvalues i=10/99 { import delimited "RP_Febu_16112023_Extract_Observation_0`i'.txt", stringcols(_all) sort patid obsdate gen x=1 if obsdate=="null" drop if x==1 drop x cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" save "0`i'.dta", replace clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" forvalues i=100/136 { import delimited "RP_Febu_16112023_Extract_Observation_`i'.txt", stringcols(_all) sort patid obsdate gen x=1 if obsdate=="null" drop if x==1 drop x cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" save `i'.dta, replace clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Observation" } ******************* CREATING SINGLE LIST OF PATIDS clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=001/009 { use "00`i'", clear if "`firstonlist'"=="yes" { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" keep patid gen obs_file`i'=1 sort patid save "Patid.dta", replace } else { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" merge 1:1 patid using "Patid.dta" sort patid ** assert merge!=3 this is false, patids are in several files drop n consid pracid obsid obsdate enterdate staffid parentobsid medcodeid value numunitid obstypeid numrangelow numrangehigh probobsid _merge gen obs_file`i'=1 save "Patid.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=010/099 { use "0`i'", clear if "`firstonlist'"=="yes" { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" keep patid gen obs_file`i'=1 sort patid save "Patid2.dta", replace } else { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" merge 1:1 patid using "Patid2.dta" sort patid ** assert merge!=3 this is false, patids are in several files drop n consid pracid obsid obsdate enterdate staffid parentobsid medcodeid value numunitid obstypeid numrangelow numrangehigh probobsid _merge gen obs_file`i'=1 save "Patid2.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=100/136 { use "`i'", clear if "`firstonlist'"=="yes" { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" keep patid gen obs_file`i'=1 sort patid save "Patid3.dta", replace } else { sort patid obsid codebook patid bysort patid: gen n=_n count if n==1 keep if n==1 count cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" merge 1:1 patid using "Patid3.dta" sort patid ** assert merge!=3 this is false, patids are in several files drop n consid pracid obsid obsdate enterdate staffid parentobsid medcodeid value numunitid obstypeid numrangelow numrangehigh probobsid _merge gen obs_file`i'=1 save "Patid3.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } ***************************** cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" clear use "Patid.dta", replace merge 1:1 patid using "Patid2.dta" drop _merge merge 1:1 patid using "Patid3.dta" drop _merge save Patid_combined, replace ***************** THIS ABOVE IS A LIST OF UNIQUE PATIDS INCLUDED IN THIS STUDY ************************************************************************************************************ /* MATCH TO GOUT CODES CHECK 2019 & 2023 CODES Two options in each loop- so as not repeating- just use either option Creates 3 files each which then merge at the end RESTRICT TO ONLY GOUT CODES TO MINIMISE SIZE OF FILES MERGE TOGETHER AT THE END TO COMPARE ONLY REALLY NEED FIRST MENTION OF GOUT */ clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=001/009 { use "00`i'", clear if "`firstonlist'"=="yes" { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge keep if gout==1 sort patid obsdate medcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" ** save "Gout.dta", replace save "1Gout.dta", replace } else { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge sort patid obsdate medcodeid keep if gout==1 cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid obsdate medcodeid obsid **merge 1:1 patid medcodeid obsdate obsid using "Gout.dta" merge 1:1 patid medcodeid obsdate obsid using "1Gout.dta" assert _merge!=3 drop _merge **save "Gout.dta", replace save "1Gout.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=010/099 { use "0`i'", clear if "`firstonlist'"=="yes" { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge keep if gout==1 sort patid obsdate medcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" **save "Gout2.dta", replace save "1Gout2.dta", replace } else { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge sort patid obsdate medcodeid keep if gout==1 cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid obsdate medcodeid obsid **merge 1:1 patid medcodeid obsdate obsid using "Gout2.dta" merge 1:1 patid medcodeid obsdate obsid using "1Gout2.dta" assert _merge!=3 drop _merge **save "Gout2.dta", replace save "1Gout2.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" local firstonlist "yes" forvalues i=100/136 { use "`i'", clear if "`firstonlist'"=="yes" { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge keep if gout==1 sort patid obsdate medcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" **save "Gout3.dta", replace save "1Gout3.dta", replace } else { sort patid obsdate medcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_gout_code_list" gen gout=1 if _merge==3 drop _merge */ merge m:1 medcodeid using "AURUM_gout_code_list_23" gen gout=1 if _merge==3 drop _merge sort patid obsdate medcodeid keep if gout==1 cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid obsdate medcodeid obsid **merge 1:1 patid medcodeid obsdate obsid using "Gout3.dta" merge 1:1 patid medcodeid obsdate obsid using "1Gout3.dta" assert _merge!=3 drop _merge **save "Gout3.dta", replace save "1Gout3.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ** MERGE THEM TOGETHER cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" clear use "Gout.dta", replace merge 1:1 patid medcodeid obsdate obsid using "Gout2.dta" drop _merge merge 1:1 patid medcodeid obsdate obsid using "Gout3.dta" drop _merge save Gout_combined, replace *** 2023 CODES cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" clear use "1Gout.dta", replace merge 1:1 patid medcodeid obsdate obsid using "1Gout2.dta" drop _merge merge 1:1 patid medcodeid obsdate obsid using "1Gout3.dta" drop _merge save Gout_combined2, replace *************** THIS to work out cut off point for old gout diagnosis use "Gout_combined.dta", clear gen month = 12 gen month2 = 3 generate day = 17 gen day2=31 generate year1 = 2008 generate year2 = 2021 gen start = mdy(month, day, year1) // generate start date of study format start %td gen end = mdy(month2, day2, year2) // generate end date of study format end %td drop month month2 day year1 year2 day2 gen obsdate2 = date(obsdate, "DMY") format obsdate2 %td drop obsdate rename obsdate2 obsdate gen month=1 gen day =1 gen year =1991 gen start2= mdy(month,day,year) format start2 %td drop if obsdate=start gen before=1 if obsdate<=end bys patid: egen check_date=max(after) assert !missing(check_date) drop check_date bys patid: egen check_date=max(start) assert !missing(check_date) drop check_date merge m:1 patid pracid using "patient.dta" drop _merge gen ageatdiagnosis=(obsdate-dob)/365.25 replace ageatdiagnosis=round(ageatdiagnosis, 1) drop if ageatdiagnosis<18 // 381 observations lost drop if ageatdiagnosis>110 // 2,302 observations deleted) gsort patid obsdate bysort patid: gen n=_n keep if n==1 count ** histogram obsdate ** histogram ageatdiagnosis ** merge 1:1 patid using "Patid_combined" ** assert _merge!=2 | _merge!=1 keep patid pracid enterdate obsdate gout start end ageatdiagnosis ** histogram obsdate tab ageatdiagnosis save "gout_patients.dta", replace **======================================================================== /* INSHEETING DRUG FILES THEN MERGE SEPARATELY WITH ALLOPURINOL THEN MERGE SEPARATELY WITH FEBUXOSTAT */ clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" forvalues i=1/9 { import delimited "RP_Febu_16112023_Extract_DrugIssue_00`i'.txt", stringcols(_all) sort patid issuedate gen x=1 if issuedate=="null" drop if x==1 drop x cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" save "00`i'.dta", replace clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" forvalues i=20/99 { import delimited "RP_Febu_16112023_Extract_DrugIssue_0`i'.txt", stringcols(_all) sort patid issuedate gen x=1 if issuedate=="null" drop if x==1 drop x cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" save "0`i'.dta", replace clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" } **12/2/26 need to repeat this and add pred to prophylaxis clear cd"Z:\res_som_febux\CPRD data\CPRD data\Drug Issue" forvalues i=42/99 { import delimited "RP_Febu_16112023_Extract_DrugIssue_0`i'.txt", stringcols(_all) sort patid issuedate gen x=1 if issuedate=="null" drop if x==1 drop x cd"Z:\res_som_febux\CPRD data\CPRD data\Extracted\Medication" save "0`i'.dta", replace clear cd"Z:\res_som_febux\CPRD data\CPRD data\Drug Issue" } **-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" forvalues i=100/121 { import delimited "RP_Febu_16112023_Extract_DrugIssue_`i'.txt", stringcols(_all) sort patid issuedate gen x=1 if issuedate=="null" drop if x==1 drop x cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" save "`i'.dta", replace clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Drug Issue" } *****--------------------------------------------------------- /* MERGING ONTO ALLOPURINOL THEN FEBUXOSTAT FILES */ clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" local firstonlist "yes" forvalues i=001/009 { use "00`i'", clear if "`firstonlist'"=="yes" { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" ** save "allo.dta", replace save "febux.dta", replace } else { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid issuedate prodcodeid **merge 1:1 patid medcodeid obsdate obsid using "allo.dta" merge 1:1 patid medcodeid obsdate obsid using "febux.dta" assert _merge!=3 drop _merge **save "allo.dta", replace save "febux.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" local firstonlist "yes" forvalues i=010/099 { use "0`i'", clear if "`firstonlist'"=="yes" { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" ** save "allo1.dta", replace save "febux1.dta", replace } else { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid issuedate prodcodeid **merge 1:1 patid medcodeid obsdate obsid using "allo1.dta" merge 1:1 patid medcodeid obsdate obsid using "febux1.dta" assert _merge!=3 drop _merge **save "allo1.dta", replace save "febux1.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } clear cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" local firstonlist "yes" forvalues i=100/121 { use "`i'", clear if "`firstonlist'"=="yes" { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" ** save "allo2.dta", replace save "febux2.dta", replace } else { sort patid issuedate prodcodeid cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists" /* merge m:1 medcodeid using "AURUM_allopurinol_code_list" gen allo=1 if _merge==3 drop _merge keep if allo==1 */ merge m:1 medcodeid using "AURUM_febuxostat_code_list" gen febux=1 if _merge==3 drop _merge keep if febux===1 sort patid issuedate prodcodeid cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" sort patid issuedate prodcodeid **merge 1:1 patid medcodeid obsdate obsid using "allo2.dta" merge 1:1 patid medcodeid obsdate obsid using "febux2.dta" assert _merge!=3 drop _merge **save "allo2.dta", replace save "febux2.dta", replace } cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" local firstonlist "no" cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted" } *****-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ** COMBINING ALLO & FEBUX FILES cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" clear use "allo.dta", replace merge 1:1 patid medcodeid obsdate obsid using "allo1.dta" drop _merge merge 1:1 patid medcodeid obsdate obsid using "allo2.dta" drop _merge save allo_combined, replace cd"C:\Users\pre49\University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Check" clear use "febux.dta", replace merge 1:1 patid medcodeid obsdate obsid using "febux1.dta" drop _merge merge 1:1 patid medcodeid obsdate obsid using "febux2.dta" drop _merge save febux_combined, replace *****-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ** INCLUDING THOSE WITHIN THE STUDY PERIOD use "allo_combined.dta", clear ** use "febux_combined2.dta", clear sort patid issuedate gen month = 12 gen month2 = 3 generate day = 17 gen day2=31 generate year1 = 2008 generate year2 = 2021 gen start = mdy(month, day, year1) // generate start date of study format start %td gen end = mdy(month2, day2, year2) // generate end date of study format end %td drop month month2 day year1 year2 day2 drop if issuedate < start drop if issuedate > end save "allo_therapy", replace **save "feux_therapy", replace ******************------------------------MERGING COMMON DOSES ONTO EACH THERAPY FILE ** -------------------------------- ALLOPURINOL clear cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2/Duplicate/Merged" use "Therapy_a_issueid.dta", clear sort dosageid cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2" merge m:1 dosageid using "common" drop if _merge==2 drop _merge drop dosageid dosage_text foreach var in daily_dose dose_number dose_frequency dose_interval choice_of_dose dose_max_average change_dose dose_duration { capture replace `var' = "." if `var' =="NA" destring(`var'), replace } cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2/Duplicate/Merged" save "Therapy_a2_issueid.dta", replace ** -------------------------------- COLCHICINE clear cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2/Duplicate/Merged" use "Therapy_c_issueid.dta", clear sort dosageid cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2" merge m:1 dosageid using "common" drop if _merge==2 drop _merge drop dosageid foreach var in daily_dose dose_number dose_frequency dose_interval choice_of_dose dose_max_average change_dose dose_duration { capture replace `var' = "." if `var' =="NA" destring(`var'), replace } cd"Z:\prprojects\Clinical_Epi\Cons_Epi\Colchicine RfPB\Aurum_without_colch_condition\Extracted\Therapy2/Duplicate/Merged" save "Therapy_c2_issueid_dosage_text.dta", replace **---------------------------------------------------------------------------------------------------------------------------- *** Treatment duration clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Medication" ** use "allo_final.dta", clear use "febx_final.dta", clear sort patid issuedate bysort patid: gen n= _n count if n==1 // 9,351 drop n *** Check for duplicates duplicates report duplicates tag, generate(duplicate) browse patid issueid issuedate prodcodeid termfromemis duplicate if duplicate!=0 sort patid issueid issuedate prodcodeid duplicates drop drop duplicate **======================================== **generate allopurinol date in date format gen allo_date= date(issuedate, "DMY") format allo_date %td rename allo_date eventdate rename duration numdays *** FEBX gen febx_date= date(issuedate, "DMY") format febx_date %td rename febx_date eventdate rename duration numdays **============================================ sort patid issueid eventdate **** DURATION ** If both qty and duration are <1 then exclude - changed this to retain and change to missing destring numdays, replace tab numdays replace numdays=. if numdays <1 | numdays >90 sum numdays ** replace numdays=60 if numdays >59 & numdays <91 we're allowing up to 3/12 prescription ************ QUANTITY ** Change to missing if quantity has a comma in gen tochange = . replace tochange = 1 if strmatch(quantity, "*,*") replace quantity="." if tochange==1 drop tochange destring quantity, replace replace quantity=. if quantity <1 | quantity >224 tab quantity replace quantity=28 if quantity==1 // assume qty means 1 packet replace quantity=56 if quantity==2 // assume qty = 2 means 2 packets replace quantity=84 if quantity==3 // assume qty=3 means packets replace quantity=7 if quantity>3 & quantity <7 // assume no qty< 7 ***************************** **** merge common dose file to ascertain daily strength merge m:1 dosageid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Lookup files\common_dosages.dta", keep (1 3) drop _merge tab daily_dose tab termfromemis **============================================ **allo gen strength=100 if strmatch(termfromemis, "*100*") replace strength=300 if strmatch(termfromemis, "*300*") & missing(strength) count if missing(strength) // 0 ***feb gen strength=120 if strmatch(termfromemis, "*120*") replace strength=80 if strmatch(termfromemis, "*80*") & missing(strength) count if missing(strength) // 0 **============================================ gen daily_strength=daily_dose*strength tab daily_strength replace daily_dose=. if daily_strength<50 | daily_strength>1000 & daily_strength<180001 drop daily_strength gen daily_strength=daily_dose*strength ********************* **** / /* PRESCRIPTIONS ON SAME DAY ** NUMDAYS AND QUANTITY- can combine if same drug prescribed on same day - COMBINE ** NUMDAYS AND QUANTITY- same dose, different productid same day - COMBINE ** Same day different doses - ADD STRENGTH TOGETHER, KEEP SAME DURATION */ sort patid eventdate prodcodeid duplicates tag patid eventdate prodcodeid, generate(duplicate) browse if duplicate!=0 bysort patid eventdate prodcodeid: egen tot_qty_days=sum(quantity) if duplicate!=0 bysort patid eventdate prodcodeid: egen tot_numdays=sum(numdays) if duplicate!=0 replace tot_qty_days=. if tot_qty_days==0 & duplicate!=0 replace tot_numdays=. if tot_numdays==0 & duplicate!=0 replace numdays=tot_numdays if duplicate!=0 & tot_numdays!=. // (310,850 real changes made) replace quantity=tot_qty_days if duplicate!=0 & tot_qty_days!=. // (310,850 real changes made) duplicates drop patid eventdate prodcodeid, force drop duplicate tot_qty_days tot_numdays ********************** ** NUMDAYS AND QUANTITY- same day, different productid same strength- combine qty & numdays sort patid eventdate prodcodeid -daily_dose duplicates tag patid eventdate strength, generate(duplicate) browse patid issueid issuedate enterdate prodcodeid quantity numdays termfromemis substancestrength eventdate daily_dose strength daily_strength duplicate if duplicate!=0 bysort patid eventdate strength: egen tot_qty_days=sum(quantity) if duplicate!=0 bysort patid eventdate strength: egen tot_numdays=sum(numdays) if duplicate!=0 replace tot_qty_days=. if tot_qty_days==0 & duplicate!=0 replace tot_numdays=. if tot_numdays==0 & duplicate!=0 replace numdays=tot_numdays if duplicate!=0 & tot_numdays!=. // (310,850 real changes made) replace quantity=tot_qty_days if duplicate!=0 & tot_qty_days!=. // (310,850 real changes made) duplicates drop patid eventdate strength, force drop duplicate tot_qty_days tot_numdays ***=============================================== ** Same day different doses / same duration, combine strength; keep same numdays & qty **** ALLO ONLY THIS PART gsort patid eventdate strength duplicates tag patid eventdate, generate(duplicate) browse patid issueid issuedate enterdate prodcodeid quantity numdays termfromemis substancestrength eventdate daily_dose strength daily_strength duplicate if duplicate!=0 replace daily_strength= strength if duplicate!=0 & missing(daily_strength) bysort patid eventdate: egen tot_strength=sum(daily_strength) if duplicate!=0 replace strength=tot_strength if duplicate!=0 duplicates drop patid eventdate, force drop duplicate tot_strength **============================================ **Febuxostat- max dose 120mg **Therefore combine qty and numdays rather than combine strength gsort patid eventdate strength duplicates tag patid eventdate, generate(duplicate) browse patid issueid issuedate enterdate prodcodeid quantity numdays termfromemis substancestrength eventdate daily_dose strength daily_strength duplicate if duplicate!=0 bysort patid eventdate: egen tot_qty_days=sum(quantity) if duplicate!=0 bysort patid eventdate: egen tot_numdays=sum(numdays) if duplicate!=0 replace tot_qty_days=. if tot_qty_days==0 & duplicate!=0 replace tot_numdays=. if tot_numdays==0 & duplicate!=0 replace numdays=tot_numdays if duplicate!=0 & tot_numdays!=. // (310,850 real changes made) replace quantity=tot_qty_days if duplicate!=0 & tot_qty_days!=. // (310,850 real changes made) duplicates drop patid eventdate, force drop duplicate tot_qty_days tot_numdays **============================================ ************************* ***Check no duplicates duplicates report patid eventdate // now all uniquue on eventdate **********Check numdays etc.. tab numdays replace numdays=28 if numdays==1 // numdays =1 means 1 packet replace numdays=56 if numdays==2 // numdays = 2 means 2 packets replace numdays=84 if numdays==3 // numdays=3 means 3 packets replace numdays=7 if numdays>3 & numdays <7 // no numdays< 7 replace numdays= 90 if numdays >90 & numdays <505 tab numdays tab quantity replace quantity=. if quantity <1 | quantity >224 tab quantity gen calc_duration = quantity/daily_dose tab calc_duration replace calc_duration= 90 if calc_duration >90 & calc_duration <350 count if missing(numdays) // 2,456,016 // 38,545 count if missing(calc_duration) // 199,212 replace numdays=calc_duration if missing(numdays) & calc_duration!=. // (1,573,026 real changes made) // (29,234 real changes made) count if missing(numdays) // 882,990 // 9,311 ***************************** **Imputing if numdays missing- by patid & prodcodeid first; then prodcodeid only bysort patid prodcodeid: egen numdays_mis=mode(numdays), max replace numdays=numdays_mis if missing(numdays) & numdays_mis!=. // (487,439 real changes made) // (4,511 real changes made) count if missing(numdays) // 395,551 // 4,800 drop numdays_mis bysort patid: egen numdays_mis=mode(numdays), max replace numdays=numdays_mis if missing(numdays) & numdays_mis!=. // (92,040 real changes made) // (517 real changes made) count if missing(numdays) // 303,511 // 4,283 drop numdays_mis bysort prodcodeid: egen numdays_mis=mode(numdays), max replace numdays=numdays_mis if missing(numdays) & numdays_mis!=. // (303,511 real changes made) // (4,283 real changes made) count if missing(numdays) // 0 // 0 drop numdays_mis replace numdays=7 if numdays<7 tab numdays drop daily_strength dose_duration change_dose dose_max_average choice_of_dose dose_interval dose_frequency dose_unit dose_number dosage_text drugsubstancename substancestrength routeofadministration formulation dmdid estnhscost drugrecid dosageid quantunitid productname bnfchapter drugissues daily_dose browse save "allo_final_2.dta", replace ********************** use "allo_final_2.dta", clear ************************* save "febx_final_2.dta", replace use "febx_final_2.dta", clear ****creating 60days prescription variable sort patid eventdate bysort patid: gen duration=eventdate[_n+1]-eventdate[_n] gen stop=1 if numdays +60 obsdate & allo_date!=. & allo_date>start & allo_date obsdate & febx_date!=. & febx_date>start & febx_date end_risk_time sort patid start_risk_time CVD_date bysort patid: gen n=_n keep if n==1 drop n _merge keep patid CVD_date pracid case start_risk_time end_risk_time gender age gen `x'=1 rename CVD_date `x'date cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" save "`x'.dta", replace clear cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists\Outcomes" } ***** NO CM observations in study period ************************* MERGE with same outcomes USING THE LINKED DATA FILES CREATED IN DO FILE #5 cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" use "Primary_CV_outcome", clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" merge 1:1 patid using "linked_primary_outcome.dta" drop _merge sort patid gen primary_outcome_date= min(Primary_CV_outcomedate, prime_outcome_date_HES) format primary_outcome_date %td gen primary_out_record=. replace primary_out_record=1 if Primary_CV_outcome==1 & prime_outcome==1 replace primary_out_record=2 if Primary_CV_outcome==1 & missing(prime_outcome) replace primary_out_record=3 if missing(Primary_CV_outcome) & prime_outcome==1 label define primary_out_record 1 "AURUM_HES" 2 "AURUM" 3 "HES" label values primary_out_record primary_out_record sort patid bysort patid: gen n=_n tab n drop n gen primary_outcome=1 keep patid pracid case start_risk_time end_risk_time gender age primary_outcome primary_outcome_date primary_out_record cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "primary_outcome", replace ******************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" use "Isch_stroke_code_list", clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" merge 1:1 patid using "linked_CVA.dta" drop _merge sort patid gen CVA_date= min(Isch_stroke_code_listdate, CVA_date_HES) format CVA_date %td gen CVA_record=. replace CVA_record=1 if Isch_stroke_code_list==1 & HES_CVA==1 replace CVA_record=2 if Isch_stroke_code_list==1 & missing(HES_CVA) replace CVA_record=3 if missing(Isch_stroke_code_list) & HES_CVA==1 label define CVA_record 1 "AURUM_HES" 2 "AURUM" 3 "HES" label values CVA_record CVA_record sort patid bysort patid: gen n=_n tab n drop n gen CVA=1 keep patid pracid case start_risk_time end_risk_time gender age CVA CVA_date CVA_record cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "CVA_outcome", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" use "MI_code_list", clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" merge 1:1 patid using "linked_MI" drop _merge sort patid gen MI_date= min(MI_code_listdate, MI_date_HES) format MI_date %td gen MI_record=. replace MI_record=1 if MI_code_list==1 & HES_MI==1 replace MI_record=2 if MI_code_list==1 & missing(HES_MI) replace MI_record=3 if missing(MI_code_list) & HES_MI==1 label define MI_record 1 "AURUM_HES" 2 "AURUM" 3 "HES" label values MI_record MI_record sort patid bysort patid: gen n=_n tab n drop n gen MI=1 keep patid pracid case start_risk_time end_risk_time gender age MI MI_date MI_record cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "MI_outcome", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" use "Revasc_code_list", clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" merge 1:1 patid using "linked_revasc" drop _merge sort patid gen revasc_date1 = min(Revasc_code_listdate, revasc_date) format revasc_date1 %td gen revasc_record=. replace revasc_record=1 if Revasc_code_list==1 & revasc==1 replace revasc_record=2 if Revasc_code_list==1 & missing(revasc) replace revasc_record=3 if missing(Revasc_code_list) & revasc==1 label define revasc_record 1 "AURUM_HES" 2 "AURUM" 3 "HES" label values revasc_record revasc_record rename revasc revasc_hes gen revasc=1 keep patid pracid case start_risk_time end_risk_time gender age revasc revasc_date1 revasc_record rename revasc_date1 revasc_date cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "Revasc_outcome", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" use "UA_code_list", clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" merge 1:1 patid using "linked_UA" drop _merge sort patid gen UA_date=min(UA_code_listdate, UA_date_HES) format UA_date %td gen UA_record=. replace UA_record=1 if UA_code_list==1 & HES_UA==1 replace UA_record=2 if UA_code_list==1 & missing(HES_UA) replace UA_record=3 if missing(UA_code_list) & HES_UA==1 label define UA_record 1 "AURUM_HES" 2 "AURUM" 3 "HES" label values UA_record UA_record gen UA=1 keep patid pracid case start_risk_time end_risk_time gender age UA UA_date UA_record cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "UA_outcome", replace **************************** ** Only linked mortality data cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" use "linked_CM", clear rename CM_HES_ONS CM rename ONS_HES_CM_date CM_date gen CM_record="HES" cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "CM_outcome", replace ************************* *** only linked CCF data cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" use "linked_CCF", clear rename HES_CCF CCF_admit rename CCF_date_HES CCF_admit_date gen CCF_record="HES" cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" save "CCF_outcome", replace **************************** cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes\To analyse" use "primary_outcome", clear merge 1:1 patid using "CVA_outcome" drop _merge merge 1:1 patid using "MI_outcome" drop _merge merge 1:1 patid using "Revasc_outcome" drop _merge merge 1:1 patid using "UA_outcome" drop _merge merge 1:1 patid using "CM_outcome" drop _merge merge 1:1 patid using "CCF_outcome" drop _merge ************************ ** THIS establish there are patients without a 'primary outcome' as CM & revasc overwhelmingly in HES data only count if missing(primary_outcome) count if CM==1 sort patid bysort patid: gen n=_n tab n drop n browse if missing(primary_outcome) ********************* gen HES_DATE= min(CM_date, revasc_date) format HES_DATE %td replace primary_outcome_date=HES_DATE if missing(primary_outcome) replace primary_outcome=1 if missing(primary_outcome) ************************ browse count if missing(primary_outcome) drop case start_risk_time end_risk_time gender age save "cardiac_outcomes", replace ****************************** *** Existing CVD clear cd"C:\Users\pre49\OneDrive - University of Keele\General - PCSC - Febuxostat Safety CPRD Study\Code_lists\Outcomes" local filename "prev_CVD_no_CCF_CM CCF_code_list" foreach x of local filename { use `x', clear sort medcodeid cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes" merge 1:m medcodeid using "Any_CV_outcome_combined", keep (3) drop _merge merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) keep if CVD_date =start_risk_time & prime_outcome_date<=end_risk_time sort patid prime_outcome_date bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_primary_outcome", replace ************************* cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "CCF_code_list2", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen CCF_date_HES2= date(CCF_date_HES, "DMY") format CCF_date_HES2 %td drop CCF_date_HES rename CCF_date_HES2 CCF_date_HES keep if CCF_date_HES>=start_risk_time & CCF_date_HES<=end_risk_time sort patid CCF_date_HES bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_CCF", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "CVA_code_list2", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen CVA_date_HES2= date(CVA_date_HES, "DMY") format CVA_date_HES2 %td drop CVA_date_HES rename CVA_date_HES2 CVA_date_HES keep if CVA_date_HES>=start_risk_time & CVA_date_HES<=end_risk_time sort patid CVA_date_HES bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_CVA", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "MI_code_list2", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen MI_date_HES2= date(MI_date_HES, "DMY") format MI_date_HES2 %td drop MI_date_HES rename MI_date_HES2 MI_date_HES keep if MI_date_HES>=start_risk_time & MI_date_HES<=end_risk_time sort patid MI_date_HES bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_MI", replace **************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "UA_code_list2", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen UA_date_HES2= date(UA_date_HES, "DMY") format UA_date_HES2 %td drop UA_date_HES rename UA_date_HES2 UA_date_HES keep if UA_date_HES>=start_risk_time & UA_date_HES<=end_risk_time sort patid UA_date_HES bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_UA", replace ****************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "CM_HES_ONS", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen ONS_HES_CM_date2= date(ONS_HES_CM_date, "DMY") format ONS_HES_CM_date2 %td drop ONS_HES_CM_date rename ONS_HES_CM_date2 ONS_HES_CM_date keep if ONS_HES_CM_date>=start_risk_time & ONS_HES_CM_date<=end_risk_time sort patid ONS_HES_CM_date bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_CM", replace ****************************** cd "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" use "HES_revasc", clear merge m:1 patid using "C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted\Outcomes/Sara_sample.dta", keep(3) drop _merge gen revasc_date2= date(revasc_date, "DMY") format revasc_date2 %td drop revasc_date rename revasc_date2 revasc_date keep if revasc_date>=start_risk_time & revasc_date<=end_risk_time sort patid revasc_date bysort patid: gen n=_n keep if n==1 drop n sort patid cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" save "linked_revasc", replace ******************************* ***************************** ** LINKED OUTCOMES: ** cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\LINKED_OUTCOMES" ** working_all_cvd_hes -> "linked_primary_outcome" ** CCF_code_list2 -> "linked_CCF" ** CVA_code_list2 -> "linked_CVA" ** MI_code_list2 -> "linked_MI" ** UA_code_list -> "linked_UA" ** CM_HES_ONS -> "linked_CM" *** HES_revasc -> "linked_revasc" ************************* ********************* IMD FILE clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Final" import delimited "patient_2019_imd_23_003214.txt", stringcols(_all) *** 1 IS LEAST DEPRIVED cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Linked data\Results\Aurum_linked\Extracted" rename e2019_imd_10 imd sort patid save "imd", replace ******************************===================================================================================================================================== ****** ANALYSIS FILES cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted2\Outcomes\To analyse" use "cardiac_outcomes_prev_cvd_covariates", clear destring gender, replace count if missing(gender) // 0 replace gen_ethnicity="Missing" if missing(gen_ethnicity) merge 1:1 patid using "Z:\res_som_febux\CPRD data\CPRD data\Linked data\Results\Aurum_linked\Extracted/imd" drop if _merge==2 drop _merge replace imd="0" if missing(imd) destring imd, replace merge 1:1 patid using "Z:\res_som_febux\CPRD data\CPRD data\Linked data\Results\Aurum_linked\Extracted/bmi_before_index_finalsample2" drop if _merge==2 drop _merge recode bmi_category .=0 merge 1:1 patid using "Z:\res_som_febux\CPRD data\CPRD data\Linked data\Results\Aurum_linked\Extracted/smoking_category_before_index_finalsample2" drop if _merge==2 drop _merge recode smoking_category .=0 encode gen_ethnicity, gen(ethnicity) fre ethnicity gen ethnicity2=1 if ethnicity==13 replace ethnicity2=2 if ethnicity==1 | ethnicity==6 | ethnicity==9 | ethnicity==11 replace ethnicity2=3 if ethnicity==2 | ethnicity==3 | ethnicity==4 replace ethnicity2=4 if ethnicity==5 replace ethnicity2=5 if ethnicity==8 | ethnicity==10 replace ethnicity2=6 if ethnicity==7 | ethnicity==12 foreach var of varlist lipids Diabetes HTN CKD CCF prev_CVD ethnicity prev_CVD CCF CKD HTN Diabetes lipids primary_outcome CVA MI revasc UA CM CCF_admit { recode `var' .=0 } ** label define ethnicity2 1 "White" 2 "Asian" 3 "Black" 4 "Chinese" 5 "Mixed/other" 6 "Missing/unknown" ** label values ethnicity2 ethnicity2 tab case gender tab case prev_CVD tab case CCF tab case CKD tab case HTN tab case Diabetes tab case lipids tab case ethnicity tab case ethnicity2 tab case imd tab case bmi_category tab case smoking_category tab case lipids by case, sort : summarize age sum age tab case primary_outcome tab case CVA tab case MI tab case revasc tab case UA tab case CM tab case CCF_admit cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted2\Outcomes\To analyse" merge 1:1 patid using "extra_covariates3.dta" drop _merge merge 1:1 patid using "1pre_post_migraine" drop _merge foreach var of varlist gout_hosp_count gout_hosp gout_count1 drug_count monthly_consult prophylaxis post_migraine pre_migraine { recode `var' .=0 } tab case gout_hosp_count tab case drug_count tab case gout_count1 tab case prophylaxis tab case pre_migraine save "cardiac_outcomes_prev_cvd_covariates6", replace clear cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Extracted2\Outcomes\To analyse" use "cardiac_outcomes_prev_cvd_covariates6", clear ** histogram start_risk_time, discrete percent xlabel(, angle(forty_five)) xscale(alt) by(case) merge 1:1 patid using "urate.dta" replace control_gout=0 if missing(control_gout) tab case control_gout ******************************* ** . label list case ** case: ** 0 No ULT ** 1 Febuxostat ** 2 Allopurinol ************************************ gen timeatrisk=(_t-_t0) by case, sort : summarize timeatrisk summarize timeatrisk ** scale(30.4375) strate, per (1000) strate case, per (1000) stcox i.case, level (95) stcox i.case lipids Diabetes HTN CKD CCF prev_CVD ethnicity2 bmi_category imd gender smoking_category gout_hosp_count drug_count gout_count1 age, level(95) stcox i.case CKD CCF prev_CVD imd gender gout_hosp_count drug_count gout_count1 age, level(95) browse patid start_risk_time end_risk_time primary_outcome primary_outcome_date _st _d _origin _t _t0 time case tab case cd"C:\Users\pre49\OneDrive - University of Keele\PCSC - Febuxostat Safety CPRD Study - CPRD data - CPRD data\Richard's do files\Not used" stcox i.case CKD CCF prev_CVD imd gender gout_hosp_count drug_count gout_count1 age, scaledsch(resid0*) schoenfeld(resid1*) level(95) stphtest stphtest, detail estat phtest, detail estat phtest, plot(1.case) saving ("1.gph", replace) estat phtest, plot(2.case) saving ("2.gph", replace) estat phtest, plot(0b.case) saving ("3.gph", replace) estat phtest, plot(CKD) saving ("4.gph", replace) estat phtest, plot(CCF) saving ("5.gph", replace) estat phtest, plot(prev_CVD) saving ("6.gph", replace) estat phtest, plot(imd) saving ("7.gph", replace) estat phtest, plot(gender) saving ("8.gph", replace) estat phtest, plot(gout_hosp_count) saving ("9.gph", replace) estat phtest, plot(drug_count) saving ("10.gph", replace) estat phtest, plot(gout_count1) saving ("11.gph", replace) estat phtest, plot(age) saving ("12.gph", replace) graph combine "1.gph" "2.gph" "3.gph" "4.gph" "5.gph" "6.gph" "7.gph" "8.gph" "9.gph" "10.gph" "11.gph" "12.gph" stcox i.case##i.prophylaxis CKD CCF prev_CVD imd gender gout_hosp_count drug_count gout_count1 age, level(95) lincom 1.case + 1.case#0.prophylaxis, hr lincom 1.case + 1.case#1.prophylaxis, hr lincom 2.case + 2.case#0.prophylaxis, hr lincom 2.case + 2.case#1.prophylaxis, hr browse patid start_risk_time end_risk_time primary_outcome primary_outcome_date _st _d _origin _t _t0 time case gen case2=. replace case2=3 if case==2 replace case2=2 if case==1 replace case2=1 if case==0 tab case2 label define case2 1 "No ULT" 2 "Febuxostat" 3 "Allopurinol" label define prophylaxis 0 "No prophylaxis" 1 "Prophylaxis" label values case2 case2 label values prophylaxis prophylaxis decode case2, gen(case3) decode prophylaxis, gen(prophylaxis2) tab case3 sts test case2 local p = r(p) sts graph, by(case2) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"')title(`"Kaplan-Meier estimate of cardiovascular event by treatment group"') tmax(5) tmin(0) ci risktable(, order(1 "No ULT" 2 "Febuxostat" 3 "Allopurinol") rowtitle(, justification(left))) legend(position(6) size(small) ring(0)) graphregion(color(white)) sts graph, by(case2) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"')title(`"Kaplan-Meier estimate of cardiovascular event by treatment group"') tmax(5) tmin(0) lost legend(position(6) size(small) ring(0)) graphregion(color(white)) sts graph, by(case2) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"')title(`"Kaplan-Meier estimate of cardiovascular event by treatment group"') tmax(5) tmin(0) lost Sts graph, by(case2) /// sts graph, by(case2 prophylaxis) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"') title(`"Kaplan-Meier estimate of CV event by treatment group"') tmax(5) tmin(0) ci risktable(, order(1 "No ULT" 2 "Febuxostat" 3 "Allopurinol") rowtitle(, justification(left))) legend(position(6) size(small) ring(0)) sts graph, by(case2 prophylaxis2) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"') title(`"Kaplan-Meier estimate of CV event by treatment group"') tmax(5) tmin(0) risktable risktable(, righttitles size(small)) legend(size(small)) sts test sts graph, by(case3 prophylaxis2) adjustfor(CKD CCF prev_CVD imd gender gout_hosp_count drug_count gout_count1 age, atomeans) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"') title(`"Kaplan-Meier estimate of CV event by treatment group"') tmax(5) tmin(0) legend(size(small)) sts graph, by(case2) adjustfor(CKD CCF prev_CVD imd gender gout_hosp_count drug_count gout_count1 age, atomeans) ytitle(`"Proportion without CV event"') xtitle(`"Time at risk (years)"') title(`"Kaplan-Meier estimate of CV event by treatment group"') tmax(5) tmin(0) legend(on position (3)) /* Same for CVA MI revasc UA CM CCF_admit */