Hello:
I am trying to encode str var into an encoded var_code, which is typically a simple command... IF you let Stata choose the order that it assigns the number-value label match for you. However, I have been trying to customize this and define which number I would like to represent which string--but have had no luck, other than manually using...
Where var contains observations Truck, Car, Boat, Plane:
Then I manually add value labels to those new numbers generated as the original representation in var.
So I can do this--it's fine, however, if I have 250 different observations in the original var, customizing the encoding originally to the value labels desired would save redundancy in having to separately convert to number then recreate the desired "string label". And manually entering 250 different value labels is laborious.
Thanks for assistance.
I am trying to encode str var into an encoded var_code, which is typically a simple command... IF you let Stata choose the order that it assigns the number-value label match for you. However, I have been trying to customize this and define which number I would like to represent which string--but have had no luck, other than manually using...
Where var contains observations Truck, Car, Boat, Plane:
Code:
gen var_code=. replace rec_code=1 if var == "Truck" replace rec_code=2 if var == "Boat" replace rec_code=3 if var == "Plane" replace rec_code=4 if var == "Car"
So I can do this--it's fine, however, if I have 250 different observations in the original var, customizing the encoding originally to the value labels desired would save redundancy in having to separately convert to number then recreate the desired "string label". And manually entering 250 different value labels is laborious.
Thanks for assistance.
Comment