I am attempting to convert from SPSS to R; I wanted to translate my cleaning syntax as a good way to learn R, but I am having a great deal of trouble with what is a simple command in SPSS.
The following code works in SPSS:
IF (n_race = 1 & (n_ethnicity = 7 | n_ethnicity = 8 | n_ethnicity = 99)) race_eth=1.
EXECUTE.
IF (n_ethnicity = 3 & (n_race = 1 | n_race = 99)) race_eth=2.
EXECUTE.
IF (n_race = 2) race_eth=3.
EXECUTE.
IF (n_race = 5 & n_ethnicity NE 9) race_eth=4.
EXECUTE.
IF ((n_ethnicity = 2 | n_ethnicity = 4 | n_ethnicity = 5) & (n_race = 1 | n_race = 99)) race_eth=4.
EXECUTE.
IF (n_ethnicity = 9 & (n_race = 1 | n_race = 5 | n_race = 99)) race_eth=5.
EXECUTE.
IF (n_race = 4 | (n_ethnicity = 6 & (n_race = 1 | n_race = 99))) race_eth=6.
EXECUTE.
IF (n_ethnicity = 1 & (n_race = 1 | n_race = 99)) race_eth=6.
EXECUTE.
IF (n_race=99 AND (n_ethnicity=7 OR n_ethnicity=99 OR n_ethnicity=8)) race_eth=99.
EXECUTE.
I thought this code would do the same thing in R, but the cell frequencies are not the same (note that I renamed n_ethnicity to n_eth in R). I would greatly appreciate any help! Thanks!
OMSOct14_Mar16$race_eth[n_race == 1 & (n_eth == 7 | n_eth == 8 | n_eth == 99)] <- 1
OMSOct14_Mar16$race_eth[n_eth == 3 & (n_race == 1 | n_race == 99)] <- 2
OMSOct14_Mar16$race_eth[n_race == 2] <- 3
OMSOct14_Mar16$race_eth[n_race == 5 & n_eth != 9] <- 4
OMSOct14_Mar16$race_eth[(n_eth == 2 | n_eth==4 | n_eth==5) & (n_race == 1 | n_race == 99)] <- 4
OMSOct14_Mar16$race_eth[n_eth == 9 & (n_race == 1 | n_race == 5 | n_race==99)] <- 5
OMSOct14_Mar16$race_eth[n_race == 4 | (n_eth == 6 & (n_race==1 | n_race == 99))] <- 6
OMSOct14_Mar16$race_eth[n_eth == 1 & (n_race == 1 | n_race == 99)] <- 6
OMSOct14_Mar16$race_eth[n_race == 99 & (n_eth == 7 | n_eth == 8 | n_eth==99)] <- 99