Given the example data below, I'm trying to count the number of unique drugs per patient ID. For example, patient 9 would have a unique drug count of 5, and patient 68 would have a count of 3.
I've been attempting to adapt some code elsewhere (https://www.stata.com/support/faqs/d...tinct-strings/), such that the counts are provided for each ID rather than each row, but I'm struggling. Any advice would be hugely appreciated.
I've been attempting to adapt some code elsewhere (https://www.stata.com/support/faqs/d...tinct-strings/), such that the counts are provided for each ID rather than each row, but I'm struggling. Any advice would be hugely appreciated.
Code:
clear input float id str16(regimen_drugs_1 regimen_drugs_2) str11 regimen_drugs_3 1 "" "" "" 2 "" "" "" 3 "" "" "" 4 "" "" "" 5 "" "" "" 6 "" "" "" 7 "" "" "" 8 "" "" "" 9 "CARBOPLATIN" "ETOPOSIDE" "" 9 "CYCLOPHOSPHAMIDE" "DOXORUBICIN" "VINCRISTINE" 10 "" "" "" 11 "" "" "" 12 "" "" "" 13 "" "" "" 14 "" "" "" 15 "" "" "" 16 "GEMCITABINE" "" "" 17 "CYCLOPHOSPHAMIDE" "DOXORUBICIN" "VINCRISTINE" 17 "EPIRUBICIN" "CYCLOPHOSPHAMIDE" "" 18 "" "" "" 19 "" "" "" 20 "CARBOPLATIN" "ETOPOSIDE" "" 21 "CARBOPLATIN" "ETOPOSIDE" "" 21 "CYCLOPHOSPHAMIDE" "DOXORUBICIN" "VINCRISTINE" 22 "" "" "" 23 "" "" "" 24 "" "" "" 25 "" "" "" 26 "" "" "" 27 "" "" "" 28 "" "" "" 29 "" "" "" 30 "" "" "" 31 "" "" "" 32 "" "" "" 33 "" "" "" 33 "CARBOPLATIN" "ETOPOSIDE" "" 33 "CARBOPLATIN" "ETOPOSIDE" "" 34 "" "" "" 35 "" "" "" 36 "" "" "" 37 "CARBOPLATIN" "ETOPOSIDE" "" 37 "CARBOPLATIN" "ETOPOSIDE" "" 38 "" "" "" 39 "" "" "" 40 "" "" "" 41 "" "" "" 42 "CARBOPLATIN" "ETOPOSIDE" "" 42 "CISPLATIN" "ETOPOSIDE" "" 43 "CARBOPLATIN" "ETOPOSIDE" "" 44 "" "" "" 45 "CARBOPLATIN" "ETOPOSIDE" "" 45 "CARBOPLATIN" "ETOPOSIDE" "" 46 "" "" "" 47 "" "" "" 48 "" "" "" 49 "" "" "" 50 "" "" "" 51 "" "" "" 52 "" "" "" 53 "" "" "" 54 "" "" "" 55 "CARBOPLATIN" "ETOPOSIDE" "" 56 "" "" "" 57 "CARBOPLATIN" "ETOPOSIDE" "" 57 "CARBOPLATIN" "ETOPOSIDE" "" 58 "CARBOPLATIN" "ETOPOSIDE" "" 59 "" "" "" 60 "" "" "" 61 "" "" "" 62 "" "" "" 63 "" "" "" 64 "" "" "" 65 "" "" "" 66 "" "" "" 67 "" "" "" 68 "PAZOPANIB" "" "" 68 "CARBOPLATIN" "ETOPOSIDE" "" 68 "CARBOPLATIN" "" "" 68 "CARBOPLATIN" "ETOPOSIDE" "" 69 "" "" "" 70 "CARBOPLATIN" "ETOPOSIDE" "" 71 "" "" "" 72 "" "" "" 73 "" "" "" 74 "" "" "" 75 "" "" "" 76 "" "" "" 77 "" "" "" 78 "" "" "" 79 "" "" "" 80 "CARBOPLATIN" "" "" 81 "" "" "" 82 "" "" "" 83 "CISPLATIN" "ETOPOSIDE" "" 84 "" "" "" 85 "" "" "" 86 "" "" "" 87 "" "" "" 88 "" "" "" end
Comment