-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparaison.do
487 lines (323 loc) · 15.7 KB
/
Comparaison.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
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
*** Programme de comparaison des résultats entre notre façon d'estimer les transport costs, et celle proposée par le référé 1
*** Étendu à d’autres comparaisons
*** Juillet 2020
if "`c(username)'" =="guillaumedaudin" {
global dir_baseline_results "~/Documents/Recherche/2013 -- Trade Costs -- local/results/baseline"
global dir_referee1 "~/Documents/Recherche/2013 -- Trade Costs -- local/results/referee1"
global dir "~/Documents/Recherche/2013 -- Trade Costs -- local"
global dir_comparaison "~/Documents/Recherche/2013 -- Trade Costs -- local/results/comparaisons_various"
global dir_temp ~/Downloads/temp_stata
global dir_results "~/Documents/Recherche/2013 -- Trade Costs -- local/results"
global dir_redaction "~/Répertoires Git/trade_costs_git/redaction/JEGeo/revision_JEGeo/revised_article"
global dir_git "~/Répertoires Git/trade_costs_git/"
}
*** Juillet 2020: Lise, tout sur mon OneDrive
/* Fixe Lise P112*/
if "`c(hostname)'" =="LAB0271A" {
* baseline results sur hummels_tra dans son intégralité
global dir_baseline_results "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\baseline"
* résultats selon méthode référé 1
global dir_referee1 "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\referee1"
* stocker la comparaison des résultats
global dir_comparaison "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\referee1\comparaison_baseline_referee1"
/* Il me manque pour faire méthode 2 en IV
- IV_referee1_panel/results_estimTC_`year'_sitc2_3_`mode'.dta
- IV_ref1_y/results_estimTC_`year'_sitc2_3_`mode'.dta
*/
global dir_temp "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\temp"
global dir "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs"
global dir_results "C:\Users\lpatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results"
}
/* Nouveau portable Lise */
if "`c(hostname)'" =="MSOP112C" {
* baseline results sur hummels_tra dans son intégralité
global dir_baseline_results "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\baseline"
* résultats selon méthode référé 1
global dir_referee1 "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\referee1"
* stocker la comparaison des résultats
global dir_comparaison "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results\referee1\comparaison_baseline_referee1"
/* Il me manque pour faire méthode 2 en IV
- IV_referee1_panel/results_estimTC_`year'_sitc2_3_`mode'.dta
- IV_ref1_y/results_estimTC_`year'_sitc2_3_`mode'.dta
*/
global dir_temp "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\temp"
global dir "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs"
global dir_results "C:\Users\Ipatureau\OneDrive - Université Paris-Dauphine\Université Paris-Dauphine\trade_costs\results"
}
set more off
/*
************Comparaison de base
use "$dir/data/hummels_tra.dta", clear
contract year iso_o sitc2 mode
tab _freq
/*Cela confirme que year iso_o sitc2 mode sont les clefs du fichier*/
use "$dir/data/base_hs10_newyears.dta", clear
contract year iso_o mode hs dist_entry
tab _freq
*Ce n’est pas une clef unique ?! Donc il y a plusieurs consignements par produit/district dans base_hs10_newyears ?
use "$dir/data/hummels_tra.dta", clear
keep if year >=2005
merge 1:m year iso_o sitc2 mode using "$dir/data/base_hs10_newyears.dta", force
tab mode _merge
**Semble suggérer qu’il y a plus de choses dans HS10 que dans hummels_tra... (même au delà des cnt)
drop if sitc2==""
tab mode _merge
drop if mode=="cnt"
tab _merge
*****Donc tout le problème est bien lié à mode=="cnt" et aux sitc vides
generate sector = substr(sitc2,1,3)
codebook sector
contract year iso_o sector mode
describe
******************************************
***************** Pour vérifier que le merge se fait sur les bases d’orgine... c’est bon aussi
use "$dir/data/hummels_tra.dta", clear
rename sitc2 sector
drop if sector==""
assert strlen(sector)==5
replace sector = substr(sector,1,3)
keep if year >=2005
contract year iso_o sector mode
save temp_hummels_tra.dta, replace
use "$dir/data/base_hs10_newyears.dta", clear
rename sitc2 sector
drop if sector==""
assert strlen(sector)==5
replace sector = substr(sector,1,3)
drop if mode=="cnt"
contract year iso_o sector mode
merge 1:1 year sector iso_o mode using temp_hummels_tra.dta, force
erase temp_hummels_tra.dta
***********************
*/
** Faire tourner sur toutes les années /mode
/* method1 peut être
- "baseline" (nos benchmark results en s=3 digits, k=5 digits)
- "baseline10" (nos benchmark results en s=3 digits, k=10 digits)
- "baselinesamplereferee1" = notre methode sur le sample issu de la méthode du référé 1, en s=3, k=5 ou 10 (A ACTUALISER)
method2 peut être
- "referee1" (methode OLS référé 1), s=3 k=10
- "baseline10" (nos benchmark results en s=3 digits, k=10 digits)
- "IV_referee1_panel" (??)
- "IV_ref1_y" (??)
*/
do "$dir_git/Open_year_mode_method_model.do"
******************************************************
******************************************************
capture program drop comparaison_by_year_mode
program comparaison_by_year_mode
args year mode method1 method2
open_year_mode_method_model `year' `mode' `method1' `model'
bys iso_o sector : keep if _n==1
capture drop _merge
rename beta beta_method1
save "$dir_temp/`method1'_`method2'.dta", replace
open_year_mode_method_model `year' `mode' `method2' `model'
bys iso_o sector : keep if _n==1
capture drop _merge
rename beta beta_method2
merge 1:1 iso_o sector using "$dir_temp/`method1'_`method2'.dta"
drop _merge
erase "$dir_temp/`method1'_`method2'.dta"
*** Comparaison des beta
/*
graph twoway (scatter beta_method2 beta_method1) (lfit beta_method2 beta_method1), ///
title("For `year', `mode'") scheme(s1mono)
graph export "$dir_comparaison/scatter_`year'_`mode'_`method1'_`method2'.png", replace
*/
*** Statistiques
clear
open_year_mode_method_model `year' `mode' `method1' `model'
rename beta beta_`method1'
gen Nb_baseline=_N
quietly summarize beta_`method1', det
generate beta_`method1'_mean = r(mean)
generate beta_`method1'_med = r(p50)
quietly summarize beta_`method1' [fweight=val], det
generate beta_`method1'_mean_pd = r(mean)
generate beta_`method1'_med_pd = r(p50)
generate blif = iso_o+sector
quietly levelsof blif
generate Nb_cx3ds_baseline = r(r)
label var Nb_cx3ds_baseline "Number of country x 3 digit sector included in the `method1'"
label var cover_`method1' "Total value of trade flows covered in the `method1'"
** pourquoi ça ne marche plus ??? Nb_cx3ds_baseline est totalement missing??? ***
drop blif
keep mode cover_`method1'-Nb_cx3ds_baseline
keep if _n==1
capture gen year=`year'
capture gen methode1 = "`method1'"
capture append using "$dir_comparaison/stats_comp_`method1'_`method2'.dta"
save "$dir_comparaison/stats_comp_`method1'_`method2'.dta", replace
clear
open_year_mode_method_model `year' `mode' `method2' `model'
capture drop group_sect
egen group_sect=group(sector)
su group_sect, meanonly
gen Nb_sector=r(max)
drop group_sect
label var Nb_sector "Nb of sectors in `method2'"
egen group_iso=group(iso_o)
su group_iso, meanonly
gen Nb_iso=r(max)
drop group_iso
label var Nb_iso "Nb of origin countries in `method2'"
rename beta beta_`method2'
gen Nb_`method2'=_N
quietly summarize beta_`method2', det
generate beta_`method2'_mean = r(mean)
generate beta_`method2'_med = r(p50)
quietly summarize beta_`method2' [fweight=val], det
generate beta_`method2'_mean_pd = r(mean)
generate beta_`method2'_med_pd = r(p50)
generate blif = iso_o+sector
quietly levelsof blif
generate Nb_cx3ds = r(r)
label var Nb_cx3ds "Number of country x 3 digit sector included in `method2' test"
label var cover_`method2' "Total value of trade flows covered in `method2' test"
drop blif
drop beta_`method2'
keep Nb_iso Nb_sector cover_`method2'-Nb_cx3ds
keep if _n==1
capture gen year=`year'
capture gen mode="`mode'"
gen methode2 = "`method2'"
merge 1:1 year mode using "$dir_comparaison/stats_comp_`method1'_`method2'.dta"
drop _merge
save "$dir_comparaison/stats_comp_`method1'_`method2'.dta", replace
end
*** A FAIRE APRES PGM comparaison_by_year_mode
capture program drop comparaison_graph
program comparaison_graph
args method1 method2
use "$dir_comparaison/stats_comp_`method1'_`method2'.dta", clear
/*
graph twoway (scatter beta_`method2'_mean beta_`method1'_mean) (lfit beta_`method2'_mean beta_`method1'_mean) ///
(scatter beta_`method2'_mean_pd beta_`method1'_mean_pd) (lfit beta_`method2'_mean_pd beta_`method1'_mean_pd) ///
(scatter beta_`method2'_med beta_`method1'_med) (lfit beta_`method2'_med beta_`method1'_med) ///
(scatter beta_`method2'_med_pd beta_`method1'_med_pd) (lfit beta_`method2'_med_pd beta_`method1'_med_pd), ///
ytitle("`method1'") xtitle("`method2'") scheme(s1mono)
graph export "$dir_comparaison/scatter_comparaison_`method1'_`method2'.png", replace
*/
keep year mode beta*
reshape long beta_, i(year mode) j(type) string
gen method="`method2'"
tab type
replace method="`method1'" if strmatch(type,"`method1'_*")!=0
* faire les différents cas possibles**Mais je ne crois plus que ce soit utile ? GD 2 mars 2021
/*
if method=="baseline" {
replace type = substr(type, 10,.) if strmatch(type,"`method1'*")!=0
}
if method=="baseline10" {
replace type = substr(type, 12,.) if strmatch(type,"`method1'*")!=0
}
if method=="baselinesamplereferee1" {
replace type = substr(type, 24,.) if strmatch(type,"`method1'*")!=0
}
*/
replace type = subinstr(type,"${method1}_","",.)
replace type = subinstr(type,"${method2}_","",.)
reshape wide beta_,i(year mode type) j(method) string
/*
graph twoway (scatter beta_`method2' beta_`method1') (lfit beta_`method2' beta_`method1'), ///
ytitle("`method1'") xtitle("`method2'") by(mode type) scheme(s1mono)
graph export "$dir_comparaison/scatter_comparaison_by_type_`method1'_`method2'.png", replace
*/
capture label var beta_IV_ref1_y_5_3 "beta computed by IV"
capture label var beta_baseline "beta baseline"
capture label var beta_baseline10 "beta 10/3"
capture label var beta_dbsamesample10_5_3 "beta baseline"
replace type="Unweighted mean" if type=="mean"
replace type="Unweighted median" if type=="med"
replace type="Weighted median" if type=="med_pd"
replace type="Weighted mean" if type=="mean_pd"
replace mode="Air" if mode=="air"
replace mode="Vessel" if mode=="ves"
*graph twoway (line beta_`method1' year) (line beta_`method2' year), by(mode type, cols(4) iscale(*.8)) scheme(s1mono)
keep if (type=="Weighted median" | type == "Weighted mean")
if "`method1'" == "baseline10" label var beta_`method1' "{it:{&beta}} 10/3"
if "`method1'" == "dbsamesample10_5_3" label var beta_`method1' "{it:{&beta}} baseline"
if "`method1'" == "baseline" label var beta_`method1' "{it:{&beta}} baseline"
if "`method1'" == "non_separe_wgt" label var beta_`method1' "{it:{&beta}}, price per kg"
if "`method1'" == "pour_robustesse_ns" label var beta_`method1' "{it:{&beta}} baseline same sample"
if "`method1'" == "non_separe" label var beta_`method1' "{it:{&beta}} without the separability assumption"
if "`method2'" == "baseline" label var beta_`method2' "{it:{&beta}} baseline"
if "`method2'" == "dbsamesample10_5_3" label var beta_`method2' "{it:{&beta}} baseline"
if "`method2'" == "IV_ref1_y_5_3" label var beta_`method2' "{it:{&beta}} computed by IV"
if "`method2'" == "referee1" label var beta_`method2' "direct {it:{&beta}} estimate"
if "`method2'" == "non_separe_qy" label var beta_`method2' "{it:{&beta}}, price per unit"
if "`method2'" == "pour_robustesse_ns" label var beta_`method2' "{it:{&beta}} baseline, same sample"
if "`method2'" == "pour_robustesse_ns" local label 1980(20)2020
if "`method2'" == "non_separe_qy" local lobel 2010(5)2020
if "`method2'" == "pour_robustesse_ns" local range 1974 2020
if "`method2'" == "non_separe_qy" local range 2009 2020
graph twoway (line beta_`method1' year) (line beta_`method2' year), xscale(range(`range')) xlabel(`label') by(mode type, note("") cols(2) iscale(*.8)) scheme(s1mono)
graph export "$dir_comparaison/scatter_chronology_`method1'_`method2'.png", replace
graph export "$dir_redaction/scatter_chronology_`method1'_`method2'.png", replace
end
*****************************************************************************************
***on lance les comparaisons
*****************************************************************************************
capture program drop comparaison
program comparaison
args method1 method2
global method1 `method1'
global method2 `method2'
if "$method1"=="baseline10" | "$method"=="dbsamesample10_5_3" local time_span 2005/2019
if "$method1"=="non_separe_wgt" | "$method2"=="non_separe_wgt" local time_span 2009/2019
if "$method1"=="referee1" | "$method2"=="referee1" local time_span 2005/2013
if "$method1"=="baseline" | "$method2"=="non_separe" local time_span 1974/2019
if "$method2"=="IV_ref1_y_5_3" | "$method1"=="IV_ref1_y_5_3" local time_span 1975/2019
if "$method2"=="referee1" | "$method1"=="referee1" local time_span 2005/2013
if "$method1"=="non_separe" local time_span 1974/2019
capture erase "$dir_comparaison/stats_comp_${method1}_$method2.dta"
foreach year of num `time_span' {
foreach mode in ves air {
*if ("`mode'"!="air" | `year' != 2013) comparaison_by_year_mode `year' `mode' $method1 $method2
if "$method1"=="qy1_wgt" {
if (`year' != 1987 | "`mode'"=="air") & (`year' != 2002 | "`mode'"=="air") & (`year' != 2012 | "`mode'"=="ves") & (`year' != 2013) comparaison_by_year_mode `year' `mode' $method1 $method2
}
else if "$method2"=="non_separe" | "$method1"=="non_separe"{
if (`year' != 2014 | "`mode'"!="ves") comparaison_by_year_mode `year' `mode' $method1 $method2
}
else comparaison_by_year_mode `year' `mode' $method1 $method2
}
}
use "$dir_comparaison/stats_comp_${method1}_$method2.dta", clear
gen method2_value_method1=cover_$method2/cover_$method1
label var method2_value_method1 "Covered value of trade flows by $method2 as a share of $method1"
gen method2_nbpair_method1=Nb_cx3ds/Nb_cx3ds_baseline
label var method2_nbpair_method1 "Covered bilateral trade flows by products by $method2 as a share of $method1"
sort mode year
save "$dir_comparaison/stats_comp_${method1}_$method2.dta", replace
cd "$dir_comparaison"
use stats_comp_${method1}_$method2.dta
export excel using stats_comp_${method1}_$method2.xls, firstrow(varl) replace
* Pb sur les graphiques sur baseline10 as methode1
*/
comparaison_graph $method1 $method2
end
*comparaison baseline10 dbsamesample10_5_3 /* pour comparer avec l’hypothèse d’aggrégation (figure 4)*/
*comparaison baseline IV_ref1_y_5_3 /* pour comparer avec l'hypothèse d'aggrégation (figure 3)*/
*comparaison baseline referee1 /* pour comparer avec les beta directement (figure D3)*/
comparaison non_separe_wgt non_separe_qy /* pour comparer avec non-séparé _poids (figure C4)*/
*comparaison non_separe pour_robustesse_ns /* pour comparer avec non-séparé _poids (figure C4)*/
*global method1 baseline
*global method1 baseline10
*global method1 baseline
*baseline pour baseline 5/3
*global method2 IV_ref1_y_5_3
*global method1 qy1_wgt
*global method1 hs10_qy1_wgt
*global method1 non_separe_wgt
******
*global method2 IV_referee1_panel
*global method2 IV_ref1_y_5_3
*global method2 baseline10
*global method2 qy1_qy
*global method2 hs10_qy1_qy
*global method2 dbsamesample10_5_3
*global method2 non_separe_qy
*global method2 referee1
*global method2 non_separe