Hello all,

I'm working with a dataset which has variables with counters as follows: payment_1, payment_2, payment_3, etc. I want to loop over each of these variables and use `encode' as in the code below. However, when naming the new variable, I want to keep a common suffix with 1,2,3...added in the end. More precisely, I want to the new variable names to look like pe_1, pe_2, pe_3, etc. Is there a way to do this in the same line of code, Apologies if my question is not clear. And thanks for any suggestions!
Code:
 foreach `var' of varlist payment_* {
    encode `var', gen(`newname')
}