Announcement

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

  • Creating a timestamp beginning at 0 for each participant (eye tracking data)

    Hi all,

    I've been struggling to find a quick solution for this for a couple of days now so I'm allowing myself to post here to ask for advice!

    I have eye-tracking data with about 2800 observations per participant (where each line/observation is gaze data collected from the eye-tracker roughly 17ms apart in time). The eye-tracker software exports a variable called RecordingTimestamp and this has a different (& arbitrary) counter for each participant and I need them to have the same reference counter for all. My idea was to create a new timestamp starting at 0 for each participant that counts up until the end of that participant's observations.

    What seemed most intuitive was this:

    generate Timestamp = sum(RecordingTimestamp - RecordingTimestamp[_n-1])

    and interestingly it does create a timestamp that seems to recognise where one participant ends and another begins, only it does not start at 0 each time. Otherwise, I don't know how to make this command respect the change in participant (by sort?) and start at 0. Any help much appreciated!
    Exp2.png



  • #2
    I think what you want is:

    Code:
    by Participant (RecordingTimestamp), sort: gen Timestamp = ///
        RecordingTimestamp - RecordingTimestamp[1]
    Note: Replace "Participant" by the actual name of your first variable.

    Let me also point out that your attempt, even if done with a -by:- prefix , it would have given you the interval of time elapsed between observations, not a running total of elapsed time, which is what the code shown here does.

    As this solution did not occur to you, I'm going to speculate that you are a new Stata user. The use of -by- is one of the basic skills that every Stata user needs to have in his or her toolkit. I suggest that you step back from any projects you are working on and invest some time in reading the User's Guide [U] and Getting Started [GS] volumes of the PDF documentation that comes with your Stata installation. It's a lot of reading, but it will show you the "bread and butter" Stata commands that play a role in nearly all aspects of Stata data management and analysis. You won't remember all the details, but you will learn enough that in most situations you will have a good sense of what commands are likely to play a role in solving your problem. Then you can refer back to the help files or the specific manual chapters for those commands to fill in the fine points. This investment of time will be amply repaid with greater efficiency in short order if you are using Stata regularly.

    Please note that showing data examples by screenshots is strongly discouraged here. There are several reasons. First, although this one happens to be readable on my computer, they are often unreadable on many setups. Second, they do not contain any metadata. Third, as here, they do not show the complete names of variables that have long names (so I hadto guess that your first variable name is Participant--but given that it apparently ends in e, I don't really know what it might be.) Third, if this were complicated enough to require testing out the solution code on some example data, there is no way to import data from a screenshot into Stata. So please do not use screenshots in the future.

    Rather, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it 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


    • #3
      Thanks so much, Clyde. That worked perfectly. Yes, I am a new user so thanks for the thoughtful and helpful response.

      Comment

      Working...
      X