I have a variable in Stata which consists of letters such as A, B, AB, AC, etc.
I want to change to numeric, with values numbers instead of letters, such as 1 instead of A.
I tried to encode the variable and then recode but it does not work.
I also tried to generate a new variable with if but that also does not work.
encodeshould work fine. Here is an example.encodeby default maps distinct strings, ordered alphabetically, to integers 1 up.If you don't like the default, you need to specify your own different scheme for translation. Doing that carefully should remove, or at least reduce, any need for a
recode.