Hi Listservers,
I have a dataset in long format which has dates when an individual visited a
doctor. I have another dataset with dates when that patient started taking a
medication. Naturally, the dates will not align exactly between the two data
sets. 
Is there a way of merging the files so that the date when the patient
started taking the medication is aligned (put on the same line) to the
closest date (but after) of a given doctor visit?
Example
File 1 - office visits
ID	date of visit
1	1/1/2009
1	1/31/2009
1	2/18/2009
1	3/14/2009
1	5/30/2009
1	7/12/2009
2	3/10/2009
2	4/25/2009
2	5/20/2009
3	2/09/2009
3	6/08/2009
3	7/10/2009
File 2 - medication fill date
ID 	date of first fill
1	2/22/2009
2	4/15/2009
3	7/15/2009
If I would like the medication date to be added to the office visit file to
be matched to the last closest office visit, then ID 1 medication date
should align with 1/31/2009, ID 2 should align with 3/10/2009 and ID 3
should align with 7/10/2009. 
Thanks in advance
Ariel 
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/