Announcement

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

  • Milliseconds problem with clock

    I am using Stata/SE 17.0 for Mac (Apple Silicon, Revision 05 Oct 2021) with a trivial example. My raw data (these are bid-ask spreads) look as follows
    Code:
     
    2021-11-23 17:45:00.154 64 UP 249,85 249,95 147
    2021-11-23 17:35:16.634 UP 249,45 1.837
    2021-11-23 17:35:16.634 UP 249,45 1.694
    2021-11-23 17:35:16.633 UP 249,45 1.037
    No, I use the usual way to convert the timestamp, for example I do
    Code:
    gen double timestamp=clock(var1, "YMDhms")
    format timestamp %tc
    and indeed I get
    Code:
    var1    bid    ask    spread    timestamp
    2021-11-15 09:00:13.058    253.5    254.75    1.25    15nov2021 09:00:13
    2021-11-15 09:00:13.140    253.75    253.8    .05    15nov2021 09:00:13
    2021-11-15 09:00:13.140    253.8    254.65    .85    15nov2021 09:00:13
    As can be seen the milliseconds from the string variable are probably not converted to Stata. In particular, the following shows this
    Code:
     tsset timestamp
    repeated time values in sample
    Does anyone know what to do?

  • #2
    The variable -timestamp- does actually contain the milliseconds, so you have converted the time faithfully into Stata's internal format. To convince yourself, study this example.

    Code:
    . di %tc clock("2021-11-23 17:45:00.154", "YMDhms")
    23nov2021 17:45:00
    
    . di %tcDDmonCCYY_HH:MM:SS.sss clock("2021-11-23 17:45:00.154", "YMDhms")
    23nov2021 17:45:00.154
    As for the error you received:

    repeated time values in sample
    Stata has told you the problem, and now you know it is nothing to do with the time conversion. Stata told you that you have repeated time values, and by definition of a time series, you cannot have repeated times. If you have problems with a time-series analysis, this would probably be better for a new thread.

    Comment


    • #3
      I did not know that the milliseconds are contained (but not shown). There were some duplicates with even the same milliseconds and after I removed them it now works. Unfortunately, the data seem to be of bad quality now...

      Comment

      Working...
      X