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
Related Posts with Switching data from long to wide view with dates and repeated observations
Difference-in-difference multiple time periodsDear all For my research, I want to estimate the effect of introducing direct election of mayors in…
Synthetic Controls - String VariablesI am trying to run the npsynth command (Abadie, Diamond, Hainmueller, 2009) with a database of gravi…
Spell lengthDear Statalisters, I am trying to calculate the spell length to capture the first transition from p…
Removing label values from selected variablesHi I have applied same label values to various variables. I want to remove such label values from se…
Seasonality graphicsHi, i need help! I'm testing seasonality in trend research about a rare disease. I found statistic…
Subscribe to:
Post Comments (Atom)
0 Response to Switching data from long to wide view with dates and repeated observations
Post a Comment