Dear all,
I am having some issues with my dataset and I would be very grateful for your help. I have a large dataset of surveillance data concerning 1 infectious disease. There are many ID duplicates as several patients had several different samples tested. The samples come from different body sites such as Site 1 or Site 2 and they are recorded in the variable SAMPLE. Unfortunately, there are many missing observations in this variable as the SAMPLE was recorded only for the first different observation of each ID as depicted below.
Observation |ID | SAMPLE |
1 1234 Site 1
2 1234 .
3 1234 .
4 1234 Site 2
5 1234 Site 3
6 5678 Site 2
7 5678 .
8 5678 .
What I would like to do is to copy the observations to SAMPLE based on the same ID. For example, Observation 1 of the variable SAMPLE copy to observations 2 and 3 of the same variable, observation 6 copy to observation 7 and 8, etc. As there are about 15.000 missing values, I cannot do it one by one. Is there any command which would allow me to copy these based on the condition of having the same ID?
My second question relates to the possibility of merging several different observations again based on ID. Let's say I want to merge observations with same ID in the variable SAMPLE so that I get this:
Observation |ID | SAMPLE |
1 1234 Site 1, Site 2, Site 3
2 5678 Site 2
Is there any way I can do such a merge?
Thanks in advance for your help.
Andrea
I am having some issues with my dataset and I would be very grateful for your help. I have a large dataset of surveillance data concerning 1 infectious disease. There are many ID duplicates as several patients had several different samples tested. The samples come from different body sites such as Site 1 or Site 2 and they are recorded in the variable SAMPLE. Unfortunately, there are many missing observations in this variable as the SAMPLE was recorded only for the first different observation of each ID as depicted below.
Observation |ID | SAMPLE |
1 1234 Site 1
2 1234 .
3 1234 .
4 1234 Site 2
5 1234 Site 3
6 5678 Site 2
7 5678 .
8 5678 .
What I would like to do is to copy the observations to SAMPLE based on the same ID. For example, Observation 1 of the variable SAMPLE copy to observations 2 and 3 of the same variable, observation 6 copy to observation 7 and 8, etc. As there are about 15.000 missing values, I cannot do it one by one. Is there any command which would allow me to copy these based on the condition of having the same ID?
My second question relates to the possibility of merging several different observations again based on ID. Let's say I want to merge observations with same ID in the variable SAMPLE so that I get this:
Observation |ID | SAMPLE |
1 1234 Site 1, Site 2, Site 3
2 5678 Site 2
Is there any way I can do such a merge?
Thanks in advance for your help.
Andrea
Comment