Announcement

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

  • Reporting summary statistics for time variable (e.g., number of minutes)

    I'd like to report the summary statistics for a time variable.

    I ran an experiment and I have the number of seconds that it took each participant to complete the study. I want to report the average amount of time it took them to complete the study (in minutes) as part of a summary stats table.

    I've converted the seconds to minutes by multiplying it by 60 and I've converted the minutes to a time format:

    Code:
    gen Minutes = string(60e3 * Durationinminutes, "%tcMM:SS")
    This does a nice job of
    However, I can't report it in the summary states table. I've tried encoding the variable, but this produces the wrong results.

    Any guidance would be greatly appreciated. I haven't been able to find the solution to this online.

  • #2
    I've converted the seconds to minutes by multiplying it by 60 and I've converted the minutes to a time format:

    Code:
    gen Minutes = string(60e3 * Durationinminutes, "%tcMM:SS")
    You are contradicting yourself here, so I'm confused what you are actually doing. First, to convert seconds to minutes, you have to divide by 60. Second, your code looks like it actually starts with minutes and converts that to milliseconds (except that you forgot to force Minutes to be a double precision variable), and then converts that to a string with a %tc format.

    You also state that you want to report the average amount of time it took: but converting to a string variable is counterproductive: you can't do calculations with a string variable. You have to first calculate the average from the numeric variable you have (whatever that is) and then, if it isn't in minutes, convert it to minutes.

    Finally you don't show what code you used to try to put the result in the summary stats table. If you are running version 17 and used the -table- command, then you are encountering a limitation that others have already noted (see https://www.statalist.org/forums/for...o-version-17): the -table- command does not currently allow string variables. But maybe you did something else, and, since you don't say what happened other than the results were "wrong" (which could mean infinitely many different things) it doesn't seem possible to give advice at this time.

    Encoding a time-formatted string variable would never, in any circumstance I can imagine, produce a useful result for any purpose.

    For more specific guidance, please post back with the actual code used for all steps in this process along with the results (including any error messages) you got from Stata. Also, if it isn't blatantly obvious, explain in what sense the results differ from what you are looking for. It might also be helpful to use the -dataex- command to show some example data. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X