Dear All,

I would like to count the number of return clients in 2020 (the first occurrence/visit either was in 2018 or 2019 for example and as shown in the below data).
I have generated a first occurrence variable (and restrict it to be in 2018 or 2019 and not 2020) "first_visit_not2020". and another variable "tag" to just count the number of clients in each year. I have tried to link these two variables together in "bys" command

Code:
 egen tag2020 = tag(id yr) if  tag1==1 & first_visit_not2020 ==1
here is example of the data

Code:
 
id yr tag tag2020 return_visit first_visit_not2020
1 2018 1 0 1 1
1 2018 0 0 2 0
1 2018 0 0 3 0
1 2019 1 0 4 0
1 2019 0 0 5 0
1 2019 0 0 6 0
1 2019 0 0 7 0
1 2019 0 0 8 0
1 2019 0 0 9 0
1 2019 0 0 10 0
1 0 0 11 0
2 2019 1 0 1 1
2 2019 0 0 2 0
2 2019 0 0 3 0
2 2019 0 0 4 0
2 2020 1 1 5 0
2 2020 0 0 6 0
2 2020 0 0 7 0
3 2020 1 1 1 0
3 2020 0 0 2 0
3 2020 0 0 3 0
3 2020 0 0 4 0
3 2020 0 0 5 0
3 2020 0 0 6 0
3 2020 0 0 7 0
3 2020 0 0 8 0
3 0 0 9 0
Also, would like to be able to count the number of visits by "id" in 2020 (the return year)
Thanks for your help in advance!