SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
Expand all | Collapse all

Syntax Recoding

  • 1.  Syntax Recoding

    Posted Mon August 22, 2022 07:06 PM
    Hello (again)!
    I have a feeling I will be posting here a lot.

    I am trying to recode variables - this is what I got:

    Numeric new variable (F8.4).
    recode old variable to new variable (1,5,=11) (2,3,4=5) .

    The new variable was generated, and I set up the values in the variable view with 11 as yes and 5 as no.
    When I run the frequencies table, they all show up as missing system.

    That makes me think of how I would integrate missing system??
    recode old variable to new variable (1,5,=11) (2,3,4=5) (sysmis = sysmis).

    Thanks again!

    ------------------------------
    A MC
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Syntax Recoding

    Posted Mon August 22, 2022 10:50 PM
    NUMERIC new_variable (F8.4).
    RECODE old_variable (1,5=11) (2,3,4=5) into new_variable.
    FREQUENCIES VARIABLES=new_variable.

    Perhaps take a look at the Command Syntax Reference Guide, for example, this.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: Syntax Recoding

    Posted Wed August 24, 2022 08:32 AM
    Thank you very much!
    I actually did spend quite some time trying to figure this out before I posted the question. :)

    ------------------------------
    A MC
    ------------------------------



  • 4.  RE: Syntax Recoding

    Posted Wed August 24, 2022 11:07 AM
    After more trying and utilizing some of this syntax, I give up. :)
    This is my other problem - I had tried this with syntax recoding and through the program functions.

    Recoding four Likert variables into one index -
    I want to combine the responses to four questions into one index, with responses from 1-5. 
    Essentially, I am adding the response of each category for each question together.

    Numeric NewVariable (F8.4).
    RECODE OldA OldB Old13D OldG (1=1)(2=2)(3=3)(4=4)(5=5)(SYSMIS=SYSMIS) into NewVariable.

    I get this...

    >Error # 4672
    >The number of variables to be recoded does not match the number of variables
    >following the keyword INTO.
    >Execution of this command stops.

    I also tried writing the syntax with compute... but still not getting what I need.
    Clearly, I do not know what I am doing. :)



    ------------------------------
    A MC
    ------------------------------



  • 5.  RE: Syntax Recoding

    Posted Wed August 24, 2022 12:19 PM
    Clear, you're trying to recode 4 variables (OldA OldB Old13D OldG) into single variable (NewVariable) which is illegal.

    RECODE OldA OldB Old13D OldG (1=1)(2=2)(3=3)(4=4)(5=5)(SYSMIS=SYSMIS) into NewVariable1 NewVariable2 NewVariable3 NewVariable4.

    or just

    RECODE OldA OldB Old13D OldG (1=1)(2=2)(3=3)(4=4)(5=5)(SYSMIS=SYSMIS) into NewVariable1 to NewVariable4.

    (you may use "to" on the right hand portion of the command if the varable names to create end with a digit)

    Also, if you are simpy copying variables rather than recoding them into different values, then this would be shorter:

    RECODE OldA OldB Old13D OldG (else=copy) into NewVariable1 to NewVariable4.




    ------------------------------
    Kirill Orlov
    ------------------------------



  • 6.  RE: Syntax Recoding

    Posted Wed August 31, 2022 11:35 AM
    Thank you very much!
    I think I still have the problem of not being able to combine the four variables into one index.

    ------------------------------
    A MC
    ------------------------------



  • 7.  RE: Syntax Recoding

    Posted Mon November 07, 2022 11:55 AM

    Hi @Kirill Orlov,
    I am having a similar issue with recoding variables using Syntax. I hope you can help. This may also help others as I can provide a glimpse of the data. I have one column/variable titled SERVICEX. There are more than 100 different classes in this column. I am recoding them as STEM (0) and NON-STEM (1). Is there a way to write a syntax to do this?

    Thank you,

    Debbie

    ​​

    ------------------------------
    Debra Dean
    ------------------------------



  • 8.  RE: Syntax Recoding

    Posted Mon November 07, 2022 12:01 PM
    Hi.

    There may be, using the IF command, for example, but first we'd have to know what the rules are for group membership.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 9.  RE: Syntax Recoding

    Posted Wed November 09, 2022 10:35 AM
    The original list will be recoded based on a non-scientific list. These are the classes that are deemed STEM-related. It's not as easy as saying math and science classes will be recoded, but this list is the list that will be used. Is there a way to use the IF statement to say if the class is on this list it will be recoded as 1 and if this class is not on the list, it will be recoded as 0?

    ADVANCED QUANT REASONING
    ALGEBRA I
    ALGEBRA I (ALG 1)
    ALGEBRA II (ALG2)
    AP ENVIRONMENTAL SCIENCE
    AP PHYSICS 1: ALGEBRA BASED
    AP PHYSICS 2: ALGEBRA BASED
    AP PHYSICS C: ELECTR&MAGNETISM
    AP PHYSICS C: MECHANICS
    AP STATISTICS (APSTATS)
    AQUATIC SCIENCE (AQUA SCI)
    BIOLOGY
    BIOLOGY (BIO)
    CHEMISTRY (CHEM)
    COLGE PREP COURSE MATHEMATICS
    COMPUTER SCIENCE I
    COMPUTER SCIENCE II
    COMPUTER SCIENCE III
    ENVIRONMENTAL SYSTEMS-ENVIRSYS
    GEOMETRY (GEOM)
    IB BIOLOGY STANDARD LEVEL
    IB ENVIRN SYS & SOC STND LEVL
    IND STUDY IN TECH APS 1ST TIME
    INDEP STUDY IN MATH (1ST TIME)
    INDEP STUDY IN MATH (2ND TIME)
    INTEGRATED PHYSICS/CHEMISTRY
    MATH MODELS WITH APPLICATIONS
    PHYSICS (PHYSICS)
    PRECALCULUS (PRE CALC)


    ------------------------------
    Debra Dean
    ------------------------------



  • 10.  RE: Syntax Recoding

    Posted Wed November 09, 2022 10:38 AM
    Hi. My previous answer must not have gone through. Here it is again:

    Try creating a new variable, like this:

    COMPUTE NEW_CODE=0.
    IF ANY(SERVICEX, 'ADVANCED QUANT REASONING', 'ALGEBRA I',
    'ALGEBRA I (ALG 1)', 'ALGEBRA II', 'ALGEBRA II (ALG2)',
    'AP ENVIRONMENTAL SCIENCE', 'AP PHYSICS 1', 'AP PHYSICS 2',
    'AP PHYSICS C', 'AP STATISTICS (APSTATS)', 'AQUATIC SCIENCE (AQUA SCI)',
    'BIOLOGY', 'BIOLOGY (BIO)', 'CHEMISTRY', 'CHEMISTRY (CHEM)',
    'COLGE PREP COURSE MATHEMATICS', 'COMPUTER SCIENCE I',
    'ENVIRONMENTAL SYSTEMS-ENVIRSYS', 'GEOMETRY',
    'GEOMETRY (GEOM)', 'IB BIOLOGY (IB-BIO)', 'IB ENVR SYS & SOC (IBENVIRS)',
    'INDEP STUDY IN MATH (1ST TIME)', 'INDEP STUDY IN MATH (2ND TIME)',
    'INDPT STDY IN TECH APS 1ST TME', 'INDPT STDY IN TECH APS 2ND TME',
    'INTEGRATED PHYSICS/CHEMISTRY', 'MATHEMATICAL MODELS W/APPLCTN',
    'PHYSICS', 'PHYSICS (PHYSICS)', 'PRECALCULUS (PRE CALC)',
    'ROBOTICS PROGRAMMING & DESIGN') NEW_CODE=1.
    EXECUTE.

    ** Just rename new_code to whatever sensible name you want.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 11.  RE: Syntax Recoding

    Posted Mon November 07, 2022 01:33 PM
    If the criteria are presence of MATHEMATICS or SCIENCE, you could just do this.
    compute sci = sum(char.index(SERVICEX, "MATHEMATICS") + char.index(SERVICEX, "SCIENCE")) > 0.

    --