Hello, the following simulation uses the command
to create, within subject ID, sequential numbers for each successive clinic visit.
However, note that the sequence number created [chemono] 1 through 6, rather than the 1 through 3 which is the desired outcome.
In other words, I wish the data to reflect that each of these two subjects had 3 visits (parenthetically, my code already correctly calculates that within each visit they each received two medications).
How would I modify the -bysort- command to achieve the correct visit sequence numbers?
Code:
bysort var1(var2): generate var3=_n
However, note that the sequence number created [chemono] 1 through 6, rather than the 1 through 3 which is the desired outcome.
In other words, I wish the data to reflect that each of these two subjects had 3 visits (parenthetically, my code already correctly calculates that within each visit they each received two medications).
How would I modify the -bysort- command to achieve the correct visit sequence numbers?
Code:
clear input str2 id str9 datetx str11 drug 1 13mar2014 Carboplatin 1 13mar2014 Paclitaxel 1 03apr2014 Carboplatin 1 03apr2014 Paclitaxel 1 24apr2014 Carboplatin 1 24apr2014 Paclitaxel 2 15may2014 Cytoxan 2 15may2014 Adriamycin 2 05jun2014 Cytoxan 2 05jun2014 Adriamycin 2 26jun2014 Cytoxan 2 26jun2014 Adriamycin end l, noo sepby(id) by datetx drug, sort: gen polychem = _n==1 by datetx: replace polychem=sum(polychem) by datetx: replace polychem=polychem[_N] bysort id (datetx): generate chemono = _n l id chemono drug polychem datetx, noo sepby(id datetx)
Comment