Hello dear stata friends, we are pretty new on stata and would like some help.

We managed to merge two data sets, (where the first data set consisted of Import Exporter Year Imports and the second one of Distance between the countries). Like this:

Importer Exporter Year Imports Distance
Austria Albania 2005 4843 812
Sweden Norway 2005 1084 417
Austria Albania 2006 4900 812
Sweden Norway 2006 1100 417

This continues for 28 importing countries and 170 exporting countries from 2004-2016 with 59623 observations. Our code looked like this and it worked fine:

use distancemaster.dta
sort Importer Exporter
save, replace
use masterfile.dta
sort Importer Exporter
save, replace
merge Importer Exporter using distancemaster.dta
drop _merge
save testingdistance, replace

Now we want to add GDP for Importer and Exporter, (we have two GDP data sets, one with Exporter from year 2004-2016 and one with Importer from year 2004-2016) we used this commando:

use BNProw.dta
sort Exporter Year
save, replace
use masterfile.dta
sort Exporter Year
save, replace
merge Exporter Year using BNProw.dta
save testinggdprow, replace

When we tried this commando, an error message errupted:

key variable Year is int in master but str4 in using data
Each key variable -- the variables on which observations are matched --
must be of the same generic type in the master and using datasets. Same
generic type means both numeric or both string.


What are we doing wrong and how can we solve it?

Best regards,

Gabriel and Hanna.