From 214cc3c1e12474f50fd6392670c82d17f2a60614 Mon Sep 17 00:00:00 2001 From: emilyherrett Date: Tue, 18 Jun 2024 17:15:17 +0100 Subject: [PATCH] Updated outputs with redaction and rounding --- .../201_cr_prevalent_cohort_simple_rates.do | 23 +++--- .../202_cr_prevalent_cohort_prevalence.do | 70 ++++++++++--------- analysis/204_prevalent_cohort_table.do | 13 ++-- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/analysis/201_cr_prevalent_cohort_simple_rates.do b/analysis/201_cr_prevalent_cohort_simple_rates.do index 63b2424..14959d0 100644 --- a/analysis/201_cr_prevalent_cohort_simple_rates.do +++ b/analysis/201_cr_prevalent_cohort_simple_rates.do @@ -20,7 +20,7 @@ do "`c(pwd)'/analysis/global.do" capture log close log using "$logdir/201_cr_prevalent_simple_rates.log", replace -local heartfailtype " "hfref" "hf" " +local heartfailtype " "hf" "hfref" " foreach hftype in `heartfailtype' { local years " "2018" "2019" "2020" "2021" "2022" "2023" " @@ -48,7 +48,10 @@ foreach v in all_hosp_fup outhf_hosp all_cvd_fup allcause_mortality /// *local start2yr=master_index_date+365.25 local start5yr=master_index_date - stset `enddatenow', id(patient_id) failure(`out'`x') enter(master_index_date) scale(365.25) + stset `enddatenow', id(patient_id) failure(`out'`x') enter(master_index_date) origin(master_index_date) scale(365.25) + + + * Overall rate stptime, per(1000) @@ -61,6 +64,9 @@ foreach v in all_hosp_fup outhf_hosp all_cvd_fup allcause_mortality /// (`events') (`r(rate)') /// (`r(lb)') (`r(ub)') + + + * Stratified foreach c of global stratifiers { levelsof `c' , local(cats) @@ -116,13 +122,13 @@ use "$tabfigdir/prevalent_rates_summary_`hftype'_2018", clear gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0)) } gen rate_midpoint = (numEvents_midpoint/personTime_midpoint)*1000 - gen lci_midpoint = (invpoisson(numEvents_midpoint,.975)/personTime_midpoint)*1000 - gen uci_midpoint = (invpoisson(numEvents_midpoint,.025)/personTime_midpoint)*1000 + gen lci_midpoint = exp( ln(rate_midpoint) - invnormal(0.975)/sqrt(numEvents_midpoint) ) + gen uci_midpoint = exp( ln(rate_midpoint) + invnormal(0.975)/sqrt(numEvents_midpoint) ) drop personTime numEvents rate lc uc replace lci_midpoint=. if rate_midpoint==0 replace uci_midpoint=. if rate_midpoint==0 - export delimited using "$tabfigdir/prevalent_rates_summary_`hftype'.csv", replace + export delimited using "$tabfigdir/prevalent_rates_summary_`hftype'_redacted_rounded.csv", replace local years " "2018" "2019" "2020" "2021" "2022" "2023" " * @@ -133,9 +139,4 @@ use "$tabfigdir/prevalent_rates_summary_`hftype'_2018", clear } -log close - - - - - +log close \ No newline at end of file diff --git a/analysis/202_cr_prevalent_cohort_prevalence.do b/analysis/202_cr_prevalent_cohort_prevalence.do index bf71d0c..88892c5 100644 --- a/analysis/202_cr_prevalent_cohort_prevalence.do +++ b/analysis/202_cr_prevalent_cohort_prevalence.do @@ -1,10 +1,10 @@ ******************************************************************************** * -* Do-file: 102_cr_prevalent_cohort_prevalence.do +* Do-file: 202_cr_prevalent_cohort_prevalence.do * * Programmed by: Emily Herrett (based on John & Alex) * -* Data used: "$outdir/prevalent_cohort_hfref_`year'.dta" +* Data used: "$outdir/prevalent_cohort_`hftype'_`year'.dta" * * Data created: "$tabfigdir/prevalences_summary_`year'" * @@ -18,7 +18,7 @@ ******************************************************************************** do "`c(pwd)'/analysis/global.do" capture log close -log using "$logdir/102_cr_prevalent_cohort_prevalence.log", replace +log using "$logdir/202_cr_prevalent_cohort_prevalence.log", replace local heartfailtype " "hfref" "hf" " foreach hftype in `heartfailtype' { @@ -28,7 +28,7 @@ foreach hftype in `heartfailtype' { ******************************************************************************** local years " "2018" "2019" "2020" "2021" "2022" "2023" " -* +* foreach year in `years' { use "$outdir/prevalent_cohort_`hftype'_`year'.dta", clear @@ -41,10 +41,12 @@ foreach year in `years' { postfile `measures' float(year) str20(drug) str20(variable) float(category) float(total) float(ondrug) using "$tabfigdir/prevalent_prevalences_summary_`hftype'_`year'", replace *need to add contraindications to this loop - *need to add automatic redaction to this loop foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_pillars { display `drug' *unstratified + preserve + *drop if patient has contraindications to the drug + capture drop if population_`drug'!=1 count local total=r(N) count if `drug'==1 @@ -85,7 +87,7 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p } } - + restore } // Close the postfile postclose `measures' @@ -97,7 +99,7 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p ******************************************************************************** noi display "combine the summaries from each year for a graph" use "$tabfigdir/prevalent_prevalences_summary_`hftype'_2018", clear - + * local years 2019 2020 2021 2022 2023 foreach year in `years' { append using "$tabfigdir/prevalent_prevalences_summary_`hftype'_`year'" @@ -156,6 +158,18 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p label define drugs 1 "ACEi/ARB" 2 "Beta blocker" 3 "MRA" 4 "ARNi" 5 "SGLT2i" 6 "Two pillars" 7 "Three pillars" 8 "Four pillars" label values drugpresc drugs + order year drugpresc variable cat category total ondrug proportion lci uci + + + export delimited using "$tabfigdir/prevalent_prevalences_summary_`hftype'_redacted_rounded.csv", replace + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2018.dta" + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2019.dta" + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2020.dta" + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2021.dta" + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2022.dta" + erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2023.dta" + + /* *************************************************************************** *OVERALL PRESCRIPTION BY YEAR *************************************************************************** @@ -215,7 +229,7 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p replace cat="5 most deprived" if variable=="IMD" & category==5 replace cat="East Midlands" if variable=="Region" & category==1 - replace cat="East of England" if variable=="Region" & category==2 + replace cat="East" if variable=="Region" & category==2 replace cat="London" if variable=="Region" & category==3 replace cat="North East" if variable=="Region" & category==4 replace cat="North West" if variable=="Region" & category==5 @@ -238,12 +252,14 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p *replace cat="No CLD" if variable=="CLD" & category==0 *replace cat="CLD" if variable=="CLD" & category==1 +*/ *************************************************************************** *OVERALL PRESCRIPTION, BY CALENDAR YEAR *************************************************************************** - + /* + *GRAPH POST OUTPUT CHECK preserve noi display "make overall graph" keep if variable=="Overall" @@ -258,29 +274,17 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p xtitle("") /// barwidth(0.8) /// || rcap uci lci year, + * + graph export "$tabfigdir/prevalent_prevalences_by_`hftype'.svg", as(svg) replace restore + */ *TABLE - order year drugpresc variable cat category total ondrug proportion lci uci - - - - export delimited using "$tabfigdir/prevalent_prevalences_summary_`hftype'.csv", replace - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2018.dta" - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2019.dta" - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2020.dta" - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2021.dta" - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2022.dta" - erase "$tabfigdir/prevalent_prevalences_summary_`hftype'_2023.dta" - - } - -log close - + /* *GRAPH STRATIFIED - local years " "2022" "2023" " - *"2018" "2019" "2020" "2021" + local years " "2023" " + *"2018" "2019" "2020" "2021" "2022" foreach year in `years' { foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_pillars { @@ -301,12 +305,10 @@ log close bargap(40) *need to add confidence intervals graph save "$tabfigdir/prevalent_prevalences_by_covar_`hftype'_`year'_`drug'.gph", replace - *TABLE - *export delimited using "$tabfigdir/prevalences_covar_`hftype'_`year'_`drug'.csv", replace - restore } - } -*/ - - + */ +} + + +log close diff --git a/analysis/204_prevalent_cohort_table.do b/analysis/204_prevalent_cohort_table.do index 84a32a4..b708a6e 100644 --- a/analysis/204_prevalent_cohort_table.do +++ b/analysis/204_prevalent_cohort_table.do @@ -67,10 +67,16 @@ foreach hftype in `heartfailtype' { drop v3 v4 v5 drop in 1/3 destring v6, gen(n) ignore(",") force - replace n=. if n>0 & n<=7 - replace v7="." if n==. - gen round_n=round(n,5) + replace n=. if n>=1 & n<=7 + gen percent=v7 + replace percent="." if n==. + gen round_n=round(n,5) + replace round_n=n if v1=="Mean follow-up, years (SD)" + replace percent=v7 if v1=="Mean follow-up, years (SD)" drop v6 + drop n + drop v7 + order v1 v2 round_n export delimited using "$tabfigdir/prevalent_table1_`hftype'_`year'_redacted_rounded", replace restore @@ -80,7 +86,6 @@ foreach hftype in `heartfailtype' { * Close log file log close - \ No newline at end of file