SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  Cumulative frequency of dates

    Posted Thu April 28, 2022 08:58 AM
    Hi there,

    I am very new to SPSS. I have tried to find an answer online with no luck. I suspect it is because I am not using the correct terms for my queries.

    I am wanting to graphically represent the number of complete and incomplete survey responses over time. The survey data has been successfully imported from LimeSurvey. I have calculated a cumulative tally of the complete and incomplete survey responses into two new variables. What I am struggling to do is create a variable for the time (X) axis.

    For example, two respondents completed the survey on the 16th and 7 respondents on the 17th. I am somehow wanting each date to be counted once, regardless of the number of responses received for each day. So I can then graph 2 completions on day 1 and 7 completions on day 2 etc. and do the same (on the same graph) with the total of each incomplete survey response for each day to see whether certain interventions have improved the completion rate.

    I appreciate any help or advice you can provide.

    Kind Regards

    Aaron

    ------------------------------
    Aaron Timoshanko
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Cumulative frequency of dates

    Posted Thu April 28, 2022 09:24 AM
    If what you are looking for is a transformation that extracts the number of days since the start date, you can use the DATEDIFF function.  If the start date is, for example,1,1,2022, you could write
    compute days = datediff(thedate, yrmoda(2022,1,1), 'days').
    where thedate is a date variable recording the end date.

    --





  • 3.  RE: Cumulative frequency of dates

    Posted Fri April 29, 2022 07:45 AM
    Hi,
    If your dates are in date format I would for each interview create a variable that is 1 if completed, 0 if not, and a similar variable for each of the other statuses.
    If it is not a date variable you will have to convert it to a date first or days since the start as Jon suggests.
    Then I would aggregate to count the response types for each day, and finally, compute a cumulative i.e.

    compute completed=0.
    if (responsestatus=1) completed=1.
    compute incomplete=0.
    if responsestatus=2 incomplete=1.
    dataset declare respaggregate.
    aggregate outfile=respaggregate
    /break interviewdate
    /complete=sum(completed)
    /incomplete=sum(incomplete)
    /totalinterviews=N(responsestatus).
    * Then do cumulative.
    dataset activate respaggregate.
    numeric cumcomplete cumincomplete cumtotal (F4.0).
    do repeat daily=complete incomplete totalinterviews
    /cumulative=cumcomplete cumincomplete cumtotal.
    compute cumulative=0.
    do if missing(lag(cumulative)).
    compute cumulative=daily.
    else.
    compute cumulative=daily+lag(cumulative).
    end if.
    end repeat.
    exe.

    Hope this is what you asked.
    best
    Jon

    ------------------------------
    Jon Pedersen
    ------------------------------



  • 4.  RE: Cumulative frequency of dates

    Posted Sun May 01, 2022 12:51 AM
    Edited by System Admin Fri January 20, 2023 04:21 PM
    Thank you @Jon Pedersen for your reply and assistance.

    I ran your syntax changing a few of the variable names (see attached) and it mostly worked. However, the cumulative total for each day did not work. Was that another variable name I should have changed?

    This is how I changed your syntax:

    compute completed=0.
    if (Completion=1) completed=1.
    compute incomplete=0.
    if (Completion=2) incomplete=1.
    dataset declare respaggregate.
    aggregate outfile=respaggregate
    /break startdate
    /complete=sum(completed)
    /incomplete=sum(incomplete)
    /totalinterviews=N(Completion).
    * Then do cumulative.
    dataset activate respaggregate.
    numeric cumcomplete cumincomplete cumtotal (F4.0).
    do repeat daily=complete incomplete totalinterviews
    /cumulative=cumcomplete cumincomplete cumtotal.
    compute cumulative=0.
    do if missing(lag(cumulative)).
    compute cumulative=daily.
    else.
    compute cumulative=daily+lag(cumulative).
    end if.
    end repeat.
    exe.


    Thank you again for your help.

    Aaron

    ------------------------------
    Aaron Timoshanko
    ------------------------------



  • 5.  RE: Cumulative frequency of dates

    Posted Sun May 01, 2022 04:58 AM

     

    Hi,

    Did yo get any error messages? If not, then it seems that the dates have a hidden time part, so that each date/time becomes a separate line even after the aggregation.

    You can fix that by

     

    Numeric newstartdate (EDATE10).

    Compute newstartdate=trunc(startdate,86400)

    And then using newstartdate in the place of startdate.

     

    86400 is the number of seconds in a day, in case you wonder.

     

    jon






  • 6.  RE: Cumulative frequency of dates

    Posted Tue May 03, 2022 01:06 AM
    Hi Jon,

    Thank you for your continued help.

    No error message but I had changed the date format to dd/mm/yyyy, which excluded/hid the times for each particular response.

    I ran the syntax you provided but the newstartdate just displays missing data ('.')

    I also tried running the original syntax after reverting to the original date form and the same issue occurred (i.e. the number of completes or incomplete for each specific date were not calculated).

    Thank you for your patience.

    Kind Regards

    Aaron

    ------------------------------
    Aaron Timoshanko
    ------------------------------



  • 7.  RE: Cumulative frequency of dates

    Posted Tue May 03, 2022 08:34 AM
    Two Jon's on this thread!.  I would need to see the data to go any further with this.

    --





  • 8.  RE: Cumulative frequency of dates

    Posted Tue May 03, 2022 08:49 AM

    Hi,

    The only thing I can think of is that there may be a missing dot after the compute command.

    I could take a look at the data, just send the response and date variable should be ok.

     But the code should be (I think).

     

    Numeric newstartdate (EDATE10).

    Compute newstartdate=trunc(startdate,86400).

    compute completed=0.
    if (Completion=1) completed=1.
    compute incomplete=0.
    if (Completion=2) incomplete=1.
    dataset declare respaggregate.
    aggregate outfile=respaggregate
    /break newstartdate
    /complete=sum(completed)
    /incomplete=sum(incomplete)
    /totalinterviews=N(Completion).
    * Then do cumulative.
    dataset activate respaggregate.
    numeric cumcomplete cumincomplete cumtotal (F4.0).
    do repeat daily=complete incomplete totalinterviews
    /cumulative=cumcomplete cumincomplete cumtotal.
    compute cumulative=0.
    do if missing(lag(cumulative)).
    compute cumulative=daily.
    else.
    compute cumulative=daily+lag(cumulative).
    end if.
    end repeat.
    exe.

     






  • 9.  RE: Cumulative frequency of dates

    Posted Sun May 01, 2022 12:58 AM
    Edited by System Admin Fri January 20, 2023 04:31 PM
    Hi @Jon Peck

    Thank you for your suggestion.

    I changed thedate to startdate but the days variable created just has displays missing data i.e. '.'

    Should the thedate variable just state/repeat the end date of the survey?

    Apologies if this is a silly question.

    Much appreciated.

    Kind Regards

    Aaron

    ------------------------------
    Aaron Timoshanko
    ------------------------------