Dear Stata Master,
I have a question about how to calculate a value coming from 2 variables and 2 different observations.
This is the example of my dataset:
I need to calculate # of days treatment interrupted, which come from date start of an observation minus date end the previous observation, for the same drug name.
For example, here for Levofloxacin= 10 days interruption (from 5 Jan to 15 Jan)
For Cycloserine = no interruption
For Bedaquiline = 1st interruption = 29 days (from 31 Jan to 1 Mar), 2nd interruption = 56 days (30 Apr to 5 May), and 3rd interruption = 106 days (15 May up to now).
Is there a way to do this calculation automatically?
Thank you in advance for your support.
Vini
I have a question about how to calculate a value coming from 2 variables and 2 different observations.
This is the example of my dataset:
| ID number | Drug name | Date start | Date end | # of days interupted |
| 1 | Levofloxacin | 1 Jan 2022 | 5 Jan 2022 | |
| 1 | Levofloxacin | 15 Jan 2022 | ||
| 1 | Cycloserine | 1 Jan 2022 | ||
| 1 | Bedaquiline | 1 Jan 2022 | 31 Jan 2022 | |
| 1 | Bedaquiline | 1 Mar 2022 | 30 April 2022 | |
| 1 | Bedaquiline | 5 May 2022 | 15 May 2022 |
For example, here for Levofloxacin= 10 days interruption (from 5 Jan to 15 Jan)
For Cycloserine = no interruption
For Bedaquiline = 1st interruption = 29 days (from 31 Jan to 1 Mar), 2nd interruption = 56 days (30 Apr to 5 May), and 3rd interruption = 106 days (15 May up to now).
Is there a way to do this calculation automatically?
Thank you in advance for your support.
Vini


Comment