I have a dataset of 105 countries and want to create an index variable but forgot the command for it.
I am using the following command which takes a lot of time:

tab countryn, g(d_in)
gen index=.
replace index==1 if
d_in1==1
replace index==2 if
d_in2==1
replace index==3 if
d_in3==1


and so on.

Does some know which is the proper command to do this in a faster way.