Skip to content

Commit

Permalink
Merge branch 'load-match-cohorts' of https://github.com/opensafely/po…
Browse files Browse the repository at this point in the history
…st-covid-thrombosis-research into load-match-cohorts
  • Loading branch information
alexwalkerepi committed Oct 14, 2020
2 parents f7896e0 + 85866b2 commit ddacd69
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion analysis/000_cr_define_covariates.do
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


di "STARTING COUNT FROM IMPORT:"
noi count
noi safecount

* Age: Exclude children and implausibly old people
qui summ age // Should be no missing ages
Expand Down
9 changes: 8 additions & 1 deletion analysis/101_cr_pneumonia_matches.do
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ noi di "Matching Report:"
noi di "****************************************"

forvalues reportMatch = 1/`numMatch' {
qui count if matchedto_`reportMatch' != -999
qui safecount if matchedto_`reportMatch' != -999
if `r(N)'!=. {
local perC = round(100*`r(N)'/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, `r(N)' (`perC' %) received `reportMatch' match"
}
else `r(N)'==. {
local perC = round(100*5/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, <5 (`perC' %) received `reportMatch' match"

}


global numMatches `r(N)'

Expand Down
4 changes: 2 additions & 2 deletions analysis/102_cr_matched_cohort_pneumonia.do
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ keep if eligibleMatchFound == 1
drop matchedFlag eligibleMatchFound

bysort setid patient: gen duplicatePatid = _n
count if duplicatePatid > 1
safecount if duplicatePatid > 1
drop if duplicatePatid > 1
drop duplicatePatid

sort setid
order setid patient_id indexdate flag
save "data/cr_matched_cohort_pneumonia_`outcome'", replace
}
}
10 changes: 9 additions & 1 deletion analysis/103_cr_control_2019_matches.do
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,19 @@ noi di "****************************************"
noi di "Matching Report:"
noi di "****************************************"


forvalues reportMatch = 1/`numMatch' {
qui count if matchedto_`reportMatch' != -999
qui safecount if matchedto_`reportMatch' != -999
if `r(N)'!=. {
local perC = round(100*`r(N)'/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, `r(N)' (`perC' %) received `reportMatch' match"
}
else `r(N)'==. {
local perC = round(100*5/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, <5 (`perC' %) received `reportMatch' match"

}


global numMatches `r(N)'

Expand Down
4 changes: 2 additions & 2 deletions analysis/104_cr_matched_cohort_control_2019.do
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ keep if eligibleMatchFound == 1
drop matchedFlag eligibleMatchFound

bysort setid patient: gen duplicatePatid = _n
count if duplicatePatid > 1
safecount if duplicatePatid > 1
drop if duplicatePatid > 1
drop duplicatePatid

Expand All @@ -75,4 +75,4 @@ order setid patient_id indexdate flag


save "data/cr_matched_cohort_control_2019_`outcome'", replace
}
}
9 changes: 8 additions & 1 deletion analysis/105_cr_control_2020_matches.do
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,17 @@ noi di "****************************************"
noi di "Matching Report:"
noi di "****************************************"


forvalues reportMatch = 1/`numMatch' {
qui count if matchedto_`reportMatch' != -999
qui safecount if matchedto_`reportMatch' != -999
if `r(N)'!=. {
local perC = round(100*`r(N)'/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, `r(N)' (`perC' %) received `reportMatch' match"
}
else `r(N)'==. {
local perC = round(100*5/ `totaltomatch', 0.1)
noi di "Out of `totaltomatch' patients, <5 (`perC' %) received `reportMatch' match"

}

global numMatches `r(N)'
Expand Down
4 changes: 2 additions & 2 deletions analysis/106_cr_matched_cohort_control_2020.do
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ keep if eligibleMatchFound == 1
drop matchedFlag eligibleMatchFound

bysort setid patient: gen duplicatePatid = _n
count if duplicatePatid > 1
safecount if duplicatePatid > 1
drop if duplicatePatid > 1
drop duplicatePatid

Expand All @@ -75,4 +75,4 @@ order setid patient_id indexdate flag


save "data/cr_matched_cohort_`outcome'", replace
}
}
34 changes: 34 additions & 0 deletions analysis/ado/safecount.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cap prog drop safecount
prog define safecount, byable(recall) rclass

marksample touse
local if " if `touse'"

local ifpos = strpos("`0'", "if ")
local inpos = strpos("`0'", "in ")

if `inpos'==1 & `ifpos'>0 {
noi di in red "if cannot be combined with in"
error 999
}

if `ifpos'>0{
local if "`0' & `touse'"
local if "`if' & `touse'"
}

if `inpos'==1{
local in = substr("`0'", `inpos',.)
}

qui cou `if' `in'
if (r(N)>5 | r(N)==0) {
count `if' `in'
scalar count = r(N)
}
else {
scalar count = .
noi di in yellow _n "** COUNT <=5 **"
}
return scalar N = count
end
46 changes: 46 additions & 0 deletions analysis/ado/safetab.ado
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cap prog drop safetab
prog define safetab, byable(recall)

marksample touse
local if " if `touse'"
local commapos = strpos("`0'", ",")
local commaposm1 = `commapos'-1

if `commapos'>0 {
local main = substr("`0'", 1, `commaposm1')
local options = substr("`0'", `commapos', .)
}
else local main `0'

local ifpos = strpos("`main'", " if ")
local ifposm1 = `ifpos'-1

local inpos = strpos("`main'", " in ")
local inposm1 = `inpos'-1

if `inpos'>0 & `ifpos'>0 {
noi di in red "if cannot be combined with in"
error 999
}

if `ifpos'>0{
local if = substr("`main'", `ifpos', .)
local if "`if' & `touse'"
local main = substr("`main'", 1, `ifposm1')
}

if `inpos'>0{
local in = substr("`main'", `inpos',.)
local main = substr("`main'", 1, `inposm1')
}

qui tab `main' `if' `in', matcell(T)
m: T=st_matrix("T")
m: T=(T:+(10:*(T:==0)))
m: st_numscalar("checkmin", min(T) )


if checkmin>5 tab `main' `if' `in' `options'
else noi di _n "**TABLE OF `main' REDACTED DUE TO SMALL N**" _n

end
File renamed without changes.
File renamed without changes.

0 comments on commit ddacd69

Please sign in to comment.