Auto fill string ID variable

Hey guys.

So I've been working on a project where I need to code a load of surveys. Each survey has (in groups of maybe 100) a specific group identifier and then a personal ID. Something like this:

ect. for group one and then again for the next group:


What I would love to do (and this variable is string-coded, by the way) is a way to be able to do something like this

replace ID = N15-xx

where Stata understands, that it needs to start at 01 and end at maybe 87 but keeps the N15- first. Then I just need to do it to each group and not manually input the ID to each survey.
assuming your group variabe (string: N15, N16....) is named "gr"

you can generate the xx number for each group
by gr: gen nb=_n

then tostring

tostring nb, replace

and generate your string ID

gen ID= gr + "-" + nb