Hello all,
The dataset am working on has errors in only year entries for stop date. I was wondering how I could go about creating a variable that has the date with the correct year.
So the stop_date is meant to have the same year as the start_date.
I created the variable yr using code below:
"gen yr = year(start_date)"
See below is the sample of the data
+--------------------------------+
| stop_date start_date yr |
|--------------------------------|
1 | 12/31/2022 10/8/2021 2021 |
2 | 12/9/2022 9/15/2021 2021 |
3 | 5/17/2023 3/18/2022 2022 |
4 | 12/28/2022 10/5/2021 2021 |
For example the correct stop_date for 1) would have to be 12/31/2021 instead of 12/31/2022.
Any assistance will be highly appreciated as I have looked through a number of previously posted date-related questions and none seemed to help.
The dataset am working on has errors in only year entries for stop date. I was wondering how I could go about creating a variable that has the date with the correct year.
So the stop_date is meant to have the same year as the start_date.
I created the variable yr using code below:
"gen yr = year(start_date)"
See below is the sample of the data
+--------------------------------+
| stop_date start_date yr |
|--------------------------------|
1 | 12/31/2022 10/8/2021 2021 |
2 | 12/9/2022 9/15/2021 2021 |
3 | 5/17/2023 3/18/2022 2022 |
4 | 12/28/2022 10/5/2021 2021 |
For example the correct stop_date for 1) would have to be 12/31/2021 instead of 12/31/2022.
Any assistance will be highly appreciated as I have looked through a number of previously posted date-related questions and none seemed to help.
Comment