I would appreciate a hand with concise code to convert variable values that are listed alphabetically (i.e. currently a to q (representing waves in a panel dataset) to numerical values (1 - 17). While I did refer to a number of previous threads, I struggled to find a solution, including Cox (2002b, 2003) and Stata help files.

My original code is clearly unnecessarily lengthy:
e.g. gen wavenum = .
replace wavenum = 1 if(wave=="a")
replace wavenum = 2 if(wave=="b")
replace wavenum = 3 if(wave=="c")

etc.

Essentially I was wondering if/how I could use 'foreach' or 'forvalues' to address this problem more succinctly .

Thank you in advance.