Dear Stata community,
I am constructing my dataset (a panel data) in order to estimate a gravity model further on.
I am having issues merging some variables from a gravity database onto my main dataset. The latter includes bilateral trade by HS6 product codes that I have selected, through years 1996-2020.
Whenever I try to merge a variable such as distance, an error occurs:
merge 1:m year iso3num_o iso3num_d dist using rawdata\Comtrade\Gravity_V202211
variables year iso3num_o iso3num_d dist do not uniquely identify observations in the master data
r(459)
I understand that possibly the problem may come from my main dataset, as there is a repetition in the years (as a pair can trade more than one product in the same year). I have then tried to delete the dupes by replacing the HS6 product codes by the NACE revision classification, which groups several of the HS product codes into one code, and then by doing the total of the value and the quantity, to eliminate the duplicates that were there. However, the issue still remains.
I have also tried to delete from the gravity dataset some observations that aren't useful (such as the years previous to 1996, and trade pairs that are not listed into my main dataset). However, this seems to be quite cumbersome and I am not sure that it would actually solve the issue.
Is there a way to go through this problem?
Below you can see the dataex of my main dataset:
Thanks in advance for your help,
Eleonora
I am constructing my dataset (a panel data) in order to estimate a gravity model further on.
I am having issues merging some variables from a gravity database onto my main dataset. The latter includes bilateral trade by HS6 product codes that I have selected, through years 1996-2020.
Whenever I try to merge a variable such as distance, an error occurs:
merge 1:m year iso3num_o iso3num_d dist using rawdata\Comtrade\Gravity_V202211
variables year iso3num_o iso3num_d dist do not uniquely identify observations in the master data
r(459)
I understand that possibly the problem may come from my main dataset, as there is a repetition in the years (as a pair can trade more than one product in the same year). I have then tried to delete the dupes by replacing the HS6 product codes by the NACE revision classification, which groups several of the HS product codes into one code, and then by doing the total of the value and the quantity, to eliminate the duplicates that were there. However, the issue still remains.
I have also tried to delete from the gravity dataset some observations that aren't useful (such as the years previous to 1996, and trade pairs that are not listed into my main dataset). However, this seems to be quite cumbersome and I am not sure that it would actually solve the issue.
Is there a way to go through this problem?
Below you can see the dataex of my main dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int(year iso3num_o iso3num_d) str6 hs6 float value double quantity str32 exporter_name str52 importer_name float bilateral 1996 842 4 "854190" 13.049 . "USA" "Afghanistan" 20808 1996 842 4 "853400" 75.27 .084 "USA" "Afghanistan" 20808 1996 842 4 "854250" 84.861 .124 "USA" "Afghanistan" 20808 1996 246 4 "854140" 1.11 .04 "Finland" "Afghanistan" 6871 1996 842 4 "854230" 26.436 .006 "USA" "Afghanistan" 20808 1996 842 4 "854110" 5.5 .002 "USA" "Afghanistan" 20808 1996 842 4 "854290" 24.264 . "USA" "Afghanistan" 20808 1996 842 4 "854140" 2.841 . "USA" "Afghanistan" 20808 1996 842 4 "854212" 7.6 .011 "USA" "Afghanistan" 20808 1996 842 4 "854214" 86.694 .427 "USA" "Afghanistan" 20808 1996 842 4 "854213" 87.871 .625 "USA" "Afghanistan" 20808 1996 842 4 "854219" 23.414 .015 "USA" "Afghanistan" 20808 1996 484 4 "853400" 4.559 .359 "Mexico" "Afghanistan" 12635 1996 842 4 "854240" 7.324 .002 "USA" "Afghanistan" 20808 1996 381 8 "853400" 81.715 .887 "Italy" "Albania" 9882 1996 251 8 "854212" 87.164 1.312 "France" "Albania" 7140 1996 40 8 "854213" 72.171 .066 "Austria" "Albania" 1089 1996 381 8 "854250" 176.064 . "Italy" "Albania" 9882 1996 276 8 "853400" 1.845 .014 "Germany" "Albania" 7663 1996 792 8 "854190" 7.266 2.125 "Turkey" "Albania" 20471 1996 381 8 "903141" 1.213 .053 "Italy" "Albania" 9882 1996 203 8 "854110" .663 .009 "Czechia" "Albania" 5213 1996 40 8 "854214" 4.156 .001 "Austria" "Albania" 1089 1996 842 8 "854290" 31.759 . "USA" "Albania" 20809 1996 372 8 "853400" 1.906 .222 "Ireland" "Albania" 9505 1996 251 8 "854230" 3.126 .005 "France" "Albania" 7140 1996 381 8 "854213" 3.221 .074 "Italy" "Albania" 9882 1996 58 8 "854290" 66.911 .014 "Belgium-Luxembourg" "Albania" 1996 1996 300 8 "854110" .668 .001 "Greece" "Albania" 8036 1996 276 8 "854213" .664 . "Germany" "Albania" 7663 1996 276 8 "854230" 1.163 . "Germany" "Albania" 7663 1996 381 8 "854129" 9.284 .003 "Italy" "Albania" 9882 1996 300 8 "854121" 4.557 .05 "Greece" "Albania" 8036 1996 381 8 "854110" 2.365 . "Italy" "Albania" 9882 1996 381 8 "854219" 5.849 .047 "Italy" "Albania" 9882 1996 757 8 "854129" 17.031 .21 "Switzerland" "Albania" 19433 1996 348 8 "854213" 10 . "Hungary" "Albania" 8635 1996 807 8 "854212" 1.108 .003 "TFYR of Macedonia" "Albania" 19729 1996 381 8 "854212" 19.383 .081 "Italy" "Albania" 9882 1996 381 8 "854290" 24.037 .824 "Italy" "Albania" 9882 1996 348 8 "903141" 13.045 .8 "Hungary" "Albania" 8635 1996 40 8 "854110" 1.228 .034 "Austria" "Albania" 1089 1996 40 8 "854212" 5.357 . "Austria" "Albania" 1089 1996 381 8 "854121" 23.484 .01 "Italy" "Albania" 9882 1996 276 8 "854190" 57.584 1.187 "Germany" "Albania" 7663 1996 276 8 "854129" 1.328 .004 "Germany" "Albania" 7663 1996 58 8 "903141" 1.189 .018 "Belgium-Luxembourg" "Albania" 1996 1996 842 8 "854250" 112.423 . "USA" "Albania" 20809 1996 842 8 "854110" 148.576 .029 "USA" "Albania" 20809 1996 807 8 "854230" 1.458 .004 "TFYR of Macedonia" "Albania" 19729 1996 381 8 "854140" 18.992 .613 "Italy" "Albania" 9882 1996 156 12 "853400" 3.392 .476 "China" "Algeria" 3825 1996 156 12 "854110" 17.364 2.077 "China" "Algeria" 3825 1996 251 12 "854240" 203.007 .345 "France" "Algeria" 7141 1996 381 12 "854230" 99.475 .203 "Italy" "Algeria" 9883 1996 372 12 "854212" 31.513 .468 "Ireland" "Algeria" 9506 1996 410 12 "903141" 30.343 1.312 "Rep. of Korea" "Algeria" 16029 1996 528 12 "854250" 16.046 .153 "Netherlands" "Algeria" 13582 1996 40 12 "854140" 1.889 .049 "Austria" "Algeria" 1090 1996 752 12 "854250" 1.039 .002 "Sweden" "Algeria" 19221 1996 826 12 "854290" 7.766 .003 "United Kingdom" "Algeria" 21494 1996 344 12 "854121" 21.227 .14 "China, Hong Kong SAR" "Algeria" 4041 1996 752 12 "854121" 34.451 .261 "Sweden" "Algeria" 19221 1996 579 12 "854250" 6.552 .002 "Norway" "Algeria" 14345 1996 392 12 "854140" 6.379 .005 "Japan" "Algeria" 10194 1996 251 12 "854290" 382.259 10.445 "France" "Algeria" 7141 1996 251 12 "854214" 28.285 .236 "France" "Algeria" 7141 1996 702 12 "854129" 27.113 6.375 "Singapore" "Algeria" 17699 1996 842 12 "854160" 9.144 .004 "USA" "Algeria" 20810 1996 826 12 "854212" 8.005 .062 "United Kingdom" "Algeria" 21494 1996 392 12 "854212" 97.832 .738 "Japan" "Algeria" 10194 1996 826 12 "854213" 40.325 .05 "United Kingdom" "Algeria" 21494 1996 381 12 "854240" 150.248 .984 "Italy" "Algeria" 9883 1996 58 12 "854140" 14.585 .121 "Belgium-Luxembourg" "Algeria" 1997 1996 724 12 "854250" 17.492 .25 "Spain" "Algeria" 18645 1996 458 12 "854230" 35.667 .132 "Malaysia" "Algeria" 11879 1996 757 12 "854140" 131.027 5.113 "Switzerland" "Algeria" 19434 1996 40 12 "854219" 7.485 .012 "Austria" "Algeria" 1090 1996 381 12 "854130" 92.99 .359 "Italy" "Algeria" 9883 1996 156 12 "854129" 24.779 .292 "China" "Algeria" 3825 1996 724 12 "854140" 524.997 18.755 "Spain" "Algeria" 18645 1996 764 12 "854110" 1.448 .027 "Thailand" "Algeria" 19875 1996 842 12 "854190" 7.639 .093 "USA" "Algeria" 20810 1996 752 12 "854190" .768 .009 "Sweden" "Algeria" 19221 1996 757 12 "854129" 19.035 .299 "Switzerland" "Algeria" 19434 1996 762 12 "854219" 1.842 .292 "Tajikistan" "Algeria" 19814 1996 392 12 "854250" 105.024 .171 "Japan" "Algeria" 10194 1996 156 12 "854250" 3.227 .156 "China" "Algeria" . 1996 752 12 "854129" 39.23 .234 "Sweden" "Algeria" 19221 1996 381 12 "903141" 3.895 .002 "Italy" "Algeria" 9883 1996 124 12 "854219" 23.044 .171 "Canada" "Algeria" 3346 1996 724 12 "854121" 8.989 .203 "Spain" "Algeria" 18645 1996 490 12 "854250" 28.005 .277 "Other Asia, nes" "Algeria" 14633 1996 702 12 "854219" 13.804 .472 "Singapore" "Algeria" 17699 1996 826 12 "854121" .829 .003 "United Kingdom" "Algeria" 21494 1996 276 12 "854213" 15.947 .01 "Germany" "Algeria" 7664 1996 752 12 "854110" 26.195 1.76 "Sweden" "Algeria" 19221 1996 757 12 "854250" 34.108 .025 "Switzerland" "Algeria" 19434 1996 208 12 "854130" 73.246 .445 "Denmark" "Algeria" 5702 1996 381 12 "854160" 2.979 .105 "Italy" "Algeria" 9883 end label values bilateral trade label def trade 1089 "Austria Albania", modify label def trade 1090 "Austria Algeria", modify label def trade 1996 "Belgium-Luxembourg Albania", modify label def trade 1997 "Belgium-Luxembourg Algeria", modify label def trade 3346 "Canada Algeria", modify label def trade 3825 "China Algeria", modify label def trade 4041 "China, Hong Kong SAR Algeria", modify label def trade 5213 "Czechia Albania", modify label def trade 5702 "Denmark Algeria", modify label def trade 6871 "Finland Afghanistan", modify label def trade 7140 "France Albania", modify label def trade 7141 "France Algeria", modify label def trade 7663 "Germany Albania", modify label def trade 7664 "Germany Algeria", modify label def trade 8036 "Greece Albania", modify label def trade 8635 "Hungary Albania", modify label def trade 9505 "Ireland Albania", modify label def trade 9506 "Ireland Algeria", modify label def trade 9882 "Italy Albania", modify label def trade 9883 "Italy Algeria", modify label def trade 10194 "Japan Algeria", modify label def trade 11879 "Malaysia Algeria", modify label def trade 12635 "Mexico Afghanistan", modify label def trade 13582 "Netherlands Algeria", modify label def trade 14345 "Norway Algeria", modify label def trade 14633 "Other Asia, nes Algeria", modify label def trade 16029 "Rep. of Korea Algeria", modify label def trade 17699 "Singapore Algeria", modify label def trade 18645 "Spain Algeria", modify label def trade 19221 "Sweden Algeria", modify label def trade 19433 "Switzerland Albania", modify label def trade 19434 "Switzerland Algeria", modify label def trade 19729 "TFYR of Macedonia Albania", modify label def trade 19814 "Tajikistan Algeria", modify label def trade 19875 "Thailand Algeria", modify label def trade 20471 "Turkey Albania", modify label def trade 20808 "USA Afghanistan", modify label def trade 20809 "USA Albania", modify label def trade 20810 "USA Algeria", modify label def trade 21494 "United Kingdom Algeria", modify
Thanks in advance for your help,
Eleonora
Comment