Hi,
I am very new to stata (few weeks in) and have come across a difficulty. (I have read a lot of forums and the stat help document looking for a simple answer but yet to find one)
I have a data set with 1900 observations and 20 variables.
Im looking at supplementation of people. Unfortunately the dataset was created with each ID having multiple Observations (up to 10) for each supplement reported instead of 10 variables.
(Background info: Supplements have been given a code i.e. iron supplement = 2, Multivitamins = 8 etc)
Eg of a section of the data set:
ID Gender Age Supplement Code
1 1 26 2
1 1 26 4
1 1 26 8
1 1 26 1
2 0 27 3
2 0 27 6
2 0 27 2
3 1 23 7
3 1 23 6
3 1 23 1
4 0 29 3
4 0 29 2
So from this example you can see there are multiple ID, gender and Age (which remain constant for each observation) however the supplement codes change as they have reported more than one supplement)
Ideally I would like:
ID Gender Age Supplement 1 Supplement 2 Supplement 3 Supplement 4
1 1 26 2 4 8 1
2 0 27 3 6 2 .
3 1 23 7 6 1 .
4 0 29 3 2 . .
Where there is the one ID, gender and Age observation and then for each supplement that was listed as an observation, it is now a new variable ( so for some participants that had listed 10 supplements they wont have 10 observations but there will be 10 variables in total)
I do hope this makes sense.
Many thanks in advance!
Elle
I am very new to stata (few weeks in) and have come across a difficulty. (I have read a lot of forums and the stat help document looking for a simple answer but yet to find one)
I have a data set with 1900 observations and 20 variables.
Im looking at supplementation of people. Unfortunately the dataset was created with each ID having multiple Observations (up to 10) for each supplement reported instead of 10 variables.
(Background info: Supplements have been given a code i.e. iron supplement = 2, Multivitamins = 8 etc)
Eg of a section of the data set:
ID Gender Age Supplement Code
1 1 26 2
1 1 26 4
1 1 26 8
1 1 26 1
2 0 27 3
2 0 27 6
2 0 27 2
3 1 23 7
3 1 23 6
3 1 23 1
4 0 29 3
4 0 29 2
So from this example you can see there are multiple ID, gender and Age (which remain constant for each observation) however the supplement codes change as they have reported more than one supplement)
Ideally I would like:
ID Gender Age Supplement 1 Supplement 2 Supplement 3 Supplement 4
1 1 26 2 4 8 1
2 0 27 3 6 2 .
3 1 23 7 6 1 .
4 0 29 3 2 . .
Where there is the one ID, gender and Age observation and then for each supplement that was listed as an observation, it is now a new variable ( so for some participants that had listed 10 supplements they wont have 10 observations but there will be 10 variables in total)
I do hope this makes sense.
Many thanks in advance!
Elle
Comment