Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:18:22+00:00 2026-06-17T09:18:22+00:00

I got high frequency data from a limit order book in Stata. Time does

  • 0

I got high frequency data from a limit order book in Stata. Time does not have a regular interval, and some observations are at the same time (in milliseconds). For each observation I need to get the midpoint 5 minutes later in a separate column. So for observation 1 the midpoint would be 10.49, because the last midpoint closest to 09:05:02.579 would be 10.49.

How to do this in Stata?

datetime                         midpoint
12/02/2012 09:00:02.579          10.5125
12/02/2012 09:00:03.471          10.5125
12/02/2012 09:00:03.471          10.5125
12/02/2012 09:00:03.471          10.51
12/02/2012 09:00:03.471          10.51
12/02/2012 09:00:03.549          10.505
12/02/2012 09:00:03.549          10.5075
   ......
12/02/2012 09:04:59.785          10.495
12/02/2012 09:05:00.829          10.4925
12/02/2012 09:05:01.209          10.49
12/02/2012 09:05:03.057          10.4875
12/02/2012 09:05:05.055          10.485
 .....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:18:22+00:00Added an answer on June 17, 2026 at 9:18 am

    My approach would be

    1. generate a new data set shifted by five minutes
    2. append this shifter data set
    3. find closest before and after observations to your five minute delta
    4. use some criteria to pick the better of these two values

    You specified closest, but you might want to add some other criteria depending on your book. Also, you mentioned more than one value at a given ms tick, but without more information I’m not sure how to handle that. Do you want to combine those midpoints first? Or are they different stocks?

    Here’s some code that implements the basics of the approach above.

    clear
    version 11.2
    set seed 2001
    
    * generate some data
    set obs 100000
    generate double dt = ///
        tc(02dec2012 09:00:00.000) + 1000*_n + int(100*rnormal())
    format dt %tcDDmonCCYY_HH:MM:SS.sss
    sort dt
    generate midpt = 100
    replace midpt = ///
        round(midpt[_n - 1] + 0.1*rnormal(), 0.005) if (_n != 1)
    
    * add back future midpts
    preserve
    tempfile future
    rename midpt fmidpt
    rename dt fdt
    generate double dt = fdt - tc(00:05:00.000)
    save `future'
    restore
    append using `future'
    
    * generate midpoints before and after 5 minutes in the future
    sort dt
    foreach v of varlist fdt fmidpt {
        clonevar `v'_b = `v'
        replace `v'_b = `v'_b[_n - 1] if missing(`v'_b)
    }
    
    gsort -dt
    foreach v of varlist fdt fmidpt {
        clonevar `v'_a = `v'
        replace `v'_a = `v'_a[_n - 1] if missing(`v'_a)
    }
    
    format fdt* %tcDDmonCCYY_HH:MM:SS.sss
    
    * use some algorithm to pick correct value
    sort dt    
    generate choose_b = ///
        ((dt + tc(00:05:00.000)) - fdt_b) < (fdt_a - (dt + tc(00:05:00.000))) 
    generate fdt_c = cond(choose_b, fdt_b, fdt_a)
    generate fmidpt_c = cond(choose_b, fmidpt_b, fmidpt_a)
    format fdt_c %tcDDmonCCYY_HH:MM:SS.sss
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Python program that does time-consuming computations. Since it uses high CPU,
I got a few examples from TTR documentation like: data(ttrc) mfi <- MFI(ttrc[,c(High,Low,Close)], ttrc[,Volume])
I've got a fairly simple situation: I have a high speed producer of data
I've got an application that goes into high CPU usage (slowly over time) when
My problem: i have many servers do caching data from key-value database. These caching
I've got a root UserControl that is 300 high. Inside that I have a
i've got a hundred pages long high quality PDF (66MB) that needs to be
The high level problem we're having is this. We've got Apache Wave installed and
Got a seg fault from my memcpy that gdb can't give me anything else
my C# application reads data from special USB device. The data are read as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.