Dear all,

I am trying to merge two datasets that contain sectoral information on value added, number of employees, output etc (for the master dataset) and sectoral information on value added (but dividing this into value added created by foreign and domestic firms). The master dataset is as follows:

//
Code:
clear
input long(country year Establishments Employment) double(Wages Output ValueAdded GrossFixedCapital) long(FemaleEmployees IndexIndustrialProduction) str3 isiccomb
4 1973   .  4321       .        . . .    .   . "15"
4 1974   .  4845       .        . . .    .   . "15"
4 1975   .  5103       .        . . .    .   . "15"
4 1976   .  4540       .        . . .    .   . "15"
4 1977   .  6309       .        . . .    .   . "15"
4 1978   .  6413       .        . . .    .   . "15"
4 1979   .  6006       .        . . .    .   . "15"
4 1980   .  5672       .        . . .    .   . "15"
4 1981  62  8481       .        . . .    .   . "15"
4 1982  69  6866       .        . . .    .   . "15"
4 1983  22  5080       .        . . .  376   . "15"
4 1984  22  5187       .        . . .  419   . "15"
4 1985  26  5446       .        . . .  742   . "15"
4 1986  30  5556       .        . . .  736   . "15"
4 1987  48  6177       .        . . .  865   . "15"
4 1988  48  5950       .        . . . 1299   . "15"
4 1990   .     .       .        . . .  565   . "15"
4 1991   .     .       .        . . .  590   . "15"
4 1998   .     .       .        . . .    .   . "15"
4 1999   .     .       .        . . .    .   . "15"
4 2001   .   115       .        . . .    .   . "15"
4 2001   .     .       .        . . .    .   . "15"
4 2002  57  1398 1416229  8803794 . .  270  67 "15"
4 2003  68  1986 1857237  2994088 . .  384  70 "15"
4 2004  60  2170 2177016  7482447 . .  720  72 "15"
4 2005 152  4376 4461093 24406704 . .  561  74 "15"
4 2006 199  5278 5400385 28422446 . .  901  76 "15"
4 2007 206  5300 6110242 36107429 . . 1237  80 "15"
4 2008 212  5431 6415492 35642064 . .  899  82 "15"
4 2009 199  5400 6824441 45082961 . .  870  86 "15"
4 2010 195  4893 6952011 40262668 . .  912  89 "15"
4 2011 197  4901 7171111 47769902 . . 1008  92 "15"
4 2012 192  4790 6604296 48133005 . .    .  97 "15"
4 2013 189  4368 5679202 39418536 . .    .  98 "15"
4 2014   .     .       . 39940819 . .    .   . "15"
4 2014   .     .       .        . . .    .  99 "15"
4 2015   .     .       .        . . .    . 100 "15"
4 2015   .     .       . 37204964 . .    .   . "15"
4 2016   .     .       .        . . .    . 101 "15"
4 2017   .     .       .        . . .    . 103 "15"
4 2018   .     .       . 45838668 . .    . 105 "15"
4 1973   .     0       .        . . .    .   . "16"
4 1974   .     0       .        . . .    .   . "16"
4 1975   .     0       .        . . .    .   . "16"
4 1976   .     0       .        . . .    .   . "16"
4 1977   .     0       .        . . .    .   . "16"
4 1978   .     0       .        . . .    .   . "16"
4 1979   .     0       .        . . .    .   . "16"
4 1980   .     0       .        . . .    .   . "16"
4 1981   0     0       .        . . .    .   . "16"
4 1982   0     0       .        . . .    .   . "16"
4 1983   0     0       .        . . .    0   . "16"
4 1984   0     0       .        . . .    0   . "16"
4 1985   0     0       .        . . .    0   . "16"
4 1986   0     0       .        . . .    0   . "16"
4 1987   0     0       .        . . .    0   . "16"
4 1988   0     0       .        . . .    0   . "16"
4 1990   .     .       .        . . .    0   . "16"
4 1991   .     .       .        . . .    0   . "16"
4 1998   .     .       .        . . .    .   . "16"
4 1999   .     .       .        . . .    .   . "16"
4 2001   .     .       .        . . .    .   . "16"
4 2002   .     .       .        . . .    .  67 "16"
4 2002   .     .       .        . . .    .   . "16"
4 2003   .     .       .        . . .    .   . "16"
4 2003   .     .       .        . . .    .  70 "16"
4 2004   .     .       .        . . .    .   . "16"
4 2004   .     .       .        . . .    .  72 "16"
4 2005   .     .       .        . . .    .  74 "16"
4 2005   .     .       .        . . .    .   . "16"
4 2006   .     .       .        . . .    .  76 "16"
4 2006   .     .       .        . . .    .   . "16"
4 2007   .     .       .        . . .    .   . "16"
4 2007   .     .       .        . . .    .  80 "16"
4 2008   .     .       .        . . .    .   . "16"
4 2008   .     .       .        . . .    .  82 "16"
4 2009   .     .       .        . . .    .  86 "16"
4 2009   .     .       .        . . .    .   . "16"
4 2010   .     .       .        . . .    .   . "16"
4 2010   .     .       .        . . .    .  89 "16"
4 2011   .     .       .        . . .    .   . "16"
4 2011   .     .       .        . . .    .  92 "16"
4 2012   .     .       .        . . .    .   . "16"
4 2012   .     .       .        . . .    .  97 "16"
4 2013   .     .       .        . . .    .   . "16"
4 2013   .     .       .        . . .    .  98 "16"
4 2014   .     .       .        . . .    .  99 "16"
4 2014   .     .       .        . . .    .   . "16"
4 2015   .     .       .        . . .    .   . "16"
4 2015   .     .       .        . . .    . 100 "16"
4 2016   .     .       .        . . .    . 101 "16"
4 2017   .     .       .        . . .    . 103 "16"
4 2018   .     .       .    90174 . .    . 105 "16"
4 1973   . 12555       .        . . .    .   . "17"
4 1974   . 14243       .        . . .    .   . "17"
4 1975   . 17202       .        . . .    .   . "17"
4 1976   . 20520       .        . . .    .   . "17"
4 1977   . 20540       .        . . .    .   . "17"
4 1978   . 22889       .        . . .    .   . "17"
4 1979   . 23733       .        . . .    .   . "17"
end
The using dataset is as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(isiccomb1 country year ownership1) double(country_dva country_ddc)
1 1  1 1         13242.5625     6646.251953125
1 1  1 2 20.943418502807617 13.302783012390137
1 1  2 1   15955.3642578125   7915.73583984375
1 1  2 2 51.944400787353516 25.787616729736328
1 1  3 1     19004.01953125      9028.44921875
1 1  3 2  51.31034469604492 24.374692916870117
1 1  4 2  54.88113021850586 24.464805603027344
1 1  4 1     23671.03515625   10549.0517578125
1 1  5 2  51.64005661010742 25.542184829711914
1 1  5 1      24928.5234375    12329.009765625
1 1  6 1     30105.23046875         14069.5625
1 1  6 2  52.90160369873047  24.73287582397461
1 1  7 2  64.03341674804688  28.88630485534668
1 1  7 1     37406.26953125     16877.76171875
1 1  8 1        42303.84375    20279.998046875
1 1  8 2  74.15796661376953  35.55222702026367
1 1  9 1     45488.15234375     21542.51953125
1 1  9 2  71.59939575195313  33.90448760986328
1 1 10 1      43533.1484375    20992.189453125
1 1 10 2  70.16531372070313  33.85472869873047
1 1 11 2  74.20100402832031 37.470272064208984
1 1 11 1     49537.87109375      25011.3359375
1 1 12 1     52762.53515625     26713.92578125
1 1 12 2 63.561065673828125  32.18401336669922
2 1  1 2 496.76495361328125 411.78302001953125
2 1  1 1  838.3035888671875  713.1104736328125
2 1  2 2    642.75830078125 503.72515869140625
2 1  2 1  925.0895385742188    760.70849609375
2 1  3 1 1160.9381103515625    951.25732421875
2 1  3 2  748.4610595703125  578.4494018554688
2 1  4 1   1592.00341796875     1268.392578125
2 1  4 2   882.517333984375  661.4505615234375
2 1  5 1  1513.726318359375    1265.0986328125
2 1  5 2   764.704833984375  638.0638427734375
2 1  6 1 1907.9449462890625 1532.0240478515625
2 1  6 2  954.3882446289063  749.4030151367188
2 1  7 2  1171.512451171875  925.6260375976563
2 1  7 1  2318.891845703125 1878.3494873046875
2 1  8 2   1347.67431640625 1145.2596435546875
2 1  8 1   2520.29736328125  2126.483154296875
2 1  9 2 1451.4041748046875 1251.6307373046875
2 1  9 1   2682.51025390625  2269.576416015625
2 1 10 2  1503.839111328125  1301.392333984375
2 1 10 1  2352.398681640625 1983.8206787109375
2 1 11 2  1574.308837890625 1454.5621337890625
2 1 11 1  2909.181396484375  2575.659423828125
2 1 12 1      2337.59765625   2039.42626953125
2 1 12 2   1336.93603515625 1195.2872314453125
3 1  1 1   6835.68017578125   13552.2333984375
3 1  1 2  603.0000610351563   983.228271484375
3 1  2 1   8003.94970703125   15798.1689453125
3 1  2 2  692.8740844726563 1133.6236572265625
3 1  3 1    9908.7001953125    18970.091796875
3 1  3 2  816.8071899414063    1278.1572265625
3 1  4 1   12285.5830078125       22668.890625
3 1  4 2 1117.3118896484375 1669.0379638671875
3 1  5 2 1022.2061767578125   1607.34423828125
3 1  5 1   11198.2177734375      21132.7109375
3 1  6 1    14896.400390625       28113.203125
3 1  6 2 1296.7537841796875 2040.7301025390625
3 1  7 1    18814.083984375     35159.16015625
3 1  7 2 1537.4046630859375     2390.107421875
3 1  8 1    21189.162109375      39604.6953125
3 1  8 2  1655.791259765625  2595.523193359375
3 1  9 2      1714.55859375  2593.202880859375
3 1  9 1    22289.751953125      40261.9453125
3 1 10 1    20451.501953125      37257.1328125
3 1 10 2 1528.5552978515625     2337.462890625
3 1 11 1      24319.1484375      44264.5859375
3 1 11 2   1620.32177734375  2486.326904296875
3 1 12 2     1382.076171875  2190.369873046875
3 1 12 1     19576.92578125       36790.890625
4 1  1 2  66.43079376220703  72.22550201416016
4 1  1 1   4591.77294921875       4294.1796875
4 1  2 2  90.55816650390625 103.06085968017578
4 1  2 1    5343.3134765625   4987.33935546875
4 1  3 1   6593.54541015625   5972.48583984375
4 1  3 2 111.22639465332031     122.7099609375
4 1  4 2 134.23480224609375  144.5155487060547
4 1  4 1    8379.9072265625   7367.14794921875
4 1  5 1     7965.482421875   6989.98974609375
4 1  5 2  118.0421142578125 130.09866333007813
4 1  6 2  140.1436767578125  153.8397674560547
4 1  6 1    9997.9130859375    8817.5361328125
4 1  7 1   12448.6123046875    11085.271484375
4 1  7 2   171.370361328125 189.02430725097656
4 1  8 1   13955.7255859375    12617.505859375
4 1  8 2     176.7802734375 201.37208557128906
4 1  9 1   14609.4384765625   12993.1357421875
4 1  9 2 182.01828002929688 204.28733825683594
4 1 10 1   13623.9228515625      11993.8203125
4 1 10 2  182.0375213623047 203.14405822753906
4 1 11 2 187.90664672851563  209.9382781982422
4 1 11 1    15625.498046875   13617.9814453125
4 1 12 2    161.18701171875 179.30474853515625
4 1 12 1     11555.63671875    10203.572265625
5 1  1 1  649.0389404296875 504.53228759765625
5 1  1 2    459.28173828125  381.8314514160156
5 1  2 2  533.0606689453125 430.08831787109375
5 1  2 1  681.7369995117188   527.529541015625
end
label values isiccomb1 isiccomb1
label def isiccomb1 1 "1", modify
label def isiccomb1 2 "15", modify
label def isiccomb1 3 "15A", modify
label def isiccomb1 4 "17D", modify
label def isiccomb1 5 "18", modify
label values country country1
label def country1 1 "032", modify
label values year year1
label def year1 1 "2005", modify
label def year1 2 "2006", modify
label def year1 3 "2007", modify
label def year1 4 "2008", modify
label def year1 5 "2009", modify
label def year1 6 "2010", modify
label def year1 7 "2011", modify
label def year1 8 "2012", modify
label def year1 9 "2013", modify
label def year1 10 "2014", modify
label def year1 11 "2015", modify
label def year1 12 "2016", modify
label values ownership1 ownership1
label def ownership1 1 "Domestic", modify
label def ownership1 2 "Foreign", modify
The error pops up as saying that there are duplicates in both datasets. My hypothesis is that duplicates come from the "using" dataset. Given that you have the same year, same sector, and country but you can distinguish the variables by value added generated by foreign firms or domestic firms. Any recommendation on how to proceed?

Thank you very much,

Hugo