I have multiple blood test results for single pregnancies and wish to select the blood test result that was taken closest to the date at which a condition was diagnosed for each pregnancy (and drop the other results)
Thus I have four variables: Pregnancy ID, date of result, result, date condition diagnosed, e.g.:
Pregnancy ID Date condition diagnosed Result Date of result
1001 01/02/2009 59 30/07/2009
1001 01/02/2009 72 02/02/2009
1001 01/02/2009 94 01/07/2007
1001 01/02/2009 10 01/01/2002
So in the example of PregnancyID 1001 above, I want to keep the result that is 72 and drop the other three.
How would I do this? When writing my syntax I also want to add the caveat that I only want to do this for pregnancies in which there are multiple results. I have already created variable dup so would want to add the condition 'if dup >=1' to the end of my syntax.
Thank you.
Related Posts with How to select the observation with a date that is closest to another date in STATA
Codebook within bys:?I usually use the command -codebook- to undertand the number of unique values of a given variable. I…
Linear mixed models: random effects for both intercept and slope? lincom margins for continuous predictorsHi, I am a student, starting to deal with linear mixed models in STATA and your help would be extre…
Problems with articulating survey design for an appended dataset with differing numbers of replicate weightsHello, I am working with the 1996, 2000, 2004 and 2008 state-level waves of the Nursing Workforce S…
MeanHi all, I am running a simulation in STATA and would like to obtain a single mean out of the code b…
Logit model - sample size and clustering questionHello, I would like to check if there is a relationship between mothers' fertility and grandparenta…
Subscribe to:
Post Comments (Atom)
0 Response to How to select the observation with a date that is closest to another date in STATA
Post a Comment