For my stats class, he wants us to collapse variables into new ones. I'm looking at precincts in the USA. Three of my variables are: %White officers (in this precinct), %Black officers, and %Hispanic Officers. How would I collapse a variable that would give which one was most predominant in a specific case? (Ex: 1 = %White is most predominant; 2 = %Black is most predominant; 3 = %Hispanic Officers is most predominant).
The example I was given was: mydata$VariableNewName= ifelse(mydata$Variable== 0, 1, mydata$VariableNewName).
But for this to work, instead of my ifelse statement equaling 0, it would have to equal whichever the predominant race is. Does that make sense? That's the part I'm stuck on.
For reference, this is how my SPSS Syntax worked if that makes my question any clearer:
Compute PredominantRace = 0.
If WhitePercent > BlackPercent AND WhitePercent > HispanicPercent PredominantRace = 1.
If BlackPercent > WhitePercent AND BlackPercent > HispanicPercent PredominantRace = 2.
If HispanicPercent > WhitePercent AND HispanicPercent > BlackPercent PredominantRace = 3.