Dear Statalist,
I have 2 questions below:
(1)
I am wondering if there is a way to generate random strings with pre-defined digits and combinations?
Specifically, I want a a total of 600 6-digit strings, in the format of [UPPER LETTER][NUMBER][UPPER LETTER][UPPER LETTER][NUMBER][UPPER LETTER], e.g. A3GF6Z.
And I don't want duplicates within these 600 obs. I am not aware of how to do this with the combination of generating both letters and numbers
In all, the conditions are
#1: obs = 600
#2: 6-digit strings
#3: format of [upp letter][#][upp letter][upp letter][#][upp letter]
#4: no duplicate
#5: random
(2)
Also, when I tried syntax below to try to generate a 6-digit all upper letter random strings , it did not work on my StataMP 15, with error saying that "command ralpha is unrecognized r(199);"\
Any help of the 2 questions is appreciated! Thanks!
Yingyi
I have 2 questions below:
(1)
I am wondering if there is a way to generate random strings with pre-defined digits and combinations?
Specifically, I want a a total of 600 6-digit strings, in the format of [UPPER LETTER][NUMBER][UPPER LETTER][UPPER LETTER][NUMBER][UPPER LETTER], e.g. A3GF6Z.
And I don't want duplicates within these 600 obs. I am not aware of how to do this with the combination of generating both letters and numbers
In all, the conditions are
#1: obs = 600
#2: 6-digit strings
#3: format of [upp letter][#][upp letter][upp letter][#][upp letter]
#4: no duplicate
#5: random
(2)
Also, when I tried syntax below to try to generate a 6-digit all upper letter random strings , it did not work on my StataMP 15, with error saying that "command ralpha is unrecognized r(199);"\
Code:
clear set obs 600 gen random_string = "" local lrandom_string 6 forval n = 1/`lrandom_string' { ralpha new, upp replace random_string = random_string + new drop new }
Any help of the 2 questions is appreciated! Thanks!
Yingyi
Comment