Hi All,
Apologies if this has already been covered (and I'm sure it has) I just cannot find the right answer despite extensive searching. I have a dataset with about 15,000 patients. Each patient has a unique ID , the meds they are on are recorded at a particular time post-transplant (e.g Initial, 3 Mth, 1 Yr, 3Yr) on individual rows. Each patient is usually on three different immunosuppressant medications, each medication is represented by a letter (see below). I am trying to group the initial immunosuppression regimens into one variable so that differences in a different outcome (not shown) can be examined between those on particular immunosuppression combinations.
transplantid drugcode monthcode
1 76 P Initial
2 76 V Initial
3 76 X Initial
4 76 P 3 Mth
5 76 V 3 Mth
6 76 X 3 Mth
7 77. P Initial
I am trying to collapse and reshape the data to have a single row for each patient according to their unique ID that includes their immunosuppression in one variable, this should be the first recorded observations post-transplant i.e. initial but not all patients had their immunosuppression recorded initially. For some the first recording was at 3 Mth or 1 Yr, monthcode is a factor variable.
Ideal Output would look something like
transplantid drugcodes monthcode
1 1 PVX Initial
2 2 VXU Initial
3 3 XPV Initial
4 4 PVX Initial
5 5 VCP Initial
6 6 XCP Initial
Many thanks in advance for any help or helpful posts people may know of
Ryan