Hi,

I have the following data where my outcome of interest is the "foodcategory" variable. I am trying to code the command in such a way so that I have only one outcome variable of foodcategory for each student at each date. I have an idea that this might involve the bysort command and switching the data from long to wide view, but I am unable to figure it out. What I want to do is to have the category "proteins" only once for student id 1 at date 9/1/2017, but as can be seen in the data, there are two "proteins" observations for that particular student at that date. Similarly, I want to do the same for other categories like "vegetables" and "fruits" .What is the best way to go about it? I have also included the example data. Any help on this would be helpful!


input byte studentid str10(date foodchoice) str12 fooditem byte consumptioninunits
1 " 9/1/2017" "vegetables" "beans" 2
1 " 9/1/2017" "vegetables" "peas" 1
1 " 9/1/2017" "proteins" "eggs" 1
1 " 9/1/2017" "fruits" "tomatoes" 2
1 " 9/1/2017" "proteins" "milk " 2
1 " 9/1/2017" "fruits" "apples" 4
1 " 9/1/2017" "fruits" "bananas " 3
1 " 5/2/2017" "fruits" "berries" 3
1 " 5/2/2017" "proteins" "protein bar" 1
1 " 5/2/2017" "proteins" "milk " 2
1 " 5/2/2017" "proteins" "cheese" 1
1 " 5/2/2017" "vegetables" "lentils" 1
1 " 5/2/2017" "fruits" "avocaodo" 2
1 " 5/2/2017" "fruits" "plums" 1
1 "19/3/2017" "fruits" "plums" 1
1 "19/3/2017" "fruits" "apples" 2
1 "19/3/2017" "vegetables" "kidney beans" 1
1 "19/3/2017" "proteins" "milk " 1
1 "19/3/2017" "vegetables" "onions" 2
1 "19/3/2017" "fruits" "cherries" 1
1 "19/3/2017" "fruits" "berries" 2