Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: merge

From   Simon Falck <>
To   "" <>
Subject   st: RE: merge
Date   Fri, 1 Jun 2012 15:05:13 +0000

Dear Fabian, 

It is difficult to give a specific reply when you do not tell us more about your datasets and key variables. However, here are some general inputs on merging files in Stata that perhaps are useful for you.

The -merge- command enables merging files with common id´s. One-to-one  -merge 1:1- implies that the identifiers (key variables) are exactly the same in both files. If this is not your case then you should consider Many-to-one -merge m:1- or One-to-many -merge 1:m-. It depends on how your datasets are structured and their content. The two latter options are used when you have a common id in both files and one file, either the master or user, differ in for example time period. If you have two datasets which includes id´s that are non-common in both directions you use the Many-to-many -merge m:m- option.

As understood the key-variables are important to inspect according to the options described above. Don’t forget to inspect the format, for example are both key variables in string format? Consider how a key-variables should be constructed and what a common attribute implies and the directions.

You get a great instruction by typing: -help merge-

Good luck,

-----Original Message-----
From: [] On Behalf Of "Fabian Schönenberger"
Sent: den 1 juni 2012 14:28
Subject: st: merge

Dear Statalist
I try to merge two datasets. In both files each observation is uniquely identified by cusip and year. I sort both files with xtset cusip year. Afterwards, I command: 

merge 1:1 cusip year using "C:\Users\User\Documents\Uni SG\Doktorat\Data\Price Data\pricedatev5.dta", keepusing(capm_marketpremium), keep(3)

I am only interested in those observations of cusip-year-combinations which are in my masterfile - therefore keep(3). 

However, either the matched observations nor the unmatched observations are correct, meaning that I get for each cusip-year observations the wrong capm_marketpremium and I do not get observations in my masterfile for cusip-year observations although the using file has an observation. 

I also tried merge m:m but it did not work. What am I doing the wrong way?

Many thanks for suggestions.

NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren:
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index