Announcement

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

  • make time interval from tick by tick data

    Hi!

    Our data is tick by tick data on a stock exchange index. However, for our analysis, we only need observations every 15 minutes, so we want to create a time interval of 15 minutes. The data has an inconsistent frequency, so it is not sure that it is a tick when the time show e.g. 09:00:00, 09:15:00, 09:30:00 or 09:45:00.

    We have tried to extract the value of the index every time the minutes are 00, 15, 30 and 45. This is the code we used

    gen intervall = value if mm(time)==00 | mm(time)==15 | mm(time)==30 | mm(time)==45 | hh(time)==17 & mm(time)==25 & ss(time)<20

    But due to the inconsistency, we can not be sure that we have in fact included variables every 15 minutes.

    How can we create this time interval for the index value?

    Attached is a photo of how our dataset looks like.

    Thank you!



    Click image for larger version

Name:	Index.PNG
Views:	1
Size:	7.9 KB
ID:	1326468

  • #2
    Welcome to Statalist Julie. Please consider using dataex next time to post your data example. This will make it easier for people to copy it and to create a working example based on your actual data. To install it, type in Stata's command window

    Code:
    ssc install dataex
    If you haven't done so already, please read the help file on Stata dates and time (help datetime). It's a difficult read but it's necessary to understand how to handle dates and time in Stata.

    Here's a quick example of how to create a variable that matches your stock data to a 15 minute interval.


    Code:
    clear
    set obs 2
    gen id = _n
    gen double time = clock("2010.04.13 09:00:00", "YMDhms")
    format %tc time
    expand 3600
    bysort id: replace time = time + msofseconds(_n-1)
    
    * create a 15 minutes time interval
    gen double time15 = floor(time / msofminutes(15)) * msofminutes(15)
    format %tc time15

    Comment


    • #3
      Thank you for the quick reply. Next time we will use dataex to post the example.

      The code for the 15 minute intervall worked great, thank you so much!

      Comment


      • #4
        Robert Picard i want to create a 3 yr 5 yr and 4yr time interval for my annual data that ranges from 1995 to 2022...how an i do that like i want to use my reg command over years 1995, 2000, 2004 and so on......skipping 3 years to create 3yr intervals...how can i do this

        Comment


        • #5
          #4 resembles https://www.statalist.org/forums/for...including-time

          Comment

          Working...
          X