I am working on World Value Survey dataset. It consists of 5 waves and multiple countries in each wave. Countries do not remain the same in each wave, i.e. some countries from previous wave are dropped and new some countries are added in next wave and so on ...

I want to create a variable that give me total number of observations for each country in each wave ..... e.g if in wave 1 country a has 5, country b has 3 and country c has 2 observations and then in wave 2 country a has 7 country c has 4 and country d has 10 observations then I want a variable (lets see count) that show up like 5, 3, 2, up to wave 1 and the continue like 7, 4, 10 etc. (data has both country codes as well as wave codes)

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte S002 int S003 float rank_gov
3 643 2
3 642 2
3 604 2
3  70 2
5 688 2
5 894 2
5 756 3
5 894 2
5 360 2
6 398 2
6 288 2
6 268 2
6 752 3
6 458 3
6 643 2
7 704 2
7 231 2
7 104 1
7 276 3
7  68 1
end
label values S002 S002
label def S002 3 "1994-1998", modify
label def S002 5 "2005-2009", modify
label def S002 6 "2010-2014", modify
label def S002 7 "2017-2020", modify
label values S003 S003
label def S003 68 "Bolivia", modify
label def S003 70 "Bosnia Herzegovina", modify
label def S003 104 "Myanmar", modify
label def S003 231 "Ethiopia", modify
label def S003 268 "Georgia", modify
label def S003 276 "Germany", modify
label def S003 288 "Ghana", modify
label def S003 360 "Indonesia", modify
label def S003 398 "Kazakhstan", modify
label def S003 458 "Malaysia", modify
label def S003 604 "Peru", modify
label def S003 642 "Romania", modify
label def S003 643 "Russia", modify
label def S003 688 "Serbia", modify
label def S003 704 "Vietnam", modify
label def S003 752 "Sweden", modify
label def S003 756 "Switzerland", modify
label def S003 894 "Zambia", modify
------------------ copy up to and including the previous line ------------------