generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
200_cr_data_management_matching.do
66 lines (52 loc) · 1.87 KB
/
200_cr_data_management_matching.do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//
// 200_cr_data_management_matching.do
//
// This program combines the main cohort data with
// comparator population data
//
// Authors: Robin (based on Alex & John)
// Date: 15 Oct 2021
// Updated: 15 Oct 2021
// Input files:
// Output files:
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
clear
do `c(pwd)'/analysis/global.do
********************************************************************************
* Append covid/pneumonia cohorts
********************************************************************************
ls $outdir/
cap log close
log using $outdir/append_cohorts.txt, replace t
* Gen flag for covid patients (case = 1)
use $outdir/cohort_rates_covid_2020, replace
gen case = 1
append using $outdir/cohort_rates_pneumonia_2019, force
replace case = 0 if case ==.
* count patients from pneumonia group who are among covid group
bysort patient_id: gen flag = _n
safecount if flag == 2
noi di "number of patients in both cohorts is `r(N)'"
drop flag
save $outdir/combined_covid_pneumonia.dta, replace
********************************************************************************
* Append covid/gen pop. cohorts
********************************************************************************
foreach year in 2019 2020 {
* Gen flag for covid patients (case = 1)
use $outdir/cohort_rates_covid_2020, replace
gen case = 1
append using $outdir/cohort_rates_general_`year', force
replace case = 0 if case ==.
* count patients from general group who are among covid group
bysort patient_id: gen flag = _n
safecount if flag == 2
noi di "number of patients in both cohorts is `r(N)'"
drop flag
save $outdir/combined_covid_general_`year'.dta, replace
}
log close