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: Matching the closests dates of lab results across visists by patients


From   Matthew White <[email protected]>
To   [email protected]
Subject   Re: st: Matching the closests dates of lab results across visists by patients
Date   Sun, 18 Dec 2011 10:13:26 -0500

Hi Miguel,

Here's one approach. If there are multiple values of lab_dmy that are
equally close to a value of lats_contatc_dmy, the earlier lab_dmy is
assigned.

gen labdate = .
levelsof lats_contatc_dmy
foreach level in `r(levels)' {
	generate diff = abs(lab_dmy - `level')
	summarize diff, meanonly
	summarize lab_dmy if diff == r(min), meanonly
	replace labdate = r(min) if lats_contatc_dmy == `level'
	drop diff
}

Best,
Matt

On Sun, Dec 18, 2011 at 4:00 AM, Miguel Angel Luque Fernandez
<[email protected]> wrote:
>
> Hi,
> I have a hierarchical
>  dataset of visits by patients.
> I would like to match, using dates, the
> lab results with the date of the closest visit, moving the value
> of the lab result to the row of the closest visit according to the lab
> and visit dates (i.e: lab value 382 have to be moved to the row of the
> visit 25-Dec-2008, see here below a dataset example)
>
> Thanks a lot in advance,
> Miguel Angel Luque Fernández
>
>
> patient    lats_contatc_dmy    lab_dmy    CD4A
> 1015    31dec2007
> 1015    30jan2008
> 1015    29feb2008
> 1015    30mar2008
> 1015    29apr2008
> 1015    29may2008    23dec2008    382
> 1015    28jun2008
> 1015    28jul2008
> 1015    27aug2008
> 1015    26sep2008
> 1015    26oct2008
> 1015    25nov2008
> 1015    25dec2008    26oct2009    429
> 1015    24jan2009
> 1015    23feb2009    03jun2010    444
> 1015    25mar2009
> 1015    24apr2009
> 1015    24may2009
> 1015    23jun2009
> 1015    23jul2009
> 1015    22aug2009
> 1015    21sep2009
> 1015    21oct2009
>
>
> *
> *   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/



-- 
Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
www.poverty-action.org

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