I have a dataset that looks something like this.
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
So this is a dataset that is collected at various time points in a patients stay and the path_recover_1/2/3/ indicates the sequential number of culture (i.e pathrecover_1 is first culture taken, path_recover_2 indicates 2nd and so on and so forth). The maximum number of cultures taken is 10. path1s_1 indicates if source of 1st culture was urine and path1s_2 if first culture was blood and so on and so forth. At a time a culture can only be taken from one source . So if 1st culture was from urine then path1s_1 will be yes, while rest will be no. same goes for other cultures. Total cultures taken go upto 10 and sources are 8.
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'
        }
     }
}
I have to do it for each culture number and then for each source. Any help on how to do this would be greatly appreciated.
Thanks a ton.

Shalom