Here is a reproducible example produced by `dataex`
These are the contents of my `do` file which shows you my effort:
You can ignore the first line, that shows how I imported my file, since you may not have the csv and you can use the `dataex` example that I gave you.
The output of my efforts is this:
1. My issue with this output is that NONE of the X-axis HH:MM:SS portion of date tick labels exist in my csv file at all! The column in my date that represents the date has the 3 patterns `"MM/DD/YYYY 07:59:00"`, `"MM/DD/YYYY 16:00:00"`, `"MM/DD/YYYY 23:59:00"`.. But my graph output has these HH:MM:SS postions of the date in axis labels that are NOT PRESENT in the dataset. ALL of the HH:MM:SS portions that you see in the X-axis labels like `05:46:40`, `00:40:00`, `19:33:20` etc do not exist in my data! If at all possible, **I would like to display 12 specific dates with `"MM/DD/YYYY 07:59:00"`, `"MM/DD/YYYY 16:00:00"`, `"MM/DD/YYYY 23:59:00"` pattern FROM my csv**, instead of Stata taking it upon itself to look at the relative position and accordingly setting a HH:MM:SS on the X axis label..
2. I would like to add 4 reference lines at 4 of those specific X-axis date points, with a custom text marker on top. The issue I'm having with this is, I cannot seem to understand how to pick the positions in X axis as they are all datetime values and how I add multiple reference lines with a text marker at a specific Y coordinate..
3. Set a smaller legend inside the graph instead of outside
I would like my output to be something like the one below.
Forigve my terrible MS Paint Skills
[1]: https://i.stack.imgur.com/npUIP.jpg
[2]: https://i.stack.imgur.com/lZkrg.jpg
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str23 eventname str10(eventdate scrapedate) byte pricepart float(thpercentile median v7 mean) str5 timestamp str19 datetime "Home Team vs. Away Team" "2016-01-03" "2015-12-04" 1 117.02 153.635 215.135 178.74034 "07:59" "2015-12-04 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-04" 2 117.02 153.635 215.135 178.74034 "16:00" "2015-12-04 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-04" 3 117.02 153.635 215.135 178.74034 "23:59" "2015-12-04 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-05" 1 117.02 153.635 215.135 178.64935 "07:59" "2015-12-05 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-05" 2 110.335 150.62 210.775 175.1715 "16:00" "2015-12-05 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-05" 3 . . . . "23:59" "2015-12-05 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-06" 1 110.335 149.55 208.6575 174.38936 "07:59" "2015-12-06 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-06" 2 110.99 151.32 210 175.17485 "16:00" "2015-12-06 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-06" 3 . . . . "23:59" "2015-12-06 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-07" 1 110.77 151.5 214.98 176.9686 "07:59" "2015-12-07 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-07" 2 107.66 147.99 205.75 171.1186 "16:00" "2015-12-07 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-07" 3 104.97 145.01 205.2 169.3728 "23:59" "2015-12-07 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-08" 1 105.415 145.33 205.265 169.3202 "07:59" "2015-12-08 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-08" 2 104.97 145.65 205.54 169.6171 "16:00" "2015-12-08 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-08" 3 . . . . "23:59" "2015-12-08 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-09" 1 104.97 145.92 207.24 170.63264 "07:59" "2015-12-09 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-09" 2 104.97 147.16 205.435 169.48587 "16:00" "2015-12-09 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-09" 3 . . . . "23:59" "2015-12-09 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-10" 1 104.97 147.16 208.315 173.76367 "07:59" "2015-12-10 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-10" 2 104.99 147.99 210 176.39133 "16:00" "2015-12-10 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-10" 3 . . . . "23:59" "2015-12-10 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-11" 1 105.69 148.75 214.67 174.9753 "07:59" "2015-12-11 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-11" 2 105.69 148.75 214.2775 174.9714 "16:00" "2015-12-11 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-11" 3 105.69 148.965 214.825 182.88837 "23:59" "2015-12-11 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-12" 1 109.76 151.5 214.98 177.088 "07:59" "2015-12-12 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-12" 2 109.57 151.5 212.325 176.69136 "16:00" "2015-12-12 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-12" 3 110.1225 148.75 207.97 175.44093 "23:59" "2015-12-12 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-13" 1 110.55 148.75 210 175.927 "07:59" "2015-12-13 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-13" 2 110.55 148.75 209.995 176.09927 "16:00" "2015-12-13 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-13" 3 110.99 151.5 207.97 175.9855 "23:59" "2015-12-13 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-14" 1 110.99 151.5 207.97 176.13016 "07:59" "2015-12-14 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-14" 2 110.99 151.5 207.49 175.95207 "16:00" "2015-12-14 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-14" 3 113.65 151.32 207.25 176.1622 "23:59" "2015-12-14 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-15" 1 114.1825 151.41 207.49 176.63448 "07:59" "2015-12-15 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-15" 2 114.36 151.32 208.21 176.49957 "16:00" "2015-12-15 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-15" 3 112.24 150 210 174.69102 "23:59" "2015-12-15 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-16" 1 113.65 151.32 210.4 175.1356 "07:59" "2015-12-16 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-16" 2 113.065 151.32 211.775 176.25023 "16:00" "2015-12-16 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-16" 3 115.91 151.5 209.105 176.2387 "23:59" "2015-12-16 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-17" 1 114.36 150.545 207.25 173.55644 "07:59" "2015-12-17 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-17" 2 114.36 151.09 207.25 174.5637 "16:00" "2015-12-17 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-17" 3 112.135 148.75 207.25 172.02206 "23:59" "2015-12-17 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-18" 1 114.36 149.92 207.87 175.4566 "07:59" "2015-12-18 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-18" 2 113.65 148.75 207.25 173.69534 "16:00" "2015-12-18 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-18" 3 118.33 151.5 214.95 180.4201 "23:59" "2015-12-18 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-19" 1 118.56 152.99 215.71 180.30553 "07:59" "2015-12-19 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-19" 2 119.31 152.99 215.12 179.263 "16:00" "2015-12-19 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-19" 3 119.31 151.5 214.2325 178.78603 "23:59" "2015-12-19 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-20" 1 119.4925 152.99 215.71 181.24663 "07:59" "2015-12-20 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-20" 2 119.25 152.99 215.85 181.3266 "16:00" "2015-12-20 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-20" 3 119.5 154.05 216.61 181.498 "23:59" "2015-12-20 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-21" 1 120.2575 154.6 216.195 181.61243 "07:59" "2015-12-21 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-21" 2 119.705 154.05 216.46 181.6927 "16:00" "2015-12-21 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-21" 3 114.36 147.71 216.31 177.83945 "23:59" "2015-12-21 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-22" 1 114.36 148.75 217.78 179.7802 "07:59" "2015-12-22 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-22" 2 115.155 148.75 218.95 182.94615 "16:00" "2015-12-22 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-22" 3 114.12 147.85 214.8325 178.60695 "23:59" "2015-12-22 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-23" 1 114.36 148.44 215.1375 178.2195 "07:59" "2015-12-23 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-23" 2 114.36 147.71 214.28 176.39894 "16:00" "2015-12-23 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-23" 3 114.3 148.75 216.6775 181.7427 "23:59" "2015-12-23 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-24" 1 114.12 147.71 214.61 179.2775 "07:59" "2015-12-24 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-24" 2 113.885 147.71 214.445 177.577 "16:00" "2015-12-24 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-24" 3 118.4625 148.75 218.95 183.9876 "23:59" "2015-12-24 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-25" 1 118.33 148.75 217.78 182.2171 "07:59" "2015-12-25 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-25" 2 118.33 148.75 218.95 184.2348 "16:00" "2015-12-25 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-25" 3 118.33 148.75 218.95 184.0091 "23:59" "2015-12-25 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-26" 1 118.595 149.65 218.95 184.72743 "07:59" "2015-12-26 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-26" 2 116.575 148.75 218.95 183.86197 "16:00" "2015-12-26 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-26" 3 115.42 148.75 218.95 182.9738 "23:59" "2015-12-26 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-27" 1 115.5625 148.75 218.6575 183.38004 "07:59" "2015-12-27 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-27" 2 114.59 148.75 218.95 185.2042 "16:00" "2015-12-27 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-27" 3 119.5 149.93 218.95 186.70554 "23:59" "2015-12-27 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-28" 1 119.5 149.92 218.95 185.5134 "07:59" "2015-12-28 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-28" 2 119.5 151.195 219.345 188.6705 "16:00" "2015-12-28 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-28" 3 113.8275 141.56 202.37 170.03584 "23:59" "2015-12-28 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-29" 1 115.12 142.9 204.655 172.76167 "07:59" "2015-12-29 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-29" 2 115.42 142.9 204.655 171.8042 "16:00" "2015-12-29 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-29" 3 109.405 137.05 192.455 171.29094 "23:59" "2015-12-29 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-30" 1 108.86 131.96 181.35 161.5101 "07:59" "2015-12-30 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-30" 2 108.86 132.72 182.93 162.9379 "16:00" "2015-12-30 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-30" 3 103.32 128.86 180.84 163.9678 "23:59" "2015-12-30 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-31" 1 102.76 124.18 177.13 155.92645 "07:59" "2015-12-31 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-31" 2 103.12 125.35 176.13 156.4449 "16:00" "2015-12-31 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2015-12-31" 3 104.85 128.08 178 161.6073 "23:59" "2015-12-31 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-01" 1 104.86 130.025 177.985 161.02515 "07:59" "2016-01-01 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-01" 2 101.95 119.5 158.695 144.57149 "16:00" "2016-01-01 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-01" 3 104.86 127.885 177.12 163.0666 "23:59" "2016-01-01 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-02" 1 105.46 131.2 168.64 145.27736 "07:59" "2016-01-02 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-02" 2 105.46 131.19 166.3 144.06587 "16:00" "2016-01-02 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-02" 3 108.385 130.035 154.0075 138.77951 "23:59" "2016-01-02 23:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-03" 1 108.0925 129.74 148.7475 136.77663 "07:59" "2016-01-03 07:59:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-03" 2 109.55 125.35 145.57 134.23042 "16:00" "2016-01-03 16:00:00" "Home Team vs. Away Team" "2016-01-03" "2016-01-03" 3 . . . . "23:59" "2016-01-03 23:59:00" end
These are the contents of my `do` file which shows you my effort:
Code:
import delimited "I:\somecsvfile.csv", clear gen double eventtime = clock(datetime, "YMDhms") tsset eventtime, format(%tcNN/DD/CCYY_HH:MM:SS) twoway (connected mean eventtime, msymbol(point) mfcolor(none)) /// (connected median eventtime, msymbol(point) mfcolor(none)) /// (connected thpercentile eventtime, msymbol(point) mfcolor(none)) /// (connected v7 eventtime, msymbol(point) mfcolor(none)), /// ytitle(Price in USD) /// xtitle(Scrape Date) /// xlabel(, angle(vertical) /// format(%tcNN/DD/CCYY_HH:MM:SS)) xmtick(##10, angle(vertical))
The output of my efforts is this:
1. My issue with this output is that NONE of the X-axis HH:MM:SS portion of date tick labels exist in my csv file at all! The column in my date that represents the date has the 3 patterns `"MM/DD/YYYY 07:59:00"`, `"MM/DD/YYYY 16:00:00"`, `"MM/DD/YYYY 23:59:00"`.. But my graph output has these HH:MM:SS postions of the date in axis labels that are NOT PRESENT in the dataset. ALL of the HH:MM:SS portions that you see in the X-axis labels like `05:46:40`, `00:40:00`, `19:33:20` etc do not exist in my data! If at all possible, **I would like to display 12 specific dates with `"MM/DD/YYYY 07:59:00"`, `"MM/DD/YYYY 16:00:00"`, `"MM/DD/YYYY 23:59:00"` pattern FROM my csv**, instead of Stata taking it upon itself to look at the relative position and accordingly setting a HH:MM:SS on the X axis label..
2. I would like to add 4 reference lines at 4 of those specific X-axis date points, with a custom text marker on top. The issue I'm having with this is, I cannot seem to understand how to pick the positions in X axis as they are all datetime values and how I add multiple reference lines with a text marker at a specific Y coordinate..
3. Set a smaller legend inside the graph instead of outside
I would like my output to be something like the one below.
Forigve my terrible MS Paint Skills
[1]: https://i.stack.imgur.com/npUIP.jpg
[2]: https://i.stack.imgur.com/lZkrg.jpg
Comment