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   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: combining data sets with different dimensions
Date   Fri, 14 Apr 2006 22:07:23 +0100 (BST)

Kremena:
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 troublemakers*/
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---------------

HTH,
Maarten

--- 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?

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. http://uk.mail.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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