Hi
My dataset contains the close prices of some financial assets. It is collected at 30mins interval. It looks like this
The column time was created from the columns Date and Time by the following codes
It returns the exact time (at milliseconds) where the price of the nearest previous transaction is recorded. I know that it is approximately on 30 min interval, but I do not want my data look like this. So I decided to round up my data to the 30 mins interval using the following codes
but Stata says that no real changes made. Theoretically, it will round up all the values of the time column to the nearest 30mins interval. I also used the display function as follow
to check if my previous code works but this time, Stata returns the correct rounded-up time.
I don't know what make the difference in the results between two lines of code, why the replace function did not work as I expected?
Thank you for your supports.
My dataset contains the close prices of some financial assets. It is collected at 30mins interval. It looks like this
Code:
clear input str10(Date Time) float time double(BNB BTC XRP ETH SOL) "12/10/2021" "22:00" 1.9547927e+12 579.2999877929688 48297.2 .8332849740982056 4141.34 175.75999450683594 "12/10/2021" "22:30" 1.9547946e+12 577.6799926757813 48397.95 .8348299860954285 4205.27 177.3300018310547 "12/10/2021" "23:00" 1.9547964e+12 570.0800170898438 47984.15 .8238450288772583 4178.57 173.55999755859375 "12/10/2021" "23:30" 1.9547982e+12 562.510009765625 47695.42 .8194249868392944 4032.24 170.9600067138672 "12/11/2021" "0:00" 1.9548e+12 561.22998046875 47554.36 .8165000081062317 4069.81 171.2100067138672 end format %tc time
Code:
gen time = clock(Date + " " + Time,"MDYhm")
Code:
replace time = round(time/(30*60*1000),1)*30*60*1000
Code:
di %tc round(time[1]/(30*60*1000),1)*30*60*1000
I don't know what make the difference in the results between two lines of code, why the replace function did not work as I expected?
Thank you for your supports.
Comment