title: Stata merging data sets based on a range of dates
body: <p>I realize that there is a Stata forum with this exact title, but I did not find its syntax all that helpful, especially since my datasets are a bit different. I have two datasets. One is the length of stay a person is in a facility, including the facility name. It looks like this:</p>
  
  <pre><code>+---+-------------+---------------+-----------------------+
  |ID#|Entrance Date|  Exit Date    | Facility Name         |
  |1  | 7/22/2009   | 2/24/2010     | Facility 1            |
  |1  | 7/10/2010   | 11/21/2010    | Facility 2            |
  |2  | 3/31/2010   | 9/23/2010     | Facility 1            |
  |3  | 11/24/2010  | 7/5/2011      | Facility 3            |
  |4  | 3/7/2007    | 4/19/2010     | Facility 2            |
  +---+-------------+---------------+-----------------------+
  </code></pre>
  
  <p>The next data set shows the dates when they were visited. All it has in it is ID and visitation date:</p>
  
  <pre><code>+---+-------------+
  |ID#|Visit Date   |
  | 1 | 08/21/2009  |
  | 1 | 09/02/2009  |
  | 1 | 09/23/2009 |
  | 3 | 04/22/2011  |
  | 3 | 05/05/2011  |
  +---+-------------+
  </code></pre>
  
  <p>I want to merge these two files together on <code>ID#</code> where <code>VisitDate</code> falls in between <code>Entrance Date</code> and <code>Exit Date</code> so that I can see 1. who had visitors, 2. what facilities they were in.  </p>