path_recover_1 | path1s_1 | path1s_2 | path1s_2 | path1s_3 | path1s_4 | path1s_5 | path1s_6 | path1s_7 | path_recover | path2s_1 | path2s_2 | path2s_3 | path2s_4 | path2s_5 | path2s_6 | path_recover_3 | path3s_1 | path3s_2 | path3s_3 |
yes | no | yes | no | no | no | no | no | no | yes | no | no | no | no | yes | no | yes | no yes | no | no |
I have abbreviated the source to s in the above table
I want to rename the source of cultures as it is very tedious to keep referring to the databook and see which number corresponds to which source. Manually changing it is a tedious. I tried writing a loop (which I am not very good at) and as expected I am getting errors.
Code:
forvalues i=2/10 { if path_recover`i'{ foreach j=1/8 in pathogen`i'_source___`j'{ if `j'==1 then rename pathogen`i'_source___`j' urine_`i' if `j'==2 then rename pathogen`i'_source___`j' blood_`i' if `j'==3 then rename pathogen`i'_source___`j' sputum_`i' if `j'==4 then rename pathogen`i'_source___`j' peritoneal_`i' if `j'==5 then rename pathogen`i'_source___`j' csf_`i' if `j'==6 then rename pathogen`i'_source___`j' pleural_`i' if `j'==7 then rename pathogen`i'_source___`j' stoolnat_`i' if `j'==8 then rename pathogen`i'_source___`j' other_`i' } } }
Thanks a ton.
Shalom
0 Response to Need help renaming variables in a loop
Post a Comment