Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: merge/joinby wityh if condition


From   Taavi Lai <taavi.lai@ut.ee>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: merge/joinby wityh if condition
Date   Wed, 17 Aug 2005 18:40:31 +0300

Dear Kit,

Tried to merge and used the condition afterwards. It seemed to work, thank you.
However the section 2) below raised another question. I have several observations per id in both files, does it matter?

Best regards,
Taavi

Kit Baum wrote:


1) joinby is rarely the answer to a question. It is a quite specialised tool corresponding to the outer join in database lingo. It will not help you here; it would combine each obs on id (first ds) with each obs on id (second ds) leading to observations belonging to two people.

2) If you have single records in each database per id, it is a straightforward one-to-one merge on the id field.

3) After merging you may apply the if condition to the result with

keep if start_date1<=start_date2 & end_date1>=end_date2

to screen out those observations not wanted.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html


On Aug 13, 2005, at 2:33 AM, Taavi wrote:


Dataset 1 has variables:
id start_date1 end_date1 sum1

Dataset 2 has variables:
id start_date2 end_date2 sum2

I need to join/merge these files by variable id and a condition:
start_date1<=start_date2 & end_date1>=end_date2

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index