Skip to content

Commit

Permalink
Updated outputs with redaction and rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyherrett committed Jun 18, 2024
1 parent 48e7a3e commit 214cc3c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 49 deletions.
23 changes: 12 additions & 11 deletions analysis/201_cr_prevalent_cohort_simple_rates.do
Original file line number Diff line number Diff line change
Expand Up @@ -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" "
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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" "
*
Expand All @@ -133,9 +139,4 @@ use "$tabfigdir/prevalent_rates_summary_`hftype'_2018", clear

}

log close





log close
70 changes: 36 additions & 34 deletions analysis/202_cr_prevalent_cohort_prevalence.do
Original file line number Diff line number Diff line change
@@ -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'"
*
Expand All @@ -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' {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -85,7 +87,7 @@ foreach drug in aa betablockers mra arni sglt2i two_pillars three_pillars four_p

}
}

restore
}
// Close the postfile
postclose `measures'
Expand All @@ -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'"
Expand Down Expand Up @@ -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
***************************************************************************
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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 {
Expand All @@ -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
13 changes: 9 additions & 4 deletions analysis/204_prevalent_cohort_table.do
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -80,7 +86,6 @@ foreach hftype in `heartfailtype' {

* Close log file
log close




0 comments on commit 214cc3c

Please sign in to comment.