Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: how can I merge two data sets over a range of values


From   David Radwin <dradwin@mprinc.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: how can I merge two data sets over a range of values
Date   Wed, 08 Feb 2012 20:06:50 -0800 (PST)

Richard,

I think you want to round the values in both datasets to the nearest dollar. Something like this:


use dataset2, clear
gen price_rounded=round(price)
save dataset2b
use dataset1, clear
gen price_rounded=round(price)
merge 1:1 price_rounded using dataset2b



Technically the value of 20 in dataset1 will merge only to values 19.5 through 20.49 in dataset2, but I suspect this is what you want.

If you want to customize the ranges more, such as matching 20 in dataset1 to the range 17.5 through 22.49 in dataset2, you can use -recode- or -egen- to create your new variables in both datasets.

David

----- Original Message -----
From: "Richard Warr" <rswarr@gmail.com>
To: statalist@hsphsun2.harvard.edu
Sent: Wednesday, February 8, 2012 1:45:31 PM
Subject: st: how can I merge two data sets over a range of values

Hi, I want to merge two data sets.  The merge variable is the stock
price.  However I would like to merge over a range of prices.  For
example if the price is 20 in dataset1, I would like that to merge
with any price in the range of 19.5 to 20.5 in dataset2.   Currently
my data sets each contain only a single stock price series (and other
variables).

Any ideas?

Thanks
Richard


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index