Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Merge by range of values
From
"Jeremy A. Grey" <[email protected]>
To
[email protected]
Subject
st: Merge by range of values
Date
Mon, 13 Jun 2011 16:49:42 -0500
Hi everyone,
I am trying to find a way to merge data sets according to a range of
values, sort of a combination of m:1 merge and inrange().
In one data set, each observation represents a subject with the
individual's value for variable X.
In another data set, each observation represents a range of values for
variable X. The start and end values of the range are separate
variables, such as start_X and end_X. The remaining variables contain
the values of Y and Z for all values of X within that range.
Is there a way to merge the Y and Z data from the second data set into
the first by comparing the value of X to the range specified by
start_X and end_X?
I thought of transforming the second data set in order to create new
variables, such as start_X_1, end_X_1, Y_1, Z_1, start_X_2, end_X_2,
Y_2, Z_2, etc., adding those data to each observation in the first
dataset, and using a loop and inrange() in order to compute Y and Z
for each subject, but there are about 3,000,000 different ranges of X
in the second data set, so this is impractical.
Thank you in advance for your help.
Jeremy
--
Jeremy A. Grey, MA
Doctoral Student
Division of Epidemiology and Community Health
University of Minnesota School of Public Health
*
* 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/