Bookmark and Share

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: update from long dataset using criteria (Out of office)


From   "Sarah Tougher" <[email protected]>
To   "[email protected]" <[email protected]>, "Colin Campbell" <[email protected]>
Subject   Re: st: update from long dataset using criteria (Out of office)
Date   Thu, 20 Oct 2011 13:34:46 +0100

I am out of the office until November 7th. I have intermittent access to email, but will try to return your message as soon as possible. 

>>> Colin Campbell <[email protected]> 10/20/11 13:33 >>>


Dear statalist,

I have a master dataset (1) which is a flat file with one record for each unique id. this contains missing data to be updated
from a second dataset (2) which is in long format with several observations per id.
I wish to update 1 with the result from 2 where the date difference between keydate(1) and test_date(2) is minimised.
i.e. for each unique id, update dataset 1 with result and test_date from dataset 2 when criteria X is satisfied

I have managed in dataset 2  to placer test_date in ascending order within each id, reshape wide and keep  only the first result 
and then merge, update  into the master to import the first result but cannot work out how to apply criteria to this.

Any help appreciated

Colin

dataset 1 

IdPacient  result    test_date            keydate
1                .                .                20/12/2010
2                .                .                01/01/1999

dataset 2
IdPacient    result    test_date            _n
1                1012      14/07/2010        2
1                1008      10/12/2010        3
1                 779       21/08/2009        1
2                 231       15/09/1999        3
2                195        01/06/1999        2
2                197        15/02/1999        1

*
*   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/


*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index