Hi!
I hope you can help me with a clever solution so I can skip the manual generation of new variables in a large dataset.
I want to create two new variables.
1. Within the same ID and SampleID, if Category_1 observations are all the same, the value in the new variable (New_Category_1) should be 1, 2, 3 or 4. Within the same ID and SampleID, if Category_1 contains different values, the value in New_Category_1 should be 5.
2. Same as above, only Category 2 can contain up to 100 different values, and the New_Category_2 should only have 2 possible outcomes (simple or complex)
I hope this makes sense.
Thank you.
I hope you can help me with a clever solution so I can skip the manual generation of new variables in a large dataset.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(ID SampleID Category_1 Category_2) 1 1 1 4 1 1 2 37 1 2 2 50 2 1 1 6 2 2 1 6 2 2 1 6 2 2 1 6 2 2 1 6 3 1 4 81 4 1 1 5 5 1 1 21 5 2 1 21 5 3 1 21 5 4 1 21 6 1 2 43 6 1 2 76 end
1. Within the same ID and SampleID, if Category_1 observations are all the same, the value in the new variable (New_Category_1) should be 1, 2, 3 or 4. Within the same ID and SampleID, if Category_1 contains different values, the value in New_Category_1 should be 5.
2. Same as above, only Category 2 can contain up to 100 different values, and the New_Category_2 should only have 2 possible outcomes (simple or complex)
I hope this makes sense.
Thank you.
Comment