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: Droping rows in the other data set
From
Eilya Torshizian <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Droping rows in the other data set
Date
Sun, 9 Feb 2014 20:38:15 +0000
Dear Statalisters,
I have two datasets. I would like to delete the rows in the Second data set that are not included in the First data set. The "ID" variable is included in both datasets with repeating values. However, some rows of the "ID" are dropped in the First data set. Let's assume that the "ID" variable in the First dataset is as follows,
First:
ID
11
11
13
15
While the "ID" variable does not include 12 and 14 values in the First data set, in the Second dataset 12 and 14 are included:
Second:
ID
11
12
12
13
14
14
15
I need to delete the incompatible rows from the Second data set.
I was thinking of using the 'egen - anymatch' command. To do so, I need the list of values from the First data set, which is derived from the following command,
- use "First.dta", clear
- levelsof ID
- global LIST `r(levels)'
- clear
Then I use the LIST scalar in the second data set:
- use "Second.dta"
- egen KEEP = anymatch(ID), values(LIST)
- drop if KEEP == 0
However, as the LIST is scalar, I am not able to do so. I appreciate your comments.
Kind regards,
Eilya.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/