-
Notifications
You must be signed in to change notification settings - Fork 0
/
WFP Extreme weather events final heavy.do
129 lines (82 loc) · 3.23 KB
/
WFP Extreme weather events final heavy.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
*****************************************************
// This is for Heavy periods computation, because it takes more times to compute all
****************************************************
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"
keep if admin2name == "Ville de Niamey"
//sort annee mois
gen seq = _n
*************************************************************
// Heavy periods computation
*************************************************************
// Heavy periods
gen heavy_threshold = 20 // days with more than 20 mm precipitation (19.6 mm/d, West Africa)
gen heavy_period = (rfh > heavy_threshold)
replace heavy_period = . if heavy_period == 0
sort location2 time2
tsset location2 time2
//keep in 1/300
gen heavy_length = .
gen Number_cons_heavydays = .
***********************************
//keep in 1/500
levelsof seq if seq <= 30 & seq > 2, local(val)
foreach x of local val {
local debut = 1
local fin = `x' - 1
tsspell in `debut' / `fin', cond(rfh > heavy_threshold)
rename _seq _seq`x'
rename _spell _spell`x'
rename _end _end`x'
******
egen max_seq`x' = max(_seq`x') in `debut'/`x'
replace heavy_length = max_seq`x' if seq == `x' //& max_seq`x'!=1
******
//gen _end`x' = .
replace _end`x' = 0 if heavy_period[_n]== 1 & heavy_period[_n-1]==. & heavy_period[_n+1]==. in `debut'/`x'
egen sum_end`x' = sum(_end`x') in `debut'/`x'
replace Number_cons_heavydays = sum_end`x' if seq == `x'
drop max_seq`x' _seq`x' _spell`x' _end`x' sum_end`x'
}
***********************************
levelsof seq if seq > 30, local(val)
foreach x of local val {
local debut = `x'-30
local fin = `x'-1
//disp `y'
tsspell in `debut' / `fin', cond(rfh > heavy_threshold)
rename _seq _seq`x'
rename _spell _spell`x'
rename _end _end`x'
******
egen max_seq`x' = max(_seq`x') in `debut'/`x'
replace heavy_length = max_seq`x' if seq == `x'
******
//gen _end`x' = .
replace _end`x' = 0 if heavy_period[_n]== 1 & heavy_period[_n-1]==. & heavy_period[_n+1]==. in `debut'/`x'
egen sum_end`x' = sum(_end`x') in `debut'/`x'
replace Number_cons_heavydays = sum_end`x' if seq == `x'
drop max_seq`x' _seq`x' _spell`x' _end`x' sum_end`x'
}
//save "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\BFA_Kadiogo_heavy.dta", replace
save "C:\Users\AHema\OneDrive - CGIAR\Desktop\2024\WFP\Spatial climate data\NER_Niamey_heavy.dta", replace