I have a data set in long format – combining prescription data and dates of doc visits which looks like this – except for the „newvar“ – which I would like to obtain.
patID | docID | prescDATE | visitDATE | newvar |
1XY | A | 10jan2018 | . | 2 |
1XY | B | 10mar2018 | . | 0 |
1XY | A | . | 09jan2018 | . |
1XY | A | . | 10jan2018 | . |
1XY | B | . | 15jun2018 | . |
1XY | C | . | 13mar2018 | . |
2GH | A | 20jan2018 | . | 1 |
2GH | C | 25mar2018 | . | 0 |
2GH | A | . | 18jan2018 | . |
2GH | C | . | 15mar2018 | 0 |
3WE | A | 02jan2018 | . | 1 |
3WE | C | 05mar2018 | . | 1 |
3WE | A | 03jan2018 | . | |
3WE | C | 07mar2018 | . |
I guess one solution would be to convert the dataset in the wide format and loop through the prescription dates?
Has anyone a clue how this could be handled in the long format?
May Thanx, Lynde
0 Response to Calculating timeframes between variables in long format
Post a Comment