Hi. My data has 3 varibales: ID, date of visit, visit number. I want to create a new variable that has the previous eval date so I can calculate the number of days since the previous date. Eg for the first ID, obs 2, I want to add a fourth variable that is the date of obs1. This is where I need help.
My next step is do run datediff(evaldate, prevdate, "day") but I welcome input if there's a better way to calculate the difference. Thanks!
* Example generated by -dataex-. For more info, type help dataex
clear
input long id str10 evaldate float epnumber
5 "2020-06-07" 1
5 "2020-09-07" 2
9 "2020-03-21" 1
9 "2020-05-23" 2
9 "2020-05-24" 3
9 "2020-06-21" 4
9 "2020-06-28" 5
9 "2020-07-05" 6
9 "2020-09-16" 7
9 "2021-02-28" 8
9 "2021-03-04" 9
My next step is do run datediff(evaldate, prevdate, "day") but I welcome input if there's a better way to calculate the difference. Thanks!
* Example generated by -dataex-. For more info, type help dataex
clear
input long id str10 evaldate float epnumber
5 "2020-06-07" 1
5 "2020-09-07" 2
9 "2020-03-21" 1
9 "2020-05-23" 2
9 "2020-05-24" 3
9 "2020-06-21" 4
9 "2020-06-28" 5
9 "2020-07-05" 6
9 "2020-09-16" 7
9 "2021-02-28" 8
9 "2021-03-04" 9
Comment