Hello,
I need some help finding a solution to the following problem:
I want to drop all the observations that occur at and after the first time a treatment turns off (goes from 1 to 0), no matter if it turns on again.

The following table is an example of my data:
id year treatment
1 2012 0
1 2013 1
1 2014 1
1 2015 1
1 2016 1
1 2017 0
1 2018 0
1 2019 1
1 2020 1
1 2021 0
2 2012 0
2 2013 0
2 2014 1
2 2015 1
2 2016 0
2 2017 0
2 2018 0
2 2019 1
2 2020 1
2 2021 1
3 2012 0
3 2013 0
3 2014 0
3 2015 0
3 2016 0
3 2017 1
3 2018 1
3 2019 1
3 2020 0
3 2021 0
I want to drop the following observations: for id 1, drop observations for years 2017 through 2021 as they come at or after the first time treatment turns off (in 2017). Similarly, for id 2, drop observations for years 2016 through 2021, and for id 3, drop observations for years 2020 and 2021.

I am unable to figure this out since the treatment can turn on again for each id and the criterion I set could apply to those observations as well, but I do not want those observations as the treatment has turned off once already.
Any help would be greatly appreciated!