generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
300_cr_data_management_matching.do
68 lines (51 loc) · 1.66 KB
/
300_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
67
68
********************************************************************************
*
* Do-file: 300_cr_data_management.do
*
* Programmed by: John & Alex
*
* Data used: None
*
* Data created: None
*
* Other $outdir: None
*
********************************************************************************
*
* Purpose:
*
* Note:
********************************************************************************
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, replace
gen case = 1
append using $outdir/cohort_rates_pneumonia, 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
* Gen flag for covid patients (case = 1)
use $outdir/cohort_rates_covid, replace
gen case = 1
append using $outdir/cohort_rates_gen_population, 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_gen_population.dta, replace
log close