Dear Statalist members,
I am facing an issue when dealing with dates.
I want to run the csdid command, which requires a first_treat date (the first date at which an individual got the intervention). In my case, individual with id =1 is treated between 2018m3 and 2019m2 while individual with id=2 is treated between 2018m6 and 2019m1.
So, what I want to obtain is:
- for id= 1, first_treat=2018m3 within the treatment period and 0 outside of the treatment period.
- for id=2, first_treat=2018m6 within the treatment period and 0 outside of the treatment period.
I have used the commands and datasets below for id=1. However, I did not obtain what I want.
Can anyone be of help here?
Best,
This the code I tried:
Below is the result:
I am facing an issue when dealing with dates.
I want to run the csdid command, which requires a first_treat date (the first date at which an individual got the intervention). In my case, individual with id =1 is treated between 2018m3 and 2019m2 while individual with id=2 is treated between 2018m6 and 2019m1.
So, what I want to obtain is:
- for id= 1, first_treat=2018m3 within the treatment period and 0 outside of the treatment period.
- for id=2, first_treat=2018m6 within the treatment period and 0 outside of the treatment period.
I have used the commands and datasets below for id=1. However, I did not obtain what I want.
Can anyone be of help here?
Best,
This the code I tried:
Code:
gen first_treat=0 replace first_treat=tm(2018m3) if inrange(date, tm(2018m3), tm(2019m2)) & id == 1 replace first_treat=tm(2018m6) if inrange(date, tm(2018m6), tm(2019m1)) & id == 2
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte id int year byte month float(treated date first_treat) 1 2017 1 1 684 0 1 2017 2 1 685 0 1 2017 3 1 686 0 1 2017 4 1 687 0 1 2017 5 1 688 0 1 2017 6 1 689 0 1 2017 7 1 690 0 1 2017 8 1 691 0 1 2017 9 1 692 0 1 2017 10 1 693 0 1 2017 11 1 694 0 1 2017 12 1 695 0 1 2018 1 1 696 0 1 2018 2 1 697 0 1 2018 3 1 698 698 1 2018 4 1 699 698 1 2018 5 1 700 698 1 2018 6 1 701 698 1 2018 7 1 702 698 1 2018 8 1 703 698 1 2018 9 1 704 698 1 2018 10 1 705 698 1 2018 11 1 706 698 1 2018 12 1 707 698 1 2019 1 1 708 698 1 2019 2 1 709 698 1 2019 3 1 710 0 1 2019 4 1 711 0 1 2019 5 1 712 0 1 2019 6 1 713 0 1 2019 7 1 714 0 1 2019 8 1 715 0 1 2019 9 1 716 0 1 2019 10 1 717 0 1 2019 11 1 718 0 1 2019 12 1 719 0 2 2017 1 1 684 0 2 2017 2 1 685 0 2 2017 3 1 686 0 2 2017 4 1 687 0 2 2017 5 1 688 0 2 2017 6 1 689 0 2 2017 7 1 690 0 2 2017 8 1 691 0 2 2017 9 1 692 0 2 2017 10 1 693 0 2 2017 11 1 694 0 2 2017 12 1 695 0 2 2018 1 1 696 0 2 2018 2 1 697 0 2 2018 3 1 698 0 2 2018 4 1 699 0 2 2018 5 1 700 0 2 2018 6 1 701 701 2 2018 7 1 702 701 2 2018 8 1 703 701 2 2018 9 1 704 701 2 2018 10 1 705 701 2 2018 11 1 706 701 2 2018 12 1 707 701 2 2019 1 1 708 701 2 2019 2 1 709 0 2 2019 3 1 710 0 2 2019 4 1 711 0 2 2019 5 1 712 0 2 2019 6 1 713 0 2 2019 7 1 714 0 2 2019 8 1 715 0 2 2019 9 1 716 0 2 2019 10 1 717 0 2 2019 11 1 718 0 2 2019 12 1 719 0 3 2017 1 0 684 0 3 2017 2 0 685 0 3 2017 3 0 686 0 3 2017 4 0 687 0 3 2017 5 0 688 0 3 2017 6 0 689 0 3 2017 7 0 690 0 3 2017 8 0 691 0 3 2017 9 0 692 0 3 2017 10 0 693 0 3 2017 11 0 694 0 3 2017 12 0 695 0 3 2018 1 0 696 0 3 2018 2 0 697 0 3 2018 3 0 698 0 3 2018 4 0 699 0 3 2018 5 0 700 0 3 2018 6 0 701 0 3 2018 7 0 702 0 3 2018 8 0 703 0 3 2018 9 0 704 0 3 2018 10 0 705 0 3 2018 11 0 706 0 3 2018 12 0 707 0 3 2019 1 0 708 0 3 2019 2 0 709 0 3 2019 3 0 710 0 3 2019 4 0 711 0 end

Comment