mardi 14 janvier 2020

R: Combining four variables into one [closed]

I have a dataset with 5 variables : [1] race-ethnicity, [2] q3_3a, [3] q3_3b, [4] q3_3c, and [5] q3_3d).

Raceeth is a factor with 11 levels (White, NHPI, Black, Latino, and 7 Asian-American groups).

q3_3a to q3_3d are a series of survey questions that have 4 outcomes: [1] ethnic media, [2] Us media, [3] Equal, and [4] Others. These questions ask respondents if they primarily get their news through ethnic sources or through U.S mainstream media. These survey questions operate as follows:

  • only the 7 Asian-Americans group are asked q3_3a
  • only NHPI are asked q3_3b
  • only Latinos are asked q3_3c
  • only Blacks are asked q3_3d

The replication data can be downloaded here:

library(foreign)
pre<-read.csv("https://www.dropbox.com/s/wzitbwr6q2i26gt/sampledata.csv?dl=1")

The cross-tabs look like this:

with(pre,table(raceeth,q3_3a,useNA="always")) # Asian 
with(pre,table(raceeth,q3_3b,useNA="always")) # NHPI 
with(pre,table(raceeth,q3_3c,useNA="always")) # Latino 
with(pre,table(raceeth,q3_3d,useNA="always")) # Black

I want to combine these four survey questions into one unified variable. For example, if a Latino person answers “2. English more”, s/he can be in the same group as an Asian/Black person choosing “2. Mainstream American more”? How do I do this? Thanks so much in advance

Aucun commentaire:

Enregistrer un commentaire