When you have high-frequency data, you cannot use Excel to visualize the data due to the high number of observations. On the follwing, we will see that importing high-frequency data into a Jupyter Notebook using Stata allows you to visualize the data without the line limit of Excel.

In [1]:
import stata_setup
stata_setup.config('C:\Program Files\Stata18/', 'se')
  ___  ____  ____  ____  ____ ®
 /__    /   ____/   /   ____/      18.0
___/   /   /___/   /   /___/       SE—Standard Edition

 Statistics and Data Science       Copyright 1985-2023 StataCorp LLC
                                   StataCorp
                                   4905 Lakeway Drive
                                   College Station, Texas 77845 USA
                                   800-STATA-PC        https://www.stata.com
                                   979-696-4600        stata@stata.com

Stata license: Single-user  perpetual
Serial number: 401806202105
  Licensed to: Jamel Saadaoui
               University of Strasbourg

Notes:
      1. Unicode is supported; see help unicode_advice.
      2. Maximum number of variables is set to 5,000 but can be increased;
          see help set_maxvar.
In [2]:
%%stata

*set scheme stcolor

cd "C:\Users\jamel\OneDrive\PROJECTS\22-11-hfd-causality"
cd "OneDrive_2022-11-05\Gazi and HFD\HFD-commodities\Project 1_Energy"

**# CL (Crude Oil WTI) Continuous futures

import delimited CL_continuous_adjusted_5min.txt, clear

rename v1 DateTime
rename v2 Open
rename v3 High
rename v4 Low 
rename v5 Close
rename v6 Volume
. 
. set scheme stcolor

. 
. cd "C:\Users\jamel\OneDrive\PROJECTS\22-11-hfd-causality"
C:\Users\jamel\OneDrive\PROJECTS\22-11-hfd-causality

. cd "OneDrive_2022-11-05\Gazi and HFD\HFD-commodities\Project 1_Energy"
C:\Users\jamel\OneDrive\PROJECTS\22-11-hfd-causality\OneDrive_2022-11-05\Gazi a
> nd HFD\HFD-commodities\Project 1_Energy

. 
. **# CL (Crude Oil WTI) Continuous futures
. 
. import delimited CL_continuous_adjusted_5min.txt, clear
(encoding automatically selected: UTF-8)
(6 vars, 1,094,456 obs)

. 
. rename v1 DateTime

. rename v2 Open

. rename v3 High

. rename v4 Low 

. rename v5 Close

. rename v6 Volume

. 
In [3]:
%%stata

gen double date = clock(DateTime, "YMDhms") 

gen double date2 = clock(DateTime, "YMDhms") 

format %100.0g date2

format %tc date

tsset date
. 
. gen double date = clock(DateTime, "YMDhms") 

. 
. gen double date2 = clock(DateTime, "YMDhms") 

. 
. format %100.0g date2

. 
. format %tc date

. 
. tsset date

Time variable: date, 19sep2006 03:45:00 to 27may2022 16:55:00, but with gaps
        Delta: .001 seconds

. 

Because %tc values can be so large, whenever you use the function clock(), you must store the results in a double, as we do below: https://www.stata.com/manuals13/u24.pdf

In [5]:
%%stata
tsline Close, ///
 title("CL (Crude Oil WTI) Continuous futures") ///
 ylabel(, angle(vertical)) tlabel(, grid) xsize(9) ///
 xlabel(1501646400000(116910750000)1969289400000, ///
 labsize(small) angle(horizontal)) graphregion(margin(l+10 r+15))
. tsline Close, ///
>  title("CL (Crude Oil WTI) Continuous futures") ///
>  ylabel(, angle(vertical)) tlabel(, grid) xsize(9) ///
>  xlabel(1501646400000(116910750000)1969289400000, ///
>  labsize(small) angle(horizontal)) graphregion(margin(l+10 r+15))

. 
Stata Graph - Graph 0 50 100 150 Close 02aug2007 04:00:00 16apr2011 07:12:30 29dec2014 10:25:00 12sep2018 13:37:30 27may2022 16:50:00 date CL (Crude Oil WTI) Continuous futures

More details about the margins in the plot: https://www.stata.com/manuals13/g-3region_options.pdf#g-3region_options

In [6]:
%%stata
graph export CL_continuous_adjusted_5min.png, width(4000) replace
file CL_continuous_adjusted_5min.png written in PNG format
In [7]:
%%stata
graph export CL_continuous_adjusted_5min.pdf, replace
file CL_continuous_adjusted_5min.pdf saved as PDF format
In [8]:
%%stata
save CL_continuous_adjusted_5min.dta, replace
file CL_continuous_adjusted_5min.dta saved
In [9]:
%%stata
describe
Contains data from CL_continuous_adjusted_5min.dta
 Observations:     1,094,456                  
    Variables:             8                  3 Jun 2023 11:53
-------------------------------------------------------------------------------
Variable      Storage   Display    Value
    name         type    format    label      Variable label
-------------------------------------------------------------------------------
DateTime        str19   %19s                  
Open            float   %9.0g                 
High            float   %9.0g                 
Low             float   %9.0g                 
Close           float   %9.0g                 
Volume          long    %8.0g                 
date            double  %tc                   
date2           double  %100.0g               
-------------------------------------------------------------------------------
Sorted by: date
In [10]:
%%stata
summarize Open High Low Close Volume 
    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        Open |  1,094,456    68.82908    23.23244       3.81     144.31
        High |  1,094,456    68.88346    23.24053       6.57      144.5
         Low |  1,094,456    68.77417    23.22415       3.73     144.08
       Close |  1,094,456    68.82897    23.23247       4.13     144.29
      Volume |  1,094,456    1074.181    1947.485          1     228211
In [11]:
%%stata
histogram Volume
(bin=60, start=1, width=3803.5)
Stata Graph - Graph 0 5.0e-05 1.0e-04 1.5e-04 2.0e-04 2.5e-04 Density 0 50000 100000 150000 200000 250000 Volume
In [12]:
%%stata
histogram Open
(bin=60, start=3.8099999, width=2.3416666)
Stata Graph - Graph 0 .005 .01 .015 .02 Density 0 50 100 150 Open
In [13]:
%%stata
histogram Close
(bin=60, start=4.1300001, width=2.3359999)
Stata Graph - Graph 0 .005 .01 .015 .02 Density 0 50 100 150 Close