Hello,
I reshaped a long-format dataset to a wide format. The Stata command has automatically added the follow-up number at the end of each new variable. I used foreach loop to add a pre-fix as Q1, Q2, Q3 for each created follow-up variable. I now need to remove the follow-up number added by Stata (last digit of each variable). However, I am uncertain how to do it, for example, I cannot use rename *3 * command to rename follow-up 3 variables after renaming follow-up 1 and 2. I would very much appreciate your help.
See some of my variables below.
Follow up 1 (Q1) Q1_S4d_1_11 Q1_S4d_1_21 Q1_S4d_1_31 Q1_S4d_1_41 Q1_S4d_1_51 Q1_S4d_1_61
Follow up 2 (Q2) Q2_S4d_1_12 Q2_S4d_1_22 Q2_S4d_1_32 Q2_S4d_1_42 Q2_S4d_1_52 Q2_S4d_1_62
Follow up 3 (Q3) Q3_S4d_1_13 Q3_S4d_1_23 Q3_S4d_1_33 Q3_S4d_1_43 Q3_S4d_1_53 Q3_S4d_1_63
I look forward to receiving your insights.
Thank you.
Dham
I reshaped a long-format dataset to a wide format. The Stata command has automatically added the follow-up number at the end of each new variable. I used foreach loop to add a pre-fix as Q1, Q2, Q3 for each created follow-up variable. I now need to remove the follow-up number added by Stata (last digit of each variable). However, I am uncertain how to do it, for example, I cannot use rename *3 * command to rename follow-up 3 variables after renaming follow-up 1 and 2. I would very much appreciate your help.
See some of my variables below.
Follow up 1 (Q1) Q1_S4d_1_11 Q1_S4d_1_21 Q1_S4d_1_31 Q1_S4d_1_41 Q1_S4d_1_51 Q1_S4d_1_61
Follow up 2 (Q2) Q2_S4d_1_12 Q2_S4d_1_22 Q2_S4d_1_32 Q2_S4d_1_42 Q2_S4d_1_52 Q2_S4d_1_62
Follow up 3 (Q3) Q3_S4d_1_13 Q3_S4d_1_23 Q3_S4d_1_33 Q3_S4d_1_43 Q3_S4d_1_53 Q3_S4d_1_63
I look forward to receiving your insights.
Thank you.
Dham
Comment