Announcement

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

  • Different display format time variables (since Stata v18.0?)

    Dear all,

    My time variables are recently coming out differently, despite my code remaining the same and despite my raw data format remaining the same. My code is validated and tested to perform also on future exports from a database system. Recently I noticed that when converting a time string into a time format, the date '01Jan1960' is included in the time additionally. My feeling is that this is potentially related to the recent release of Stata v18.0 in my institute as all other factors have remained constant.

    Example data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 time_var
    "10:00"
    end
    Code:
    assert length(time_var) == 5                            
    gen time_var_new = clock(time_var, "hm")
    format time_var_new %tcHH:MM
    order time_var_new, after(time_var)
    drop time_var
    rename time_var_new time_var
    Would anyone happen to know what could be causing this, but more importantly how I can fix this?

    Thank you and best wishes,

    Moniek

  • #2
    There are no time variables in Stata, only datetime variables. You can format a datetime variable to display only the time part. So if your issue is that the datetime variable does not display only the time from running your code, I cannot replicate this in the most up-to-date version of Stata 18.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 time_var
    "10:00"
    end
    assert length(time_var) == 5                            
    gen time_var_new = clock(time_var, "hm")
    format time_var_new %tcHH:MM
    order time_var_new, after(time_var)
    drop time_var
    rename time_var_new time_var
    list
    Res.:

    Code:
    . list
    
         +----------+
         | time_var |
         |----------|
      1. |    10:00 |
         +----------+
    To update Stata:

    Code:
    update all

    Comment


    • #3
      Not so. I don't know what "tested and validated" means but an experienced Stata user would see at least one potential problem in your code, yet nothing has changed in Stata 18 to affect how this code has worked.

      It's not good practice to hold datetimes in anything but a double, as is explained repeatedly in help datetime

      in practice if you use only dates that are conventional times of day in hours and minutes then the largest is presumably no more 86.4 million (milliseconds) and the others are multiples of 60000 (milliseconds) and a float will serve.

      In principle all date-times are that, a date plus a time, and the origin zero is the beginning of 1960.

      So your data will show a daily date unless the display format excludes that, and yours does, so your data example and code example don't show the problem you report.



      Code:
      . * Example generated by -dataex-. For more info, type help dataex
      . clear
      
      . input str5 time_var
      
            time_var
        1. "10:00"
        2. end
      
      . 
      . assert length(time_var) == 5                            
      
      . gen time_var_new = clock(time_var, "hm")
      
      . format time_var_new %tcHH:MM
      
      . order time_var_new, after(time_var)
      
      . drop time_var
      
      . rename time_var_new time_var
      
      . 
      . list 
      
           +----------+
           | time_var |
           |----------|
        1. |    10:00 |
           +----------+

      Comment


      • #4
        Dear Andrew, dear Nick,

        Thank you both for your responses.

        - @Andrew: Apologies, I am aware that there are only datetime variables in Stata (mistake in my wording)
        - @Nick: I fully agree about the double, thank you for picking this up. However, regardless of the format, the display format seems to have changed recently for me.

        I realize now, after both of you using 'list', that it is purely the display format in the Data Editor that has looks differently for me recently. Previously, it would not display the 01Jan1960 in the Data Editor for me, but now it does (see screenshot)

        Click image for larger version

Name:	Stata_Screenshot.PNG
Views:	1
Size:	962 Bytes
ID:	1748990


        Would this have something to do with Stata v18.0? Ideally I would see the same display format as the format in which I export the data to Excel.

        Thank you for your thoughts,

        Best wishes,

        Moniek

        Comment


        • #5
          This is how it appears to me on a Windows machine.

          Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	10.9 KB
ID:	1748993



          The cell displays the time, but as you can see, the datetime is displayed at the top RHS because the cursor is on the cell.

          Comment


          • #6
            Again, nothing discussed here has changed in Stata 18.

            Comment

            Working...
            X