Announcement

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

  • Time-series computing autocorrelation function

    Best Statalist community,

    I'm working with time-series data and I'm trying to compute autocorrelation function, variance and the spread of Pt - Pt-1. I defined the following model:

    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	1.1 KB
ID:	1471699

    Pt is the transaction price, Mt is the value of a firm, S is the spread, that is the difference between the ask and bid prices and Qt is 1 if the investor buys or -1 if the investor sells (with the same probability and uncorrelated over time). I use the 'close' as the transaction price.

    So my question is how can I compute the autocorrelation function, variance and spread of Pt - Pt-1 using the data below?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 date int time float(open high low close) long volume str9 ticker
    "09/15/2008"  930 33.31 33.31 33.31 33.31 2135 "zeus"
    "09/15/2008"  932 32.94 32.94 32.94 32.94  100 "zeus"
    "09/15/2008"  934 32.32 32.32 31.95 31.95  600 "zeus"
    "09/15/2008"  935 31.96 31.96 31.91 31.91  600 "zeus"
    "09/15/2008"  936 31.67 31.67 31.27 31.27 2380 "zeus"
    "09/15/2008"  937 31.27 31.27  30.4 30.44 1600 "zeus"
    "09/15/2008"  938 30.68 31.29 30.68 31.29 3200 "zeus"
    "09/15/2008"  939 31.17 31.23 31.03 31.08  700 "zeus"
    "09/15/2008"  941 31.35 31.78 31.14 31.46 1800 "zeus"
    "09/15/2008"  942 31.73 32.13 31.47 31.64 1100 "zeus"
    "09/15/2008"  943 31.65 31.66 31.48 31.49 2800 "zeus"
    "09/15/2008"  944  31.6 31.81 31.51 31.65 1900 "zeus"
    "09/15/2008"  945 31.68 31.68 31.68 31.68  200 "zeus"
    "09/15/2008"  946 31.71  31.8 31.68 31.77  700 "zeus"
    "09/15/2008"  947    32 32.14    32    32  600 "zeus"
    "09/15/2008"  948 32.04 32.06 32.04 32.06  200 "zeus"
    "09/15/2008"  949 32.06 32.18 32.01 32.18  700 "zeus"
    "09/15/2008"  950 32.17 32.18 32.06 32.18 2600 "zeus"
    "09/15/2008"  951 32.15 32.15 31.92    32 5976 "zeus"
    "09/15/2008"  952 32.06 32.11 31.63 31.63 3900 "zeus"
    "09/15/2008"  953 31.92 32.12 31.89 32.01 4100 "zeus"
    "09/15/2008"  954 32.01 32.03 31.92 31.99 3200 "zeus"
    "09/15/2008"  955 32.01 32.02 31.98 32.01 1500 "zeus"
    "09/15/2008"  956 31.99 32.14 31.99 32.14 1300 "zeus"
    "09/15/2008"  957 32.11 32.11 32.01 32.01  400 "zeus"
    "09/15/2008"  958 32.02 32.04 32.01 32.01 1200 "zeus"
    "09/15/2008"  959 32.03 32.11 31.98 32.11 1586 "zeus"
    "09/15/2008" 1000 32.06 32.16 32.06 32.11  300 "zeus"
    "09/15/2008" 1001 32.02 32.02 32.02 32.02  260 "zeus"
    "09/15/2008" 1002 32.01 32.01 31.92 31.92 5400 "zeus"
    "09/15/2008" 1003 31.92 32.08 31.89    32  800 "zeus"
    "09/15/2008" 1004 32.02 32.02 32.02 32.02  100 "zeus"
    "09/15/2008" 1005 31.92 32.04 31.82 31.94 3100 "zeus"
    "09/15/2008" 1006 31.94 32.04 31.94 32.04  400 "zeus"
    "09/15/2008" 1007 31.99 31.99 31.53 31.53 1300 "zeus"
    "09/15/2008" 1008 31.51 31.51 31.39  31.4 1100 "zeus"
    "09/15/2008" 1009 31.39  31.5 31.14 31.35 3200 "zeus"
    "09/15/2008" 1010 31.48 31.51 31.03 31.15 2000 "zeus"
    Kind regards,

    Johnson

  • #2
    Welcome to Statalist.

    Let me start by pointing out that your data does not represent date and time correctly. Your date is a string variable, and your time is a number that is not a suitable representation of hours and minutes - since the gap between 9:59 represented as 959 and 10:00 represented as 1000 is 41 minutes rather than 1 minute. So to start with, you have to better understand how Stata represents dates and times.

    Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

    All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

    But once that is done, your problem remains unclear. You tell us that your variable close corresponds to the transaction price Pt, but what tells us the value of the firm Mt, what tells us the bid and asked prices to compute the spread S, and what tells us if the investor bought or sold to compute Qt?

    Comment

    Working...
    X