I'm using the Understanding Society Survey to measure racial harassment. The survey is based on two-stage questions, meaning that participants are first asked whether they have been f.ex. attacked (yes/no) and what the reasons for these were (ethnicity, nationality, etc.) and then once they've chosen the reason they are further asked where this form of harassment happened.
I want to create one single variable out of this.
Thus I want to first create one variable meaning that people have been harassed due to their ethnicity. I therefore need to create one variable out of the different locations together (a_resattackedw1_1_3=1 + a_resattackedw1_2_3=1 + ...).
In SPSS I did this like this:
##compute attacked_ethn=0
if(a_resattackedw1_1_3=1) attacked_ethn=1.
if(a_resattackedw1_2_3=1) attacked_ethn=1.
if(a_resattackedw1_3_3=1) attacked_ethn=1.
if(a_resattackedw1_4_3=1) attacked_ethn=1.
if(a_resattackedw1_5_3=1) attacked_ethn=1.
if(a_resattackedw1_6_3=1) attacked_ethn=1.
if(a_resattackedw1_7_3=1) attacked_ethn=1.
if(a_resattackedw1_97_3=1) attacked_ethn=1.
add value labels attacked_ethn 0 'not mentioned' 1 'mentioned'.
How do I do this in R?
And then furthermore how do I create one variable for attacked due to racial reasons after I created the previous variables for all racially motivated reasons?
Again, in SPSS I did it like this:
#compute attacked due to racism variable#
IF (a_attacked_dv = 1) attacked=SUM(attacked_ethn,attacked_nat,attacked_rel).
VARIABLE LABELS attacked 'attacked for racial reasons'.
EXECUTE.
FREQUENCIES VARIABLES=attacked
/ORDER=ANALYSIS.
What is the R code for this?
Thank you for your help!