Using the code below, I am trying to rename the first 145 variables in my dataset and reiterate this for every 4 variables. The line of code "local H_or_U = cond(mod(`pos',2) == 0, "H", "U")" is supposed to add the "H" prefix to the first two variables and the "U" prefix to the third and fourth one and so on. On the contrary, the line of code noted above only adds the H prefix to all of 145 variables. Thanks for helping me to fix this.
NM
Code:
local pos 0 forvalues i = 1 (4) 145 { local H_or_U = cond(mod(`pos',2) == 0, "H", "U") rename _bs_`++pos' `H_or_U'H_M_W_bs_`pos' rename _bs_`++pos' `H_or_U'H_M_B_bs_`pos' rename _bs_`++pos' `H_or_U'H_M_W_bs_`pos' rename _bs_`++pos' `H_or_U'H_M_B_bs_`pos' }
0 Response to Problem with renaming variables
Post a Comment