Hey folks. I have a dataset with respondents reporting how many visits they took to certain recreation sites in the past year, and I have created a variable which records the maximum number of visits the respondents report across all sites.Here is an example dataset showing the structure:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(Site1 Site2 Site3 MaxVisits)
3 5 1 5
6 1 0 6
12 6 11 12
3 0 0 3
end
I want to generate a new variable which takes on the value of the most visited site, like this :
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(Site1 Site2 Site3 MaxVisits) str5 MostVisitedSite
3 5 1 5 "Site2"
6 1 0 6 "Site1"
12 6 11 12 "Site1"
3 0 0 3 "Site1"
end
Any idea how to go about this? Also is there any way to deal with the possibility here that more than one site may be the most visited (like randomly returning one of the tied sites for the value of MostVisitedSite)? Thank you so much in advance!
0 Response to Returning the name of a variable that takes on the maximum value within a set of other variables?
Post a Comment