Dear Statalist,
I'm trying to keep observations that have the max value of a variable for multiple variables for a caseID so that there is only one caseID with the max number for the variable. All of the variables are binary outcomes. For example, in the dataset below, I would like to collapse the CaseIDs so that there is one CaseID for 1 and 2 and keep the highest number for orange, apple, and banana for each CaseID. I'd like to get table 1 to look like table 2. Thanks in advance for any guidance!
Table 1
Table 2
I'm trying to keep observations that have the max value of a variable for multiple variables for a caseID so that there is only one caseID with the max number for the variable. All of the variables are binary outcomes. For example, in the dataset below, I would like to collapse the CaseIDs so that there is one CaseID for 1 and 2 and keep the highest number for orange, apple, and banana for each CaseID. I'd like to get table 1 to look like table 2. Thanks in advance for any guidance!
Table 1
CaseID | Orange | Apple | Banana |
1 | 1 | 0 | 0 |
1 | 0 | 1 | 0 |
1 | 0 | 0 | 1 |
1 | 0 | 0 | 0 |
2 | 0 | 0 | 1 |
2 | 0 | 0 | 0 |
2 | 0 | 0 | 0 |
CaseID | Orange | Apple | Banana |
1 | 1 | 1 | 1 |
2 | 0 | 0 | 1 |
Comment