I have a dataset of sales transactions where there are potentially multiple buyers and multiple sellers for a given sale transaction as illustrated below:
I need to remove all observations within a sale_id group if any buyer is the same as any seller in the sale_id group and retain all other observations. For example, both observations for sale_id 37990841 should be included in my final dataset because the buyer_id is not the same as either of the seller_ids. However, both observations for sale_id 38070842 should be excluded because buyer_id 56098 also appears as a seller_id for the same sale_id. Here is what my final dataset should look like:
A simple drop command is obviously insufficient here, but I am unsure how to proceed.
Thank you in advance for your help
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long sale_id double(seller_id buyer_id) 37990841 11020 88369 37990841 39642 88369 38070842 75912 56098 38070842 56098 56098 38080470 74588 74588 38080470 86591 74588 38090443 74895 74617 38090443 74617 74617 38140391 10216 . 38140391 10216 . 38410027 11703 11703 38410027 11703 20458 38490322 75034 75034 38490322 75034 75034 38550746 64231 64231 38550746 64231 64231 38650703 . 64231 38650703 . 76655 38650964 88786 48207 38650964 48207 48207 38650964 86021 48207 38650964 59555 48207 end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long sale_id double(seller_id buyer_id) 37990841 11020 88369 37990841 39642 88369 38140391 10216 . 38140391 10216 . 38650703 . 64231 38650703 . 76655 end
Code:
drop if seller_id==buyer_id

Comment