-
Notifications
You must be signed in to change notification settings - Fork 0
/
_building_weather_variables.do
446 lines (384 loc) · 24.2 KB
/
_building_weather_variables.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
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
* Francisco Cavalcanti
* Website: https://sites.google.com/view/franciscocavalcanti/
* GitHub: https://github.com/FranciscoCavalcanti
* Twitter: https://twitter.com/Franciscolc85
* LinkedIn: https://www.linkedin.com/in/francisco-de-lima-cavalcanti-5497b027/
// Replace missing observations in monthly historial mean
sort id_munic_7 year month
by id_munic_7 month, sort: egen sdff = mean(evaporacao)
by id_munic_7, sort: replace evaporacao = sdff if evaporacao ==.
drop sdff
sort id_munic_7 year month
by id_munic_7 month, sort: egen sdff = mean(chuva)
by id_munic_7, sort: replace chuva = sdff if chuva ==.
drop sdff
sort id_munic_7 year month
by id_munic_7 month, sort: egen sdff = mean(temperatura_media)
by id_munic_7, sort: replace temperatura_media = sdff if temperatura_media ==.
drop sdff
sort id_munic_7 year month
by id_munic_7 month, sort: egen sdff = mean(umidade)
by id_munic_7, sort: replace umidade = sdff if umidade ==.
drop sdff
///////////////////////////////////////////
/////
///// Generate cumulative weather measures
///// Regarding 12 monhts
/////
///////////////////////////////////////////
//Aridity Index - 12 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + /*
*/ month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11]
**if opa == 78 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 78
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] + /*
*/ chuva[_n-5] + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] + /*
*/ chuva[_n-11] if opa == 78
by id_munic_7, sort: gen inst2 = evaporacao[_n] + evaporacao[_n-1] + evaporacao[_n-2] + evaporacao[_n-3] + /*
*/ evaporacao[_n-4] + evaporacao[_n-5] + evaporacao[_n-6] + evaporacao[_n-7] + evaporacao[_n-8] + /*
*/ evaporacao[_n-9] + evaporacao[_n-10] + evaporacao[_n-11] if opa == 78
**Inverse of Aridity Index (higher numbers represent higher aridity) - 12 months
by id_munic_7, sort: gen aridity_evapo_12months = inst2/inst1
label variable aridity_evapo_12months "Aridity Index over 12 months"
drop opa inst*
//Quantity of Rainfall - 12 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11]
**if opa == 78 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 78
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] + chuva[_n-5] + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] + chuva[_n-11] if opa == 78
**Inverse of Aridity Index (higher numbers represent higher aridity) - 12 months
by id_munic_7, sort: gen acum_rain_12months = inst1
label variable acum_rain_12months "Cumulative rainfall over 12 months"
drop opa inst*
//Average Umidiy - 12 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11]
**if opa == 78 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 78
by id_munic_7, sort: gen inst1 = umidade[_n] + umidade[_n-1] + umidade[_n-2] + umidade[_n-3] + umidade[_n-4] + umidade[_n-5] + umidade[_n-6] + umidade[_n-7] + umidade[_n-8] + umidade[_n-9] + umidade[_n-10] + umidade[_n-11] if opa == 78
**average umidity - 12 months
by id_munic_7, sort: gen umidade_12months = inst1/12
label variable umidade_12months "Average umidiy over 12 months"
drop opa inst*
//Average Temperature - 12 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11]
**if opa == 78 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 78
by id_munic_7, sort: gen inst1 = temperatura_media[_n] + temperatura_media[_n-1] + temperatura_media[_n-2] + temperatura_media[_n-3] + temperatura_media[_n-4] + temperatura_media[_n-5] + temperatura_media[_n-6] + temperatura_media[_n-7] + temperatura_media[_n-8] + temperatura_media[_n-9] + temperatura_media[_n-10] + temperatura_media[_n-11] if opa == 78
**Average Temperature - 12 months
by id_munic_7, sort: gen temperatura_12months = inst1/12
label variable temperatura_12months "Average temperature over 12 months"
drop opa inst*
// The Standardised Precipitation-Evapotranspiration Index (SPEI)- 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + /*
*/ month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11]
**if opa == 78 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 78
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] + /*
*/ chuva[_n-5] + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] + /*
*/ chuva[_n-11] if opa == 78
by id_munic_7, sort: gen inst2 = evaporacao[_n] + evaporacao[_n-1] + evaporacao[_n-2] + evaporacao[_n-3] + /*
*/ evaporacao[_n-4] + evaporacao[_n-5] + evaporacao[_n-6] + evaporacao[_n-7] + evaporacao[_n-8] + /*
*/ evaporacao[_n-9] + evaporacao[_n-10] + evaporacao[_n-11] if opa == 78
**Difference between Evaporation and Precipitation (higher numbers represent higher aridity) - 12 months
by id_munic_7, sort: gen acum_SPEI_12months = inst2 - inst1
label variable acum_SPEI_12months "Cumulative SPEI over 12 months"
drop opa inst*
///////////////////////////////////////////
/////
///// Generate cumulative weather measures
///// Regarding 24 monhts
/////
///////////////////////////////////////////
//Aridity Index - 24 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] /*
*/ + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11] + month[_n-12] /*
*/ + month[_n-13] + month[_n-14] + month[_n-15] + month[_n-16] + month[_n-17] + month[_n-18] /*
*/ + month[_n-19] + month[_n-20] + month[_n-21] + month[_n-22] + month[_n-23]
**if opa == 156 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 156
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] /*
*/ + chuva[_n-5] + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] /*
*/ + chuva[_n-11] + chuva[_n-12] + chuva[_n-13] + chuva[_n-14] + chuva[_n-15] /*
*/ + chuva[_n-16] + chuva[_n-17] + chuva[_n-18] + chuva[_n-19] + chuva[_n-20] /*
*/ + chuva[_n-21] + chuva[_n-22] + chuva[_n-23] /*
*/ if opa == 156
by id_munic_7, sort: gen inst2 = evaporacao[_n] + evaporacao[_n-1] + evaporacao[_n-2] + evaporacao[_n-3] + evaporacao[_n-4] /*
*/ + evaporacao[_n-5] + evaporacao[_n-6] + evaporacao[_n-7] + evaporacao[_n-8] + evaporacao[_n-9] + evaporacao[_n-10] /*
*/ + evaporacao[_n-11] + evaporacao[_n-12] + evaporacao[_n-13] + evaporacao[_n-14] + evaporacao[_n-15] /*
*/ + evaporacao[_n-16] + evaporacao[_n-17] + evaporacao[_n-18] + evaporacao[_n-19] + evaporacao[_n-20] /*
*/ + evaporacao[_n-21] + evaporacao[_n-22] + evaporacao[_n-23] /*
*/ if opa == 156
**Inverse of Aridity Index (higher numbers represent higher aridity) - 24 months
by id_munic_7, sort: gen aridity_evapo_24months = inst2/inst1
label variable aridity_evapo_24months "Aridity Index over 24 months"
drop opa inst*
//Quantity of Rainfall - 24 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] /*
*/ + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11] + month[_n-12] /*
*/ + month[_n-13] + month[_n-14] + month[_n-15] + month[_n-16] + month[_n-17] + month[_n-18] /*
*/ + month[_n-19] + month[_n-20] + month[_n-21] + month[_n-22] + month[_n-23]
**if opa == 156 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 156
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] + chuva[_n-5] /*
*/ + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] /*
*/ + chuva[_n-11] + chuva[_n-12] + chuva[_n-13] + chuva[_n-14] + chuva[_n-15] /*
*/ + chuva[_n-16] + chuva[_n-17] + chuva[_n-18] + chuva[_n-19] + chuva[_n-20] /*
*/ + chuva[_n-21] + chuva[_n-22] + chuva[_n-23] /*
*/ if opa == 156
**Inverse of Aridity Index (higher numbers represent higher aridity) - 24 months
by id_munic_7, sort: gen acum_rain_24months = inst1
label variable acum_rain_24months "Cumulative rainfall over 24 months"
drop opa inst*
//Average Umidiy - 24 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] /*
*/ + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11] + month[_n-12] /*
*/ + month[_n-13] + month[_n-14] + month[_n-15] + month[_n-16] + month[_n-17] + month[_n-18] /*
*/ + month[_n-19] + month[_n-20] + month[_n-21] + month[_n-22] + month[_n-23]
**if opa == 156 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 156
by id_munic_7, sort: gen inst1 = umidade[_n] + umidade[_n-1] + umidade[_n-2] + umidade[_n-3] + umidade[_n-4] + umidade[_n-5] /*
*/ + umidade[_n-6] + umidade[_n-7] + umidade[_n-8] + umidade[_n-9] + umidade[_n-10] /*
*/ + umidade[_n-11] + umidade[_n-12] + umidade[_n-13] + umidade[_n-14] + umidade[_n-15] /*
*/ + umidade[_n-16] + umidade[_n-17] + umidade[_n-18] + umidade[_n-19] + umidade[_n-20] /*
*/ + umidade[_n-21] + umidade[_n-22] + umidade[_n-23] /*
*/ if opa == 156
**average umidity - 24 months
by id_munic_7, sort: gen umidade_24months = inst1/24
label variable umidade_24months "Average umidiy over 24 months"
drop opa inst*
//Average Temperature - 24 months
sort id_munic_7 year month
gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] /*
*/ + month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11] + month[_n-12] /*
*/ + month[_n-13] + month[_n-14] + month[_n-15] + month[_n-16] + month[_n-17] + month[_n-18] /*
*/ + month[_n-19] + month[_n-20] + month[_n-21] + month[_n-22] + month[_n-23]
**if opa == 156 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 156
by id_munic_7, sort: gen inst1 = temperatura_media[_n] + temperatura_media[_n-1] + temperatura_media[_n-2] + temperatura_media[_n-3] + temperatura_media[_n-4] + temperatura_media[_n-5] /*
*/ + temperatura_media[_n-6] + temperatura_media[_n-7] + temperatura_media[_n-8] + temperatura_media[_n-9] + temperatura_media[_n-10] /*
*/ + temperatura_media[_n-11] + temperatura_media[_n-12] + temperatura_media[_n-13] + temperatura_media[_n-14] + temperatura_media[_n-15] /*
*/ + temperatura_media[_n-16] + temperatura_media[_n-17] + temperatura_media[_n-18] + temperatura_media[_n-19] + temperatura_media[_n-20] /*
*/ + temperatura_media[_n-21] + temperatura_media[_n-22] + temperatura_media[_n-23] /*
*/ if opa == 156
**Average Temperature - 24 months
by id_munic_7, sort: gen temperatura_24months = inst1/24
label variable temperatura_24months "Average temperature over 24 months"
drop opa inst*
// The Standardised Precipitation-Evapotranspiration Index (SPEI)- 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen opa = month[_n] + month[_n-1] + month[_n-2] + month[_n-3] + month[_n-4] + month[_n-5] + /*
*/ month[_n-6] + month[_n-7] + month[_n-8] + month[_n-9] + month[_n-10] + month[_n-11] + month[_n-12] /*
*/ + month[_n-13] + month[_n-14] + month[_n-15] + month[_n-16] + month[_n-17] + month[_n-18] /*
*/ + month[_n-19] + month[_n-20] + month[_n-21] + month[_n-22] + month[_n-23]
**if opa == 156 our observations is continues in months
**so we just have to count cumulative rainfall if opa == 156
by id_munic_7, sort: gen inst1 = chuva[_n] + chuva[_n-1] + chuva[_n-2] + chuva[_n-3] + chuva[_n-4] + /*
*/ chuva[_n-5] + chuva[_n-6] + chuva[_n-7] + chuva[_n-8] + chuva[_n-9] + chuva[_n-10] /*
*/ + chuva[_n-11] + chuva[_n-12] + chuva[_n-13] + chuva[_n-14] + chuva[_n-15] /*
*/ + chuva[_n-16] + chuva[_n-17] + chuva[_n-18] + chuva[_n-19] + chuva[_n-20] /*
*/ + chuva[_n-21] + chuva[_n-22] + chuva[_n-23] /*
*/ if opa == 156
by id_munic_7, sort: gen inst2 = evaporacao[_n] + evaporacao[_n-1] + evaporacao[_n-2] + evaporacao[_n-3] + evaporacao[_n-4] /*
*/ + evaporacao[_n-5] + evaporacao[_n-6] + evaporacao[_n-7] + evaporacao[_n-8] + evaporacao[_n-9] + evaporacao[_n-10] /*
*/ + evaporacao[_n-11] + evaporacao[_n-12] + evaporacao[_n-13] + evaporacao[_n-14] + evaporacao[_n-15] /*
*/ + evaporacao[_n-16] + evaporacao[_n-17] + evaporacao[_n-18] + evaporacao[_n-19] + evaporacao[_n-20] /*
*/ + evaporacao[_n-21] + evaporacao[_n-22] + evaporacao[_n-23] /*
*/ if opa == 156
**Difference between Evaporation and Precipitation (higher numbers represent higher aridity) - 24 months
by id_munic_7, sort: gen acum_SPEI_24months = inst2 - inst1
label variable acum_SPEI_24months "Cumulative SPEI over 24 months"
drop opa inst*
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Lag of weather variables
//// Regarding variables of 12 monhts
////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Construct Lags of Measures of Rainfall
** Average Rainfall - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_rain_12months_lag1 = acum_rain_12months[_n-12]
by id_munic_7, sort: gen acum_rain_12months_lag2 = acum_rain_12months[_n-24]
by id_munic_7, sort: gen acum_rain_12months_lag3 = acum_rain_12months[_n-36]
* Construct Lags of Measures of Umidity
** Average Umidiy - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen umidade_12months_lag1 = umidade_12months[_n-12]
by id_munic_7, sort: gen umidade_12months_lag2 = umidade_12months[_n-24]
by id_munic_7, sort: gen umidade_12months_lag3 = umidade_12months[_n-36]
* Construct Lags of Measures of Temperature
** Average Temperature - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen temperatura_12months_lag1 = temperatura_12months[_n-12]
by id_munic_7, sort: gen temperatura_12months_lag2 = temperatura_12months[_n-24]
by id_munic_7, sort: gen temperatura_12months_lag3 = temperatura_12months[_n-36]
* Construct Lags of Measures of Aridity Index
** Aridity Index - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen aridity_evapo_12months_lag1 = aridity_evapo_12months[_n-12]
by id_munic_7, sort: gen aridity_evapo_12months_lag2 = aridity_evapo_12months[_n-24]
by id_munic_7, sort: gen aridity_evapo_12months_lag3 = aridity_evapo_12months[_n-36]
* Construct Lags of Measures of SPEI
** SPEI - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_SPEI_12months_lag1 = acum_SPEI_12months[_n-12]
by id_munic_7, sort: gen acum_SPEI_12months_lag2 = acum_SPEI_12months[_n-24]
by id_munic_7, sort: gen acum_SPEI_12months_lag3 = acum_SPEI_12months[_n-36]
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Lag of weather variables
//// Regarding variables of 24 monhts
////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Construct Lags of Measures of Rainfall
** Average Rainfall - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_rain_24months_lag1 = acum_rain_24months[_n-24]
by id_munic_7, sort: gen acum_rain_24months_lag2 = acum_rain_24months[_n-48]
* Construct Lags of Measures of Umidity
** Average Umidiy - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen umidade_24months_lag1 = umidade_24months[_n-24]
by id_munic_7, sort: gen umidade_24months_lag2 = umidade_24months[_n-48]
* Construct Lags of Measures of Temperature
** Average Temperature - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen temperatura_24months_lag1 = temperatura_24months[_n-24]
by id_munic_7, sort: gen temperatura_24months_lag2 = temperatura_24months[_n-48]
* Construct Lags of Measures of Aridity Index
** Aridity Index - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen aridity_evapo_24months_lag1 = aridity_evapo_24months[_n-24]
by id_munic_7, sort: gen aridity_evapo_24months_lag2 = aridity_evapo_24months[_n-48]
* Construct Lags of Measures of SPEI
** SPEI - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_SPEI_24months_lag1 = acum_SPEI_24months[_n-24]
by id_munic_7, sort: gen acum_SPEI_24months_lag2 = acum_SPEI_24months[_n-48]
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Lead of weather variables
//// Regarding variables of 12 monhts
////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Construct Leads of Measures of Rainfall
** Average Rainfall - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_rain_12months_lead1 = acum_rain_12months[_n+12]
by id_munic_7, sort: gen acum_rain_12months_lead2 = acum_rain_12months[_n+24]
by id_munic_7, sort: gen acum_rain_12months_lead3 = acum_rain_12months[_n+36]
* Construct Leads of Measures of Umidity
** Average Umidiy - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen umidade_12months_lead1 = umidade_12months[_n+12]
by id_munic_7, sort: gen umidade_12months_lead2 = umidade_12months[_n+24]
by id_munic_7, sort: gen umidade_12months_lead3 = umidade_12months[_n+36]
* Construct Leads of Measures of Temperature
** Average Temperature - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen temperatura_12months_lead1 = temperatura_12months[_n+12]
by id_munic_7, sort: gen temperatura_12months_lead2 = temperatura_12months[_n+24]
by id_munic_7, sort: gen temperatura_12months_lead3 = temperatura_12months[_n+36]
* Construct Leads of Measures of Aridity Index
** Aridity Index - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen aridity_evapo_12months_lead1 = aridity_evapo_12months[_n+12]
by id_munic_7, sort: gen aridity_evapo_12months_lead2 = aridity_evapo_12months[_n+24]
by id_munic_7, sort: gen aridity_evapo_12months_lead3 = aridity_evapo_12months[_n+36]
* Construct Leads of Measures of SPEI
** SPEI - 12 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_SPEI_12months_lead1 = acum_SPEI_12months[_n+12]
by id_munic_7, sort: gen acum_SPEI_12months_lead2 = acum_SPEI_12months[_n+24]
by id_munic_7, sort: gen acum_SPEI_12months_lead3 = acum_SPEI_12months[_n+36]
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Lead of weather variables
//// Regarding variables of 24 monhts
////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* Construct Leads of Measures of Rainfall
** Average Rainfall - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_rain_24months_lead1 = acum_rain_24months[_n+24]
by id_munic_7, sort: gen acum_rain_24months_lead2 = acum_rain_24months[_n+48]
* Construct Leads of Measures of Umidity
** Average Umidiy - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen umidade_24months_lead1 = umidade_24months[_n+24]
by id_munic_7, sort: gen umidade_24months_lead2 = umidade_24months[_n+48]
* Construct Leads of Measures of Temperature
** Average Temperature - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen temperatura_24months_lead1 = temperatura_24months[_n+24]
by id_munic_7, sort: gen temperatura_24months_lead2 = temperatura_24months[_n+48]
* Construct Leads of Measures of Aridity Index
** Aridity Index - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen aridity_evapo_24months_lead1 = aridity_evapo_24months[_n+24]
by id_munic_7, sort: gen aridity_evapo_24months_lead2 = aridity_evapo_24months[_n+48]
* Construct Leads of Measures of SPEI
** SPEI - 24 months
sort id_munic_7 year month
by id_munic_7, sort: gen acum_SPEI_24months_lead1 = acum_SPEI_24months[_n+24]
by id_munic_7, sort: gen acum_SPEI_24months_lead2 = acum_SPEI_24months[_n+48]
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Average and standard deviation of weather variables
////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
* keep only observations by year
keep if month ==12
// Calculating the average of cumulative rainfall each year and its standard deviation
by id_munic_7: egen mean_acum_rain_12months = mean(acum_rain_12months)
by id_munic_7: egen sd_acum_rain_12months = sd(acum_rain_12months)
label variable mean_acum_rain_12months "Historial mean of rainfall"
label variable sd_acum_rain_12months "Standard deviation of historical rainfall"
by id_munic_7: egen mean_acum_rain_24months = mean(acum_rain_24months)
by id_munic_7: egen sd_acum_rain_24months = sd(acum_rain_24months)
label variable mean_acum_rain_24months "Historial mean of rainfall"
label variable sd_acum_rain_24months "Standard deviation of historical rainfall"
// Calculating the average of cumulative aridity index each year and its standard deviation
by id_munic_7: egen mean_aridity_evapo_12months = mean(aridity_evapo_12months)
by id_munic_7: egen sd_aridity_evapo_12months = sd(aridity_evapo_12months)
label variable mean_aridity_evapo_12months "Historial mean of aridity index"
label variable sd_aridity_evapo_12months "Standard deviation of historical aridity index"
by id_munic_7: egen mean_aridity_evapo_24months = mean(aridity_evapo_24months)
by id_munic_7: egen sd_aridity_evapo_24months = sd(aridity_evapo_24months)
label variable mean_aridity_evapo_24months "Historial mean of aridity index"
label variable sd_aridity_evapo_24months "Standard deviation of historical aridity index"
// Calculating the average of cumulative umidity each year and its standard deviation
by id_munic_7: egen mean_umidade_12months = mean(umidade_12months)
by id_munic_7: egen sd_umidade_12months = sd(umidade_12months)
label variable mean_umidade_12months "Historial mean of umidity"
label variable sd_umidade_12months "Standard deviation of historical umidity"
by id_munic_7: egen mean_umidade_24months = mean(umidade_24months)
by id_munic_7: egen sd_umidade_24months = sd(umidade_24months)
label variable mean_umidade_24months "Historial mean of umidity"
label variable sd_umidade_24months "Standard deviation of historical umidity"
// Calculating the average of cumulative temperature each year and its standard deviation
by id_munic_7: egen mean_temperatura_12months = mean(temperatura_12months)
by id_munic_7: egen sd_temperatura_12months = sd(temperatura_12months)
label variable mean_temperatura_12months "Historial mean of temperature"
label variable sd_temperatura_12months "Standard deviation of historical temperature"
by id_munic_7: egen mean_temperatura_24months = mean(temperatura_24months)
by id_munic_7: egen sd_temperatura_24months = sd(temperatura_24months)
label variable mean_temperatura_24months "Historial mean of temperature"
label variable sd_temperatura_24months "Standard deviation of historical temperature"
// Calculating the average of cumulative rainfall each year and its standard deviation
by id_munic_7: egen mean_acum_SPEI_12months = mean(acum_SPEI_12months)
by id_munic_7: egen sd_acum_SPEI_12months = sd(acum_SPEI_12months)
label variable mean_acum_SPEI_12months "Historial mean of SPEI"
label variable sd_acum_SPEI_12months "Standard deviation of historical SPEI"
by id_munic_7: egen mean_acum_SPEI_24months = mean(acum_SPEI_24months)
by id_munic_7: egen sd_acum_SPEI_24months = sd(acum_SPEI_24months)
label variable mean_acum_SPEI_24months "Historial mean of SPEI"
label variable sd_acum_SPEI_24months "Standard deviation of historical SPEI"