Hi everyone,
I have a panel data from 2000-2020 at the factory level. The factory ID is a string variable and I am trying to create a numeric id for the factory.
Here is the code that I tried:
And this is how it looks:
For some reason, this is not generating unique ids. I thought maybe the issue is it's generating a float variable but even after I try gen long, the problem remains.
I have a panel data from 2000-2020 at the factory level. The factory ID is a string variable and I am trying to create a numeric id for the factory.
Here is the code that I tried:
Code:
bysort FACTORYId : gen id = _N
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str50 FACTORYId float id "0000006F" 1 "0000008B" 2 "0000008B" 2 "0000022F" 1 "0000023F" 1 "0000033F" 5 "0000033F" 5 "0000033F" 5 "0000033F" 5 "0000033F" 5 "0000103F" 1 "0000108B" 3 "0000108B" 3 "0000108B" 3 "0000123F" 2 "0000123F" 2 "0000132F" 2 "0000132F" 2 "0000133F" 4 "0000133F" 4 "0000133F" 4 "0000133F" 4 "0000206F" 5 "0000206F" 5 "0000206F" 5 "0000206F" 5 "0000206F" 5 "0000207F" 2 "0000207F" 2 "0000208B" 6 "0000208B" 6 "0000208B" 6 "0000208B" 6 "0000208B" 6 "0000208B" 6 "0000209F" 2 "0000209F" 2 "0000219F" 2 "0000219F" 2 "0000222F" 1 "0000306F" 1 "0000308B" 3 "0000308B" 3 "0000308B" 3 "0000310F" 3 "0000310F" 3 "0000310F" 3 "0000322F" 1 "0000323F" 1 "0000332F" 1 "0000333F" 3 "0000333F" 3 "0000333F" 3 "0000406F" 1 "0000407F" 2 "0000407F" 2 "0000408B" 5 "0000408B" 5 "0000408B" 5 "0000408B" 5 "0000408B" 5 "0000420F" 2 "0000420F" 2 "0000522F" 3 "0000522F" 3 "0000522F" 3 "0000523F" 1 "0000532F" 1 "0000607F" 1 "0000622F" 1 "0000623F" 4 "0000623F" 4 "0000623F" 4 "0000623F" 4 "0000706F" 1 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000708B" 8 "0000723F" 1 "0000733F" 2 "0000733F" 2 "0000803F" 1 "0000806F" 4 "0000806F" 4 "0000806F" 4 "0000806F" 4 "0000807F" 1 "0000820F" 2 "0000820F" 2 "0000823F" 5 "0000823F" 5 "0000823F" 5 "0000823F" 5 "0000823F" 5 "0000832F" 1 end
Comment