-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstata_code.do
More file actions
634 lines (423 loc) · 13.6 KB
/
stata_code.do
File metadata and controls
634 lines (423 loc) · 13.6 KB
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
set trace off
set more off
clear all
global dir_main "C:\Projects\Occasional\20190802Adalberto"
global dir_figs "${dir_main}\_figs"
global dir_dict "${dir_main}\_dict"
global dir_dta "${dir_main}\_data"
global dir_DATA "C:\data"
global dir_SHAPE "${dir_DATA}\_shape"
global dir_UNcode "${dir_DATA}\UNcode"
global dir_UNDPpop "${dir_DATA}\UNDPpop"
global dir_CI5plus "${dir_DATA}\CI5plus"
global dir_CI5XI "${dir_DATA}\CI5XI"
global dir_GLOBO2018 "${dir_DATA}\Globocan2018"
global dir_GHE "${dir_DATA}\GHE_mortality"
global dir_WHO_mortality "${dir_DATA}\WHO_mortality"
global dir_inkbash "C:\Projects\inkbash"
global dir_fix_label "${dir_inkbash}\fix_label"
global dir_maps_data "C:\Projects\Standard_maps\_data"
*begin trend panel
use "${dir_dta}\nordpred_testis_output_recent.dta", clear
replace py = 0 if age == 18
replace cases = 0 if age == 18
replace cases = 0 if cases < 0
CSU_ASR age cases py,var_age_gr(country*) by( country* base year gof np ) standardE("st_err") var_ASR("asr")
merge m:1 country_code using "${dir_dta}\pop_estimate.dta"
drop _m
sort country_code year
format temp_ratio %4.1f
CSU_country_info country_code
drop continent* country_iso3
sort area_label country_code year
egen dummy_country = group(country_code)
tempfile temp_graph
save `temp_graph' ,replace
use `temp_graph' ,clear
keep country* area*
duplicates drop
gsort area* country_label
bys area_code :gen order = _n
gen str_order = string(order,"%02.0f")
drop order
tempfile temp_order
save `temp_order' ,replace
use `temp_graph' ,clear
merge m:1 area* country* using `temp_order'
drop _m
sort country* year
save `temp_graph' ,replace
sum asr
tab year
forvalues i =1/ 26 {
use `temp_graph' ,clear
keep if dummy_country == `i'
drop if year < 1975
sum year
local min_y = r(min)
if mod( `min_y', 10) == 0 {
local min2_y = `min_y'
}
else {
local min2_y = `min_y'+5
}
local title_graph = country_label
if national == 0 {
local title_graph = "`title_graph'*"
local subtitle_graph = "*: based on regional registries"
}
else {
local subtitle_graph = ""
}
# delimit ;
twoway
(connected asr year if base<=2 , lcolor( "25 113 159") lwidth(medthick) msymbol(none) mlabcolor(black))
(connected asr year if base>=2 , lcolor( "25 113 159") lwidth(medthick) lpattern(dash) msymbol(none) mlabcolor(black)) //
,
title( `title_graph', color(black))
//caption( `subtitle_graph', size(2))
ytitle( "Age standardized incidence rate per 100,000",size(small))
yscale( log range(0.9 17) titlegap(5)) // titlegap(1)
ylabel( 1 1.2 1.5 2 2.5 3 4 5 6 7 8 9 10 12 13 15 17 , labels labsize(small) angle(horizontal) format(%3s) grid glwidth(vthin) glcolor(gs13))
ymtick(0.9 (0.1) 2.5 2.5 (0.5) 5 5 (1) 17 , nolabels grid glwidth(vthin) glcolor(gs13))
xtitle( "Year" ,size(small) )
xscale( titlegap(3))
xlabel( 1980 (10) 2030, labsize(small) valuelabel grid glwidth(vthin) glcolor(gs13) ) // labgap(1)
xmtick( 1980 (5) 2035 , nolabels grid glwidth(vthin) glcolor(gs13))
xline( 1980 , lwidth(vthin) lcolor(gs13))
legend(off)
name(graph`i', replace)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
ysize(10) xsize(7)
;
# delimit cr
local area_code = area_code
local str_order = str_order
local title_graph = country_label
graph export "${dir_inkbash}\trend_panel\temp\graph_`area_code'_`str_order'.eps", as(eps) replace
}
*end
*begin pie
local sex 0
local x 6
local top = `x' - 1
insheet using "${dir_GHE}\GHE_mortality_2016.csv", clear
keep if country_code == 76 // 170
keep if sex == `sex'
keep if inrange(age,0,6)
keep if inlist(ghe_level,0,2)
collapse (sum) cases, by(ghe*)
gsort -cases
gen rk_cases =_n
keep if rk_cases <= `x'
list
tempfile temp_tot
save `temp_tot', replace
use `temp_tot', replace
gen percent = cases/cases[1]*100
forvalue i = 1(1)`top' {
replace percent = percent[_n] - percent[_n+`i'] if rk == 1
}
list ghe_cause percent
use `temp_tot', replace
replace rk_cases = rk_cases -1
forvalue i = 1(1)`top' {
replace cases = cases[_n] - cases[_n+`i'] if rk == 0
}
replace rk = `x' if rk == 0
csv_merge ghe_code using "${dir_DATA}\_dict\cancer_color_2018.csv", master_key(10) using_key(10)
keep if _m == 3
drop _m
sort rk
forvalue i = 0(1)`x' {
local color`i' = color[`i']
}
replace ghe_cause = "Other causes" if ghe_code == 0
#delimit ;
graph pie cases ,
over(rk)
angle(90)
pie(1, color (`color1'))
pie(2, color (`color2'))
pie(3, color (`color3'))
pie(4, color (`color4'))
pie(5, color (`color5'))
pie(6, color (`color6'))
pie(7, color (`color7'))
pie(8, color (`color8'))
pie(9, color (`color9'))
pie(10, color (`color10'))
pie(11, color (`color11'))
plabel(1 percent, size(medium) color (black) gap(10))
plabel(2 percent, size(medium) color (black) gap(10))
plabel(3 percent, size(medium) color (black) gap(10))
plabel(4 percent, size(medium) color (black) gap(10))
plabel(5 percent, size(medium) color (black) gap(10))
plabel(6 percent, size(medium) color (black) gap(10))
plabel(6 percent, size(medium) color (black) gap(10))
plabel(7 percent, size(medium) color (black) gap(10))
plabel(8 percent, size(medium) color (black) gap(10))
plabel(9 percent, size(medium) color (black) gap(10))
plabel(10 percent, size(medium) color (black) gap(10))
plabel(11 percent, size(medium) color (black) gap(10))
legend(off)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
;
#delimit cr
graph export "${dir_inkbash}\pie\temp\temp.eps", as(eps) replace
keep rk ghe_cause cases
outsheet using "${dir_inkbash}\pie\temp\cancer_info.csv", comma replace
*end
*begin top5 pie bar auto
local sex 0
local country 900
use "${dir_GLOBO2018}\Globocan_asr_cases_cumrisk_CRC.dta", clear
drop asr cumrisk
keep if sex == `sex'
drop if inlist(cancer_code,17,37,38,40) // drop skin, other cancer and unspecified cancer
//regroup for cancer_tabacco related
replace cancer_code =15 if inlist(cancer_code ,1,2,3,4,5,6,7,8,9,11,13,14,15,23,29,30 )
replace cancer_label = "Smoking related cancer" if cancer_code ==15
collapse (sum) cases (mean) py, by (type sex cancer* country*)
keep if country_code == `country'
tab country_label
collapse (sum) cases py, by(type sex cancer*)
gsort +type sex -cases
bys type sex : gen rk_cases =_n
keep if rk_cases <= 6
tempfile temp_tot
save `temp_tot', replace
gen percent = 0
forvalues i = 0(1)5 {
replace percent = (cases/(cases[_n-`i']))*100 if rk == `i' +1
}
list
*begin pie
use `temp_tot', replace
gen prop5 = 0 if rk == 1
replace prop5 = 1 if rk > 1
collapse (sum) cases, by(type prop5)
gen percent = (cases - cases[_n+1])*100 / cases if prop5 == 0
replace percent = cases *100 / cases[_n-1] if prop5 == 1
forvalue i = 0(1)2 {
#delimit ;
graph pie percent if type == `i',
over(prop5)
angle(90)
pie(2, color (26 98 162))
pie(1, color ( 220 220 220))
plabel(2 percent, size(medium) color (black) gap(5))
plabel(1 percent, size(medium) color (black) gap(5))
legend(off)
name(pie_`i', replace)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
;
#delimit cr
graph export "${dir_inkbash}\pie_bar\temp\pie`i'.eps", as(eps) replace
}
*end
*begin bar
forvalue i = 0(1)2 {
use `temp_tot', replace
replace rk_cases = rk_cases -1
drop if rk_cases == 0
merge m:1 cancer_code using "${dir_DATA}\_dict\cancer_color_2018.dta"
keep if _m == 3
drop _m
sort type rk
keep if type == `i'
local color1= color[1]
local color2= color[2]
local color3= color[3]
local color4= color[4]
local color5= color[5]
drop cancer* sex color
reshape wide cases, i(type) j(rk)
local total = cases1 + cases2 + cases3 + cases4 + cases5
gen bar1 = cases1 / `total'
gen bar2 = cases2 / `total'
gen bar3 = cases3 / `total'
gen bar4 = cases4 / `total'
gen bar5 = cases5 / `total'
# delimit;
graph bar (asis) bar5 bar4 bar3 bar2 bar1 ,
stack
yscale(off)
bar(1, color ( `color5'))
bar(2, color ( `color4'))
bar(3, color ( `color3'))
bar(4, color ( `color2'))
bar(5, color ( `color1'))
ylabel(,nolabels noticks nogrid)
legend(off)
xsize(4)
ysize(10)
name(bar_`i', replace)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
;
# delimit cr
graph export "${dir_inkbash}\pie_bar\temp\bar`i'.eps", as(eps) replace
}
use `temp_tot', replace
replace rk_cases = rk_cases -1
drop if rk_cases == 0
merge m:1 cancer_code using "${dir_DATA}\_dict\cancer_color_2018.dta"
keep if _m == 3
drop _m
gsort type -rk
by type : egen tot=total(cases)
by type : gen pos = sum(cases)
replace pos = pos - (cases/2)
replace pos = ((pos/tot)*312.001) + 98.582 - 7.2755
replace pos = ((pos - 59.833)/1.33333)*(-1)
drop py color
gsort type rk
keep cancer_label pos
list
outsheet using "${dir_inkbash}\pie_bar\temp\cancer_label.csv", comma replace
use `temp_tot', replace
quietly gen prop5 = 0 if rk == 1
quietly replace prop5 = 1 if rk > 1
gsort type +prop
quietly collapse (sum) cases, by(type prop5)
keep cases
outsheet using "${dir_inkbash}\pie_bar\temp\cancer_number.csv", comma replace
*end
*end
*begin top5 pie bar auto
forvalue a = 0(1)2 {
forvalue b = 981(1)984 {
if `a' == 0 {
local sex_lab "both"
}
else if `a' == 1{
local sex_lab "male"
}
else if `a' == 2{
local sex_lab "female"
}
if `b' == 981 {
local country_lab "very"
}
else if `b' == 982{
local country_lab "high"
}
else if `b' == 983{
local country_lab "medium"
}
else if `b' == 984{
local country_lab "low"
}
use "${dir_GLOBO2018}\Globocan_asr_cases_cumrisk_CRC.dta", clear
drop asr cumrisk
keep if sex == `a'
drop if inlist(cancer_code,17,37,38,40) // drop skin, other cancer and unspecified cancer
keep if country_code == `b'
tab country_label
collapse (sum) cases py, by(type sex cancer*)
gsort +type sex -cases
bys type sex : gen rk_cases =_n
keep if rk_cases <= 6
list
tempfile temp_tot
save `temp_tot', replace
*begin pie
use `temp_tot', replace
gen prop5 = 0 if rk == 1
replace prop5 = 1 if rk > 1
collapse (sum) cases, by(type prop5)
gen percent = (cases - cases[_n+1])*100 / cases if prop5 == 0
replace percent = cases *100 / cases[_n-1] if prop5 == 1
forvalue i = 0(1)2 {
#delimit ;
graph pie percent if type == `i',
over(prop5)
angle(90)
pie(2, color (26 98 162))
pie(1, color ( 220 220 220))
plabel(2 percent, size(medium) color (black) gap(5))
plabel(1 percent, size(medium) color (black) gap(5))
legend(off)
name(pie_`i', replace)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
;
#delimit cr
graph export "${inkbash}\pie_bar\temp\pie_`country_lab'_`sex_lab'_`i'.eps", as(eps) replace
}
*end
*begin bar
forvalue i = 0(1)2 {
use `temp_tot', replace
replace rk_cases = rk_cases -1
drop if rk_cases == 0
merge m:1 cancer_code using "${dir_DATA}\_dict\cancer_color_2018.dta"
keep if _m == 3
drop _m
sort type rk
keep if type == `i'
local color1= color[1]
local color2= color[2]
local color3= color[3]
local color4= color[4]
local color5= color[5]
drop cancer* sex color
reshape wide cases, i(type) j(rk)
local total = cases1 + cases2 + cases3 + cases4 + cases5
gen bar1 = cases1 / `total'
gen bar2 = cases2 / `total'
gen bar3 = cases3 / `total'
gen bar4 = cases4 / `total'
gen bar5 = cases5 / `total'
# delimit;
graph bar (asis) bar5 bar4 bar3 bar2 bar1 ,
stack
yscale(off)
bar(1, color ( `color5'))
bar(2, color ( `color4'))
bar(3, color ( `color3'))
bar(4, color ( `color2'))
bar(5, color ( `color1'))
ylabel(,nolabels noticks nogrid)
legend(off)
xsize(4)
ysize(10)
name(bar_`i', replace)
graphregion(style(none) istyle(none))
plotregion(style(none) istyle(none))
;
# delimit cr
graph export "${inkbash}\pie_bar\temp\bar_`country_lab'_`sex_lab'_`i'.eps", as(eps) replace
}
use `temp_tot', replace
replace rk_cases = rk_cases -1
drop if rk_cases == 0
merge m:1 cancer_code using "${dir_DATA}\_dict\cancer_color_2018.dta"
keep if _m == 3
drop _m
gsort type -rk
by type : egen tot=total(cases)
by type : gen pos = sum(cases)
replace pos = pos - (cases/2)
replace pos = ((pos/tot)*312.001) + 98.582 - 7.2755
replace pos = ((pos - 59.833)/1.33333)*(-1)
drop py color
gsort type rk
keep cancer_label pos
list
outsheet using "${inkbash}\pie_bar\temp\cancer_label_`country_lab'_`sex_lab'.csv", comma replace
use `temp_tot', replace
quietly gen prop5 = 0 if rk == 1
quietly replace prop5 = 1 if rk > 1
gsort type +prop
quietly collapse (sum) cases, by(type prop5)
keep cases
outsheet using "${inkbash}\pie_bar\temp\cancer_number_`country_lab'_`sex_lab'.csv", comma replace
*end
}
}
*end