Hi everybody, I'm so sorry to bother you.
I have the following dataset:

ID ammission_date dismission_date
1 07sep2019 09sep2019
1 15 sep2019 28sep2019
2 9mar2020 10mar2020
3 6june2020 8june2020
3 8may2020 10 may2020
3 1jan2020 21jan2020
...

I need to calculate if the distance between first dismission date and second ammission date (and between the second dismission date and the third ammission date and so on) is <=7 for repeted observations.
I thought of first sorting the ammission dates, then the ID (which in my dataset is not sorted) and then to reshape wide in order to calculate the distance by row. This doesn't work properly because the new vars I get with the reshape wide are not sorted (ammission_date1 could be further thant ammission_date2). Have you any idea of how can I do? Thank you a lot!

Martina