Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: combining data sets with different dimensions

From   Kremena Platikanova <[email protected]>
To   [email protected]
Subject   Re: st: combining data sets with different dimensions
Date   Fri, 14 Apr 2006 16:08:38 -0600

When I try that, at the step:
merge importer year using dataset2.dta

I receive the message: variables importer year do not uniquely identify
observations in the master data

What do I need to do differently?


--- Maarten buis <[email protected]> wrote:
This can be done using the -merge- command. The trick is to use the right
combination of variables
as identifiers. See the (untested) code below.

*--------------begin example-------------
use dataset2.dta
sort importer year
save dataset2.dta, replace
use dataset1.dta, clear
sort importer year
merge importer year using dataset2.dta
tab _merge /*check if merge was successful for all countries*/
           /*Luxemb(o)urg and C�te D'Ivoire/Ivory Coast are notorious
drop _merge
sort exporter year
save dataset1.dta, replace
use dataset3.dta, clear
sort exporter year
save dataset3.dta, replace
use dataset1.dta, clear
merge exporter year using dataset3.dta
tabe _merge
drop _merge
sort importer exporter
save dataset1.dta, replace
use dataset4.dta, clear
sort importer exporter
save dataset4.dta, replace
use dataset1.dta, clear
merge importer exporter using dataset4.dta
tab _merge
drop _merge
*---------------end example---------------


--- Kremena Platikanova <[email protected]> wrote:
> I want to combine the following four data sets:
> Data set 1:
> importer   exporter   year   commodity_code   commodity_value
> (for example,
> USA        Canada     2003      0001             .....
> USA        Canada     2003      0002             .....
> USA        Canada     2003      0003             .....
> USA        Canada     2004      0001             .....
> USA        Canada     2004      0004             .....)
> Data set 2:
> importer   year   gdp_importer
> Data set 3:
> exporter   year   gdp_exporter
> Data set 4:
> importer   exporter   geograph_distance
> Basically, I want to add the variables:
> gdp_importer, gdp_exporter and geograph_distance (between importer and
> exporter) to data set 1.
> How can I do that given the difference in the dimesions of the data sets?

Kremena Platikanova
Ph.D. Candidate
Department of Economics
University of Colorado, Boulder
*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index