Good Afternoon,
I have a dataset which is formatted as follows :
...and so on (note that these aren't the same dates as in my set, this is an example).
The interviewdate and bloodtestdate are both in 'long' storage type, with '%d' display format.
The 'interviewdate' for each participant is the same, as these are their baseline interview dates.
I am interested in selecting the bloodtestdate which is the closest date to the interview date plus or minus one year.
I thought about dropping all of the bloodtestdate variables that don't fall within a year of the interview date, tagging the first observation with the egen command and going from here but then if a participant has had multiple dates in one year, it won't select the closest date to the interview date.
I have many, many blood test variables that I need to do this for as my analysis goes on. Any help would be greatly appreciated.
Thank you,
Kerry
I have a dataset which is formatted as follows :
id | interviewdate | bloodtestdate | bloodtestvalue |
1 | 01feb2009 | 01mar2009 | 106 |
1 | 01feb2009 | 06apr2009 | 107 |
2 | 24aug2012 | 17jan2009 | 500 |
2 | 24aug2012 | 08feb2010 | 502 |
2 | 24aug2012 | 06apr2011 | 509 |
2 | 24aug2012 | 02mar2012 | 400 |
3 | 06jan2007 | 06may2006 | 350 |
...and so on (note that these aren't the same dates as in my set, this is an example).
The interviewdate and bloodtestdate are both in 'long' storage type, with '%d' display format.
The 'interviewdate' for each participant is the same, as these are their baseline interview dates.
I am interested in selecting the bloodtestdate which is the closest date to the interview date plus or minus one year.
I thought about dropping all of the bloodtestdate variables that don't fall within a year of the interview date, tagging the first observation with the egen command and going from here but then if a participant has had multiple dates in one year, it won't select the closest date to the interview date.
I have many, many blood test variables that I need to do this for as my analysis goes on. Any help would be greatly appreciated.
Thank you,
Kerry
Comment