Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • time spent on survey

    Hi there,

    Could I get some help in calculating time spent on the survey based on the following variables please?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(START_DATE FINISHED_DATE)
    2039257179999.9993  2039258084999.999
    2039257108999.9995 2039258135999.9988
         2039257127000 2039258178999.9995
     2039257169000.001      2039258197000
    2039257593999.9993 2039258222999.9998
    2039257218999.9988  2039258233000.001
    2039257217999.9993 2039258273000.0002
    2039257324000.0002 2039258278000.0007
    2039257635000.0007 2039258362000.0002
    2039257315000.0012 2039258427999.9993
    2039257548999.9993      2039258528000
    2039257552000.0007 2039258529999.9993
    2039257336000.0005 2039258544000.0012
     2039257583000.001 2039258573999.9995
    2039257160999.9993 2039258573999.9995
    2039257387000.0005 2039258585000.0002
     2039257564000.001 2039258636000.0002
     2039257568999.999 2039258699000.0005
    2039257729000.0012      2039258713000
    2039257333999.9988  2039258723000.001
    end
    format %tcnn/dd/ccYY_hh:MM START_DATE
    format %tcnn/dd/ccYY_hh:MM FINISHED_DATE

    Many thanks
    Karen

  • #2
    Code:
    gen time_spent_on_survey = clockdiff_frac(START_DATE, FINISHED_DATE, "m")
    format time_spent_on_survey %2.1f
    will give you the time spent in minutes, displayed to one decimal place. If you want more decimal places, change the -format- command accordingly. If you don't want fractions of a minute, just whole minutes, then instead of -clockdiff_frac()-, use -clockdiff()- with the same arguments.

    As an aside, I would not name those variables START_DATE and FINISHED_DATE because they are not actually dates. They are date-time variables. When you name them dates, you will be tempted, as you work with them, to try to manipulate them with code that is appropriate for date variables. And that will give you nonsensical results. I usually name variables like this start_time, or start_dt (short for datetime, which I use of the date is a relevant part of it), or start_tm so that I don't make that kind of mistake.

    Comment

    Working...
    X