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]
RE: st: Droping rows in the other data set
From
Eilya Torshizian <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: Droping rows in the other data set
Date
Sun, 9 Feb 2014 22:55:49 +0000
Hi Rich,
Thanks for your prompt reply. I was thinking of using merge; however, my code didn't work well. Yours is perfect.
For the future reference, there is a typo in the code,
...
merge m:1 id using id1
...
BTW, I am curious to know if it's possible to implement the other strategy or not (i.e. by using the 'egen' command)? The main issue is to change the scalar's format.
Kind regards,
Eilya.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of [email protected]
Sent: Monday, 10 February 2014 10:01 a.m.
To: [email protected]
Subject: Re: st: Droping rows in the other data set
if I understand you correctly the following appears to be a much easier strategy
use data1
keep id
duplicates drop
sort id
save id1
us data2
sort id
merge m:1 is using id1
drop if _merge==1
save data2a
of course you need to substitute your own data set names, etc.
also, you were not clear about what you want to do with any id that is in data1 but not in data2 (these will have _merge=2)
Rich
-----Original Message-----
>From: Eilya Torshizian <[email protected]>
>Sent: Feb 9, 2014 3:38 PM
>To: "[email protected]" <[email protected]>
>Subject: st: Droping rows in the other data set
>
>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/
*
* 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/
*
* 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/