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 between Intraclass Correlation and Within R-SquaredHi, I am running the following fixed effects model: xtset acode qdate xtreg recycling loginc logpop…
invalid error using nwcommandsHi everyone! I want to use the nwcommands to do some social network analysis and encountered a prob…
Merger of datasets with different data frequencyHi everyone, I have to merge two datasets: "Monthly data" and "Fundamentals quarterly". The first …
Spatial matrix user definesDear All, I would like to generate a spatial matrix defined by myself. I have the following data: …
Multilevel Model with ESS Data (Survey Data) doesn't convergeTo whom it may concern, I try to calculate a multilevel model for the effect of migration integrati…
Subscribe to:
Post Comments (Atom)
0 Response to Switching data from long to wide view with dates and repeated observations
Post a Comment