lebebr01/SPSStoR

recode into different variables

Closed this issue · 4 comments

is it possible to convert "recode into different variables" with this packages?

Is it possible you can share example SPSS code for this? That would help me better understand if this is implemented.

The SPSS syntax is similar to follows:

DATASET ACTIVATE DataSet1.
RECODE VAR00001 (MISSING=SYSMIS) (1=1) (2=1) (3=2) (ELSE=3) INTO Var2.
EXECUTE.

RECODE VAR00001 (5 thru 10=2) (Lowest thru 4=1) (11 thru Highest=3) INTO Var2.
EXECUTE.

Thank you

There is a recode_to_r function in the package that should be able to accomplish these tasks. I'm unsure if I had programmed all of the keywords, for example 'Lowest' or 'Highest'. You can try converting a SPSS file with:

spss_to_r(spss_file)

Thank you.
I tried, some of the conversions worked.

SPSS code:

RECODE Yon ('R'=0) ('L'=1) INTO Yon2.
EXECUTE.

RECODE VAR00001 (MISSING=SYSMIS) (1=1) (2=1) (3=2) (ELSE=3) INTO Var2.
EXECUTE.

RECODE VAR00001 (5 thru 10=2) (Lowest thru 4=1) (11 thru Highest=3) INTO Var2.
EXECUTE.

Output:

library(car)
# x is the name of your data frame
x$Yon <- recode(x$Yon, “'R'=0”)
x$VAR00001 <- recode(x$VAR00001, “MISSING=SYSMIS”)
x$VAR00001 <- recode(x$VAR00001, “5thru10=2”)