-
Notifications
You must be signed in to change notification settings - Fork 0
/
WFP Extreme weather events 2.do
217 lines (138 loc) · 6.04 KB
/
WFP Extreme weather events 2.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
import delimited "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\G5_Sahel_admin2Name.csv", varnames(1) clear
rename admin2pcod location
save "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\G5_Sahel_admin2Name.dta", replace
import delimited "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\sahel_rfh-daily_20240703.csv", clear
merge m:1 location using "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\G5_Sahel_admin2Name.dta"
drop _m
generate time2 = date(time, "YMD")
format %td time2
gen annee = year(time2)
gen mois = month(time2)
gen jour = day(time2)
gen YM = string(annee) + "_" + string(mois)
/*
//gen tmp_time = time2
//format %td tmp_time
//gen ddate = mdy(mois, jour, annee)
//format ddate %td
*/
tab location
encode location, generate(location2)
tab location2
keep if admin2name == "Kadiogo"
sort annee mois
gen seq = _n
gen seq_1 = seq - 30
replace seq_1 = 1 if seq_1<=0
*************************************************************
// Dry periods computation
*************************************************************
// Dry periods
gen dry_threshold = 2 // days with less than 2 mm precipitation (2.85 mm/d, West Africa)
gen dry_period = (rfh < dry_threshold)
replace dry_period = . if dry_period == 0
/*
. tab dry_period,m
dry_period | Freq. Percent Cum.
------------+-----------------------------------
1 | 3,767,674 85.00 85.00
. | 664,799 15.00 100.00
------------+-----------------------------------
Total | 4,432,473 100.00
*/
*************************************************************
// heavy rainfall
*************************************************************
gen heavy_treshold = 20 // Extreme rainfall categories (heavy>20 mm): (>19.6mm/d, West Africa)
gen heavy = (rfh > heavy_treshold)
//replace heavy = . if heavy == 0
/*
tab heavy,m
heavy | Freq. Percent Cum.
------------+-----------------------------------
1 | 40,757 0.92 0.92
. | 4,391,716 99.08 100.00
------------+-----------------------------------
Total | 4,432,473 100.00
. tab adm0_code heavy,m
| heavy
adm0_code | 1 . | Total
-----------+----------------------+----------
BF | 13,323 701,592 | 714,915
ML | 8,983 785,367 | 794,350
MR | 1,418 745,271 | 746,689
NE | 5,878 1,058,551 | 1,064,429
TD | 11,155 1,100,935 | 1,112,090
-----------+----------------------+----------
Total | 40,757 4,391,716 | 4,432,473
*/
sort location2 time2
tsset location2 time2
//tsset location_last_num time2,monthly
//tsset location2 time2,delta(30 days)
*************************************************************
// heavy rainfall
*************************************************************
tsspell , cond(rfh > heavy_treshold)
egen length_heavy = max(_seq), by(location2 _spell)
gen n_heavy_sequence = .
replace n_heavy_sequence = _end if length_heavy !=1
//egen num = sum(_end), by(location_last_num _spell)
order location2 rfh time2 heavy _seq _spell _end length_heavy
rename _seq heavy_seq
rename _spell heavy_spell
rename _end heavy_end
*ssc install rangestat
rangestat (sum) n_heavy_sequence, interval(time2 -29 -1) by(location2)
rangestat (max) heavy_seq, interval(time2 -29 -1) by(location2)
replace heavy_seq_max = 30 if heavy_seq_max > 30
replace heavy_seq_max = . if n_heavy_sequence_sum == .
*************************************************************
// Dry periods computation
*************************************************************
sort YM
gen seq = _n
tsspell , cond(rfh < dry_threshold) // & rfh < dry_threshold
replace _spell = . if _spell == 0
replace _seq = . if _seq == 0
replace _end = . if _end == 0
replace _seq = 30 if _seq > 30
replace _seq = . if dry_period == .
rename _seq dry_seq
rename _spell dry_spell
rename _end dry_end
egen dry_length = max(dry_seq), by(location2 dry_spell)
gen dry_end_true = .
replace dry_end_true = dry_end if dry_length !=1
//Number of consecutive days with less than 2 mm precipitation in the last 30 days
rangestat (sum) Number_cons_drydays = dry_end_true, interval(time2 -30 -1) by(location2)
gen Number_cons_drydays2 = Number_cons_drydays + 1 if Number_cons_drydays<=1
drop dry_length
drop dry_end_true_sum
drop Number_cons_drydays
rangestat (count) dry_spell, interval(time2 -30 -1) by(location2)
//rangestat (obs) dry_spell, interval(time2 -30 -1) by(location2)
rangestat (max) dry_seq, interval(time2 -30 -1) by(location2)
rangestat (sum) dry_end_true, interval(time2 -30 -1) by(location2)
drop dry_seq_max
drop dry_seq_max
egen dry_length = max(dry_seq), by(location2 dry_spell)
rangestat (sum) dry_end_true, interval(time2 -29 -1) by(location2)
rangestat (max) dry_seq, interval(time2 -29 -1) by(location2)
replace dry_seq_max = 30 if dry_seq_max > 30
replace dry_seq_max = . if n_dry_sequence_sum == .
ssc install rangestat
rangestat (sum) n_dry_sequence, interval(time2 -29 -1) by(location2)
rangestat (max) dry_seq, interval(time2 -29 -1) by(location2)
replace dry_seq_max = 30 if dry_seq_max > 30
replace dry_seq_max = . if n_dry_sequence_sum == .
order location location2 admin2name rfh time2 heavy heavy_seq heavy_spell heavy_end length_heavy n_heavy_sequence dry_period dry_seq dry_spell dry_end length_dry n_dry_sequence
//drop *_end *_seq *_spell
drop length_heavy length_dry dry_threshold heavy_treshold
drop time location2
order location admin2name time2 rfh heavy heavy_seq heavy_spell heavy_end length_heavy n_heavy_sequence n_heavy_sequence_sum heavy_seq_max dry_period dry_seq dry_spell dry_end length_dry n_dry_sequence n_dry_sequence_sum dry_seq_max
rename n_heavy_sequence_sum
rename heavy_seq_max
rename n_dry_sequence_sum
rename dry_seq_max
save "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\WF_extreme_weather_events.dta",replace