Hello all,

I'm trying to create a loop such that for each set of 4 through 6 a unique id (starting at 1, ending at N) is assigned for all those values inside the set, regardless of the name of that row. Example data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str3 name byte(tau id)
"AAA" 4 1
"AAA" 5 1
"AAA" 6 1
"AAA" 4 2
"AAA" 5 2
"AAA" 6 2
"AAA" 4 3
"AAA" 5 3
"AAA" 6 3
"BBB" 4 4
"BBB" 5 4
"BBB" 6 4
"CCC" 4 5
"CCC" 5 5
"CCC" 6 5
"CCC" 4 6
"CCC" 5 6
"CCC" 6 6
end

etc. Data is sorted like this. The variable ID here is manually assigned for sake of example, but in the real dataset it is about 350,000 observations.

I've tried both
Code:
foreach
Code:
forvalues
and
Code:
levels
But none seem to cycle through each set of 4-6 independently, instead assigning the same ID number to all sets (in my case, 1). I've tried the methods in https://www.stata.com/support/faqs/d...-with-foreach/, but to no avail. I think I'm overlooking something rather easy, could anyone point me in the right direction?

Thanks in advance,

Bas de Kruijf