SPSS Statistics

 View Only
  • 1.  Syntax format for sum for particular codes

    Posted 24 days ago

    Hi everyone,

    I'm having trouble finding a syntax for this - I'm trying to calculate sums for each particular category of usetype (0 = no use ,1 = both drugs used, 2 = alcohol use only, 3=cannabis use only) for each day of 14 days (D14_UseType, D13_UseType ... D2_UseType, D1_UseType)

    These use types are based on syntax I have made: (an example for D1 below)

    DO IF (DAY1ALC>=1) AND (DAY1CAN>=0.125).
        RECODE D1_UseType (SYSMIS=1).
    END IF.
    EXECUTE.
     
    DO IF (DAY1ALC>=1) AND (DAY1CAN=0).
        RECODE D1_UseType (SYSMIS=2).
    END IF.
    EXECUTE.
     
    DO IF (DAY1ALC=0) AND (DAY1CAN=0).
        RECODE D1_UseType (SYSMIS=0).
    END IF.
    EXECUTE.
     
    DO IF (DAY1ALC=0) AND (DAY1CAN>=0.125).
        RECODE D1_UseType (SYSMIS=3).
    END IF.
    EXECUTE.

    I now am trying to calculate the 4 types of sums (1. sum of alcoholic drinks on alcohol only days, 2. sum of grams of cannabis use on cannabis only days, 3. sum of alcoholic drinks on both use days, 4. sum of cannabis grams on both use days) of all 14 days for each use type to calculate quantity 

    Therefore for example if for a particular case D1_UseType, D3_UseType, and D9_UseType is coded as 2 (alcohol only days), sum DAY1ALC, DAY3ALC, and DAY9ALC 

    So my main question is how would I do syntax for each type of sum I need. Thanks!



    ------------------------------
    Toni-Rose Asuncion
    ------------------------------


  • 2.  RE: Syntax format for sum for particular codes

    Posted 24 days ago

    i wouldn't use DO IF here.  if day1alc>=1 & day1can>=.125 d1_usetype=1.

    aggregate outfile=* /break d1_usetype/ number=n.



    ------------------------------
    Art Jack
    ------------------------------



  • 3.  RE: Syntax format for sum for particular codes

    Posted 24 days ago

    Thank you for the feedback on the syntax! From here, my main question is how can I use these variables (the use type variables) to calculate the 4 sums I need. I added a better explanation below: 

    1. So I started off with a data set 28 variables from a 14 day survey - (14 days of cannabis, 14 days of alcohol). Respondents specified how much of each substance they used.

    Day14Can, Day13Can, Day12Can .... Day3Can, Day2Can, Day1Can

    Day14Alc, Day13Alc .... Day2Alc, Day1Alc.

    2. From here I wanted to create a variable that tells me how they used substances in a particular day (Day#_UseType). Each category of use included no-use, both use, alcohol only, cannabis only(this was computed using the above syntax which seemed to work).

    Day14_Type, Day13_Type .... Day2_Type, Day1_Type

    3. NOW my difficulty is calculating sums for each category (see original post) for each participant. I was trying to find a syntax that will allow me to only count the sum on Day14Can if they were

    For example if a participant had the following pattern for the 14 days BASED on the original 28 variables:

    Day 14 - 5 alcoholic drinks, 0 grams (thus Day14_Type would be 2 - which mean alcohol only)

    Day 13 - 1 alcoholic drink, 0.5 grams of cannabis (thus Day 13_Type would be 1 - which means both use on this day)

    Day 12 - 0 alcoholic drinks, 1 gram of cannabis (thus Day12_Type would be 3 - which means cannabis only)

    Day 11- 0 alcoholic drinks or grams (thus Day11_Type would be 0 - no use)

    Day 10 - 9 drinks, 1 g (Day10_Type would be both use days)

    for the rest of the days (imagine they used 0 drinks and 0 cannabis for the remainder)

    The sum categories for this person would be :

    ALCOHOL ON ALCOHOL ONLY DAYS - 5 drinks

    CANNABIS ON CANNABIS ONLY DAYS - 1 gram

    ALCOHOL ON BOTH USE DAYS - 10 drinks

    CANNABIS SUM ON BOTH USE DAYS - 1.5 grams

    I wanted to know if theres a way (specifically syntax) i can use the variables I made in point 2 to calculate the sums from point 1 for each sum category I need instead of doing it by hand like i just did.

    I've been trying to combine if statements, else statements and compute statements and it hasn't worked. And I have a pretty big sample so automating this through syntax would be VERY helpful



    ------------------------------
    Toni-Rose Asuncion
    ------------------------------



  • 4.  RE: Syntax format for sum for particular codes

    Posted 24 days ago

    If you need to calculate sums from column to column use the sum function, or count (needs to be string).   if they are all in the same column use the aggregate function.  

    compute alc_sum=sum(alc1 to alc15).  

    count alc=alc1 to alc15 ('4').

    aggregate outfile=* /break d1_usetype/ number=n.



    ------------------------------
    Art Jack
    ------------------------------



  • 5.  RE: Syntax format for sum for particular codes

    Posted 24 days ago
    Edited by Toni-Rose Asuncion 24 days ago

    It's a bit more complicated than that because each participant will have a different pattern of how they used substances (it is column to column though).

    For example participant A has the following pattern:

    Alcohol (day 14 to day 1): 0, 0, 4, 0, 1, 2, 0, 5, 1, 2, 0, 1, 2, 0 

    Cannabis (day 14 to day 1): 1, 0.25, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.125, 0

    - I have to split these totals up into 4 sums (alcohol on alcohol only days, alcohol on both use days, etc).

    Participant B has this pattern:

    Alcohol: 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 1, 0

    Cannabis: 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0.25, 0

    If I use that syntax it would not differentiate between alcohol on alcohol only days vs alcohol on both use days (hence why in my second point I attempted to code for type in order).

    Is there anyway I can use the DayTypes to tell SPSS to only sum up the relevant information for the appropriate sum:

    e.g., if Day14_Type was coded 1 as a both use day, it will then provide add this value in the Day14Alc for that participant into the sum for alcohol on both use days variable (and if they had the same code for Day 2 and 5 - the same values for Day2Alc and Day5Alc would also go into the sum) AND Day14Can sum into the cannabis on both use days variable. Thanks!



    ------------------------------
    Toni-Rose Asuncion
    ------------------------------



  • 6.  RE: Syntax format for sum for particular codes

    Posted 24 days ago

    Look at Do Repeat with a nested do if or a vector & loop. 



    ------------------------------
    Art Jack
    ------------------------------



  • 7.  RE: Syntax format for sum for particular codes

    Posted 23 days ago

    Thank you so much! I'll look into that!



    ------------------------------
    Toni-Rose Asuncion
    ------------------------------