No announcement yet.
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating timeframes between variables in long format

    Dear Forum-Users,
    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 .
    What I want to do is „check“ whether the patient has been to the doctor who issued the prescription within a certain time-window (lets say five days before or after the prescription date). If this is true, newvar should count the visits within that time-window.
    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