SPSS Statistics

 View Only
Expand all | Collapse all

Creating a new variable from two existing one

  • 1.  Creating a new variable from two existing one

    Posted Fri July 15, 2022 10:19 AM
    Hi and thanks for any help you can provide.

    I have two variables, one is religion, 1=None, 2=Catholic, 3=Protestant, 4=other. The other is practicing catholic, with 1=practicing, 2=non-practicing.

    I want a variable affiliation that includes all the possibilities - none, practicing Catholic, non-practicing Catholic, Protestant, and other. 

    I have been trying to figure out how to do this with compute and if statements but without success. It has been a long time since I did this in grad school!

    Pat

    ------------------------------
    Pat Christian
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Creating a new variable from two existing one

    Posted Fri July 15, 2022 11:08 AM
    Hi, Pat.

    I think a random binary summation kind of thing will do it.

    *Example data.
    data list free /religion practicing.
    begin data.
    2 1
    3 2
    4 1
    2 2
    4 2
    3 1
    1 2
    end data.
    
    * religion: 1=None, 2=Catholic, 3=Protestant, 4=other.
    * practicing: 1=No, 2=Yes.
    
    compute a=religion**(religion-1).
    if practicing=2 & religion>1 a=a+1.
    autorecode a /into affiliation.
    delete variables a.
    
    ** Affiliation 1=None, 2=Non-practicing Catholic,
    ** 3=Practicing Catholic, 4=Non-Practicing Protestant,
    ** 5=Practicing Protestant,6=Non-Practicing Other,
    ** 7=Practicing Other.
    
    value labels affiliation
    1 "None"
    2 "Non-practicing Catholic"
    3 "Practicing Catholic"
    4 "Non-Practicing Protestant"
    5 "Practicing Protestant"
    6 "Non-Practicing Other"
    7 "Practicing Other".
    
    summarize religion practicing affiliation /format list nototals nocasenum
    /cells none /statistics none.​

    PS. If I count, I'm a 3.  :^)

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