Dear all Statalist experts,
I have a dataset as below
Now I want to delete all observations of a TYPE2 if this TYPE2 has (indicator==1 and year1 !=2019). In short, indicator is the first observation for each TYPE2 where post33treat1=1 and year1 is the real year. In specific, for the sample above, the last two observations will be deleted (because indicator==1 when year1=2020). Please let me know if my dataset is insufficient or my description is unclear.
Thanks in advance.
I have a dataset as below
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float year1 long TYPE2 float(treat1 FAT_w1 post33 post33treat1 indicator) 2016 2 0 . 0 0 . 2016 3 . . 0 . . 2017 3 . 105.86112 0 . . 2018 3 . 169.16325 0 . . 2021 3 . . 1 . . 2019 4 1 . 1 1 1 2020 4 1 6.876883 1 1 . 2017 6 1 . 0 0 . 2018 6 1 2.2230647 0 0 . 2019 6 1 2.0798314 1 1 1 2020 6 1 1.665593 1 1 . 2021 6 1 1.4405484 1 1 . 2016 7 1 . 0 0 . 2017 7 1 9.328573 0 0 . 2018 7 1 14.143867 0 0 . 2019 7 1 16.777643 1 1 1 2020 7 1 19.836254 1 1 . 2021 7 1 13.363945 1 1 . 2016 10 0 . 0 0 . 2019 10 0 . 1 0 . 2020 10 0 10.358336 1 0 . 2016 11 0 . 0 0 . 2017 11 0 .6820889 0 0 . 2018 11 0 .8348646 0 0 . 2019 11 0 1.1720647 1 0 . 2020 11 0 1.3943592 1 0 . 2021 11 0 1.464206 1 0 . 2017 13 0 . 0 0 . 2018 13 0 14.170573 0 0 . 2019 13 0 17.122456 1 0 . 2020 13 0 10.125214 1 0 . 2016 15 . . 0 . . 2019 15 . . 1 . . 2020 15 . 5.240753 1 . . 2021 15 . 3.297071 1 . . 2016 16 . . 0 . . 2017 16 . 1.4334356 0 . . 2018 16 . 1.8452812 0 . . 2019 16 . 2.1694336 1 . . 2020 16 . 2.2726302 1 . . 2021 16 . 2.469463 1 . . 2020 18 1 . 1 1 1 2021 18 1 20.48241 1 1 . end label values TYPE2 TYPE2 label def TYPE2 2 "2557XG", modify label def TYPE2 3 "2563UY", modify label def TYPE2 4 "2563UZ", modify label def TYPE2 6 "2580PG", modify label def TYPE2 7 "25846A", modify label def TYPE2 10 "2621N5", modify label def TYPE2 11 "2622UU", modify label def TYPE2 13 "2625KH", modify label def TYPE2 15 "2631U4", modify label def TYPE2 16 "2633HC", modify label def TYPE2 18 "2634G2", modify
Thanks in advance.

Comment