SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  compute variable

    Posted Mon October 24, 2022 10:37 AM
    Hello,
    SPSS and I talk different language. However, I hope I will learn.

    My challenge is control of workplace when the same person answers 2 or more workplaces. Workplaces A, B and C. or A, B and C and D etc. 
    In my analysis I need:
    Workplace A AND/OR Workplace B = new variable AB.  Workplace C AND/OR workplace D = new variable CD and E AND/OR F = new variabel, EF. 

    Therefore, I need to exclude the answers when someone has answer ex. A and D or B and F.
    (Workplace A=1 | Workplace B= 1) Workplace AB=1.
    (Workplace A = 1 | workplace B = 1 AND Workplace C=1 OR D =1 OR F =1) Workplace AB =0.

    I have tried a lot of different way, with no success, they are still included. 
    In addition, if it is possible to do, I need transform one variable when the answers are mixed ex. A and E or B and C = new variable Mixed.

    The goal is one new variable: Workplace
    Transform AB, CD, EF and (if it is possible; a variable "mixed") to one new variable Workplace.

    IF (Workplace AB= 1) Workplace =1.
    IF (Workplace CD = 1) Workplace =2.
    IF (Workplace EF= 1) Workplace =3.
    IF (Workplace mixed=1) Workplace =4.
    EXECUTE.

    All advice is gratefully received.
    Carina

    ------------------------------
    Carina Ahlstedt
    ------------------------------

    #SPSSStatistics


  • 2.  RE: compute variable

    Posted Mon October 24, 2022 11:05 AM
    Edited by System Admin Fri January 20, 2023 04:23 PM
    Hi.

    You could try something like this. It may not be elegant, but I think it does what you want. I have made up my own data - a through f, each a different workplace, each coded 1 or 0. (They could just as easily be 1 or system-missing.)

    data list free/a b c d e f.
    begin data.
    1 0 0 0 0 0
    0 1 0 0 0 0
    0 0 1 0 0 0
    0 0 0 1 0 0
    0 0 0 0 1 0
    0 0 0 0 0 1
    1 0 1 0 1 0
    1 1 1 0 0 0
    0 0 1 0 0 1
    end data.

    compute workplace=0.
    if sum.1(a,b)>0 workplace=1.
    if sum.1(c,d)>0 workplace=2.
    if sum.1(e,f)>0 workplace=3.

    if workplace=1 and sum.1(c,d,e,f)>0 workplace=4.
    if workplace=2 and sum.1(a,b,e,f)>0 workplace=4.
    if workplace=3 and sum.1(a,b,c,d)>0 workplace=4.
    execute.

    The SUM function look for at least valid value (that's why they could be 0 or system-missing).



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



  • 3.  RE: compute variable

    Posted Mon October 24, 2022 11:09 AM
    Note edited original to correct typo in variable name.

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