generated from opensafely/research-template
/
300_cr_data_management_matching.do
56 lines (50 loc) · 1.81 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
********************************************************************************
*
* 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 groups matched datasets
********************************************************************************
ls $outdir/
foreach v in covid pneumonia {
import delimited $outdir/input_`v'.csv, clear
save $outdir/patients_`v'.dta, replace
}
* Gen flag for covid patients (case = 1)
use $outdir/patients_covid.dta, replace
gen case = 1
append using $outdir/patients_pneumonia.dta
replace case = 0 if case ==.
gen year_20 = 1 if case == 1
replace year_20 = 0 if case == 0
save $outdir/matched_combined_pneumonia.dta, replace
********************************************************************************
* Format controls_2019 matched sets
********************************************************************************
import delimited $outdir/matched_combined_control_2019.csv, clear
gen year_20 = 1 if case == 1
replace year_20 = 0 if case == 0
save $outdir/matched_combined_control_2019.dta, replace
********************************************************************************
* Format controls_2020 matched sets
********************************************************************************
import delimited $outdir/matched_combined_control_2020.csv, clear
gen year_20 = 1 if case == 1
replace year_20 = 0 if case == 0
save $outdir/matched_combined_control_2020.dta, replace