Hello.
I have the following dataset with variables id and group. IDs are repeated because right now they are allowed to be in more than one group and my dataset is in long format. Ultimately, what I would like to do is to merge groups if they have at least one common ID, something along the lines of variable idgroup.
However, although I think I might need to use something along the lines of ‘cond’ to generate idgroup, I am still missing how could I include id values to determine whether to capture the value of group. Also, I would need to make sure the variable idgroup is actually merging groups with at least one common id. For example, id==6 should be part of the idgroup==”AD” since they share id==1 even though id==6 only appears on group==”A”. I appreciate any suggestions.
I have the following dataset with variables id and group. IDs are repeated because right now they are allowed to be in more than one group and my dataset is in long format. Ultimately, what I would like to do is to merge groups if they have at least one common ID, something along the lines of variable idgroup.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float id str1 group str2 idgroup 1 "A" "AD" 2 "B" "B" 3 "C" "CG" 1 "D" "AD" 4 "E" "E" 5 "F" "F" 3 "G" "CG" 6 "A" "AD" end
Comment