Hello Stata Community.

I'm working in my master thesis with a data base about middle class, their values and political perceptions for 24 Latin American countries. I'll focus on 2012, 2014 and 2016 waves. So, my explained variable is a categorical one (0=lower classe ; 1=middle class and 2=upper class). To run the model I have created this variable for each country and year. The problem is that i have to "isolate" the middle class in one variable, and that's relatively easy by hand with "gen" command, but I think there is an easier way than doing it one by one (or not). So, i want to run a loop which take every categorical income variable and split it in 3 different variables (LW_10_90_2012=lower classe ; MC_10_90_2012=middle class and UC_10_90_2012=upper class as an example). Here the list of variables for 2012 (there're the same variables for 2014 and 2016). Is it possible to do this process by using a loop or is it better to do it one by one?

Thank you so much!!!

per_10_90_Total_q10g_12
per_10_90_Mexico_q10g_12
per_10_90_Guatemala_q10g_12
per_10_90_Salvador_q10g_12
per_10_90_Honduras_q10g_12
per_10_90_Nicaragua_q10g_12
per_10_90_CostaRica_q10g_12
per_10_90_Panama_q10g_12
per_10_90_Colombia_q10g_12
per_10_90_Ecuador_q10g_12
per_10_90_Bolivia_q10g_12
per_10_90_Peru_q10g_12
per_10_90_Paraguay_q10g_12
per_10_90_Chile_q10g_12
per_10_90_Uruguay_q10g_12
per_10_90_Brasil_q10g_12
per_10_90_Venezuela_q10g_12
per_10_90_Argentina_q10g_12
per_10_90_RD_q10g_12
per_10_90_Haiti_q10g_12
per_10_90_Jamaica_q10g_12
per_10_90_Guyana_q10g_12
per_10_90_TriniT_q10g_12
per_10_90_Belice_q10g_12
per_10_90_Surinam_q10g_12