Hello all:

I am trying to replace first row of path with "CLL" and second row of path as "RT" for _merge == 2 cases. The code is replacing both rows with either CLL or RT. What am I doing wrong? studyid 4 and 5 would be examples.

bys studyid: replace path[`1'] = "CLL" if _merge == 2
bys studyid: replace path[`_N'] = "RT" if _merge == 2 // not working

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input int studyid str55 path byte _merge
 1 "Normal"       3
 1 "CLL"          3
 1 "CLL"          3
 1 "CLL"          3
 1 "CLL/PL"       3
 1 "CLL"          3
 1 "CLL"          3
 1 "CLL"          3
 1 "CLL"          3
 2 "CLL"          3
 3 "CLL"          3
 3 "Mixed CLL-RT" 3
 3 "Mixed CLL-RT" 3
 3 "Mixed CLL-RT" 3
 4 ""             2
 4 ""             2
 5 ""             2
 5 ""             2
 6 "CLL"          3
 6 "Mixed CLL-RT" 3
 6 "CLL"          3
 6 "CLL"          3
 6 "CLL"          3
 6 "CLL"          3
 6 "RT"           3
 6 "CLL"          3
 7 "Mixed CLL-RT" 3
 8 ""             2
 8 ""             2
 9 "CLL"          3
 9 "CLL"          3
 9 "CLL"          3
 9 "CLL"          3
10 ""             2
10 ""             2
11 ""             2
11 ""             2
12 "Normal"       3
12 "CLL"          3
12 "Normal"       3
12 "RT"           3
12 "Normal"       3
12 "Normal"       3
12 "Normal"       3
13 "CLL"          3
13 "CLL"          3
14 "Other"        3
14 "Other"        3
14 "Other"        3
14 "Other"        3
15 "CLL"          3
15 "Mixed CLL-RT" 3
15 "CLL"          3
15 "CLL"          3
15 "CLL"          3
16 "Mixed CLL-RT" 3
16 "Mixed CLL-RT" 3
16 "CLL"          3
16 "CLL"          3
17 "CLL"          3
17 "Mixed CLL-RT" 3
17 "CLL"          3
18 "CLL"          3
18 "RT"           3
18 "Normal"       3
18 "Normal"       3
18 "."            3
18 "Normal"       3
18 "Normal"       3
19 "CLL"          3
19 "CLL"          3
19 "CLL"          3
20 ""             2
20 ""             2
21 "Normal"       3
22 ""             2
22 ""             2
23 "CLL"          3
23 "Normal"       3
23 "CLL"          3
23 "CLL"          3
23 "CLL"          3
23 "CLL"          3
23 "CLL"          3
23 "CLL"          3
23 "CLL"          3
24 "."            3
24 "CLL"          3
24 "CLL"          3
25 "CLL"          3
25 "."            3
25 "Mixed CLL-RT" 3
25 "Mixed CLL-RT" 3
26 "RT"           3
26 "CLL"          3
26 "CLL"          3
26 "CLL"          3
26 "Mixed CLL-RT" 3
27 "Normal"       3
27 "CLL"          3
end
label values _merge _merge
label def _merge 2 "Using only (2)", modify
label def _merge 3 "Matched (3)", modify