generated from opensafely/research-template
/
10_hh_imd_descriptives_for_Hamish_W1.do
324 lines (225 loc) · 9.22 KB
/
10_hh_imd_descriptives_for_Hamish_W1.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*==============================================================================
DO FILE NAME: 00_hhClassif_cr_analysis_dataset
PROJECT: describe household composition by ethnicity and IMD
DATE: 12th August 2020
AUTHOR: Rohini Mathur/Kevin Wing
DESCRIPTION OF FILE: program 10, descriptive variables
DATASETS USED: main analysis dataset for each wave
DATASETS CREATED: none
OTHER OUTPUT: logfiles, printed to folder analysis/$logdir
sysdir set PLUS "/Users/kw/Documents/GitHub/households-research/analysis/adofiles"
sysdir set PERSONAL "/Users/kw/Documents/GitHub/households-research/analysis/adofiles"
==============================================================================*/
sysdir set PLUS ./analysis/adofiles
sysdir set PERSONAL ./analysis/adofiles
pwd
* Open a log file
cap log close
log using ./logs/10_hh_imd_descriptives_for_Hamish_W1.log, replace t
* Open Stata dataset
use ./output/hhClassif_analysis_dataset_ageband_3MAIN.dta, clear //age 67+ only
*% of hh category by region
safetab region hhRiskCatExp_5cats, row
log close
*Household composition by ethnic group and IMD quintile (Q1: most affluent, Q5: most deprived)
*tab eth5 hhRiskCat67PLUS_5cats if imd==1, row
*tab eth5 hhRiskCat67PLUS_5cats if imd==5, row
/*
keep patient_id hhRiskCat hhRiskCatExp_4cats hh_size* hhRiskCatBROAD ethnicity ethnicity_16 hh_size eth5 imd eth16
tab hhRiskCat67PLUS_5cats imd if eth5==1, col
tab hhRiskCat67PLUS_5cats imd if eth5==2, col
tab hhRiskCat67PLUS_5cats imd if eth5==3, col
tab hhRiskCat67PLUS_5cats imd if eth5==4, col
tab hhRiskCat67PLUS_5cats imd if eth5==5, col
*generate new household category which includes living alone
gen hh_rohini=hhRiskCatBROAD
replace hh_rohini=0 if hh_size==1 & hhRiskCatBROAD==1 //67+ living alone
label define hh_rohini 0"Living alone (67+ only)" 1"1 gen (67+ only)" 2"2 gens" 3"3+ gens"
label values hh_rohini hh_rohini
tab hh_rohini
label var hh_rohini "Number of generations in each household"
*add household size =1 to household size variable
tab hh_size5cat
replace hh_size5cat=0 if hh_size==1
label define hh_size5catLabel 0 "1", modify
tab hh_size5cat
label var hh_size5cat "Number of people in each household"
*Set up output file
cap file close tablecontent
file open tablecontent using ./output/table_ethnicity_descriptivesMAIN.txt, write text replace
file write tablecontent ("Table x: Household size by ethnic group") _n
/*
* ADD ETHNICITY LABEL
label define eth5 1 "White" ///
2 "South Asian" ///
3 "Black" ///
4 "Mixed" ///
5 "Other" ///
6 "Unknown"
label values eth5 eth5
safetab eth5, m
*/
local lab1: label eth5 1
local lab2: label eth5 2
local lab3: label eth5 3
local lab4: label eth5 4
local lab5: label eth5 5
di "`lab1'" "`lab2'" "`lab3'" "`lab4'" "`lab5'"
file write tablecontent _tab ("Total") _tab _tab ///
("`lab1'") _tab _tab ///
("`lab2'") _tab _tab ///
("`lab3'") _tab _tab ///
("`lab4'") _tab _tab ///
("`lab5'") _tab _n _n
*HOUSEHOLD GENERATIONS BROAD
tabulatevariable_eth, variable(hh_rohini) min(0) max(3)
file write tablecontent _n _n
*HOUSEHOLD SIZE
tabulatevariable_eth, variable(hh_size5cat) min(0) max(4)
file write tablecontent _n _n
*IMD
tabulatevariable_eth, variable(imd) min(1) max(5)
file write tablecontent _n _n
*HOUSEHOLD GENERATIONS DETAILED
tabulatevariable_eth, variable(hhRiskCat) min(1) max(14)
file write tablecontent _n _n _n
file write tablecontent _n _n
file write tablecontent ("Table x: Household size by ethnic subgroup") _n
/*
* HOUSEHOLD SIZE BY SOUTH ASIAN SUBGROUPS
local lab1: label eth16 4
local lab2: label eth16 5
local lab3: label eth16 6
file write tablecontent _tab ("Total") _tab ("Total") _tab ///
("`lab1'") _tab ("`lab1'") _tab ///
("`lab2'") _tab ("`lab2'") _tab ///
("`lab3'") _tab ("`lab3'") _n
*HOUSEHOLD GENERATIONS BROAD
tabulatevariable_eth16, variable(hh_rohini) min(0) max(3)
file write tablecontent _n _n
*HOUSEHOLD SIZE
tabulatevariable_eth16, variable(hh_size5cat) min(0) max(4)
file write tablecontent _n _n
*IMD
tabulatevariable_eth16, variable(imd) min(1) max(5)
file write tablecontent _n _n
*HOUSEHOLD GENERATIONS DETAILED
tabulatevariable_eth16, variable(hhRiskCat) min(1) max(14)
file write tablecontent _n _n _n
*/
******************************ETH5 IMD
file write tablecontent ("Table x: Household size by ethnic group and IMD") _n
*gen eth-imd variable for all eth5 vars
gen eth_imd=1 if eth5==1 & imd==1
replace eth_imd=2 if eth5==1 & imd==5
replace eth_imd=3 if eth5==2 & imd==1
replace eth_imd=4 if eth5==2 & imd==5
replace eth_imd=5 if eth5==3 & imd==1
replace eth_imd=6 if eth5==3 & imd==5
replace eth_imd=7 if eth5==4 & imd==1
replace eth_imd=8 if eth5==4 & imd==5
replace eth_imd=9 if eth5==5 & imd==1
replace eth_imd=10 if eth5==5 & imd==5
label define eth_imd 1"White Q1" 2"White Q5" 3"SA Q1" 4"SA Q5" 5"Black Q1" 6"Black Q5" 7"Mixed Q1" 8"Mixed Q5" 9"Other Q1" 10"Other Q5"
label values eth_imd eth_imd
tab eth_imd
local lab1: label eth_imd 1
local lab2: label eth_imd 2
local lab3: label eth_imd 3
local lab4: label eth_imd 4
local lab5: label eth_imd 5
local lab6: label eth_imd 6
local lab7: label eth_imd 7
local lab8: label eth_imd 8
local lab9: label eth_imd 9
local lab10: label eth_imd 10
file write tablecontent _tab ("Total") _tab _tab ///
("`lab1'") _tab _tab ///
("`lab2'") _tab _tab ///
("`lab3'") _tab _tab ///
("`lab4'") _tab _tab ///
("`lab5'") _tab _tab ///
("`lab6'") _tab _tab ///
("`lab7'") _tab _tab ///
("`lab8'") _tab _tab ///
("`lab9'") _tab _tab ///
("`lab10'") _tab _n _n
*HOUSEHOLD GENERATIONS BROAD
tabulatevariable_ethimd, variable(hh_rohini) min(0) max(3)
file write tablecontent _n _n
*HOUSEHOLD SIZE
tabulatevariable_ethimd, variable(hh_size5cat) min(0) max(4)
file write tablecontent _n _n
*HOUSEHOLD GENERATIONS DETAILED
tabulatevariable_ethimd, variable(hhRiskCat) min(1) max(14)
file write tablecontent _n _n
/*
******************************ETH16 IMD
file write tablecontent ("Table x: Household size by ethnic subgroup and IMD") _n
*gen eth-imd variable for white and SA
gen eth16_imd=1 if eth16==4 & imd==1
replace eth16_imd=2 if eth16==4 & imd==5
replace eth16_imd=3 if eth16==5 & imd==1
replace eth16_imd=4 if eth16==5 & imd==5
replace eth16_imd=5 if eth16==6 & imd==1
replace eth16_imd=6 if eth16==6 & imd==5
label define eth16_imd 1"Indian Q1" 2"Indian Q5" 3"Pakistani Q1" 4"Pakistani Q5" 5 "Bangladeshi Q1" 6"Bangladeshi Q5"
label values eth16_imd eth16_imd
tab eth16_imd
local lab1: label eth16_imd 1
local lab2: label eth16_imd 2
local lab3: label eth16_imd 3
local lab4: label eth16_imd 4
local lab5: label eth16_imd 5
local lab6: label eth16_imd 6
file write tablecontent _tab ("Total") _tab ("Total") _tab ///
("`lab1'") _tab ("`lab1'") _tab ///
("`lab2'") _tab ("`lab2'") _tab ///
("`lab3'") _tab ("`lab3'") _tab ///
("`lab4'") _tab ("`lab4'") _tab ///
("`lab5'") _tab ("`lab5'") _tab ///
("`lab6'") _tab ("`lab6'") _n ///
*HOUSEHOLD GENERATIONS BROAD
tabulatevariable_eth16imd, variable(hh_rohini) min(0) max(3)
file write tablecontent _n _n
*HOUSEHOLD SIZE
tabulatevariable_eth16imd, variable(hh_size5cat) min(0) max(4)
file write tablecontent _n _n
*HOUSEHOLD GENERATIONS DETAILED
tabulatevariable_eth16imd, variable(hhRiskCat) min(1) max(14)
file write tablecontent _n _n
file close tablecontent
*/
* Close log file
log close
*check imd
insheet using ./output/table_ethnicity_descriptivesMAIN.txt, clear
/**BAR CHARTS
use ./output/hhClassif_analysis_datasetMAIN.dta, clear
keep eth5 imd hhRiskCatBROAD hh_size5cat hhRiskCat
tab hhRiskCatBROAD, generate(broad)
tab hh_size5cat, generate(size)
tab hhRiskCat, generate(hhcat)
*gen eth-imd variable for white and SA
gen eth_imd=1 if eth5==1 & imd==1
replace eth_imd=2 if eth5==1 & imd==2
replace eth_imd=3 if eth5==1 & imd==3
replace eth_imd=4 if eth5==1 & imd==4
replace eth_imd=5 if eth5==1 & imd==5
replace eth_imd=6 if eth5==2 & imd==1
replace eth_imd=7 if eth5==2 & imd==2
replace eth_imd=8 if eth5==2 & imd==3
replace eth_imd=9 if eth5==2 & imd==4
replace eth_imd=10 if eth5==2 & imd==5
label define eth_imd 1"White Q1" 2"White Q2" 3"White Q3" 4"White Q4" 5"White Q5" ///
6"SA Q1" 7"SA Q2" 8"SA Q3" 9"SA Q4" 10"SA Q5"
label values eth_imd eth_imd
tab eth_imd
*BY ETHNICITY
graph bar broad1 broad2 broad3, over(eth5) saving(./output/rohini_hhbroad_ethMAIN.gph, replace)
cap graph bar size1 size2 size3 size4 size5, over(eth5) saving(./output/rohini_hhsize_ethMAIN.gph, replace)
graph bar hhcat1 hhcat2 hhcat3 hhcat4 hhcat5 hhcat6 hhcat7 hhcat8 hhcat9 hhcat10 hhcat11 hhcat12 hhcat13 hhcat14, over(eth5) saving(./output/rohini_hhcat_ethMAIN.gph, replace) legend(off)
*BY ETHNICITY AND IMD
graph bar broad1 broad2 broad3, over(eth_imd) saving(./output/rohini_hhbroad_ethimdMAIN.gph, replace)
cap graph bar size1 size2 size3 size4 size5, over(eth_imd) saving(./output/rohini_hhsize_ethimdMAIN.gph, replace)
graph bar hhcat1 hhcat2 hhcat3 hhcat4 hhcat5 hhcat6 hhcat7 hhcat8 hhcat9 hhcat10 hhcat11 hhcat12 hhcat13 hhcat14, over(eth_imd) saving(./output/rohini_hhcat_ethimdMAIN.gph, replace) legend(off)