Announcement

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

  • Convert clock data type to daily

    Hi Statalisters,

    I have had issues with converting a date variable which was imported from database in clock data type into daily. Here is a sample of the data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double year_of_birth
    1.9039428e+12
    1.9039428e+12
    1.9039428e+12
    1.9039428e+12
    1.9039428e+12
    1.9039428e+12
    1.9039428e+12
    1.9066212e+12
    1.9066212e+12
    1.9066212e+12
    end
    format %tc year_of_birth
    I have tried with
    Code:
    format %td year_of_birth
    list
    But the data changes to numbers


    Code:
        year_o~h    
            
    1.    1.90e+12    
    2.    1.90e+12    
    3.    1.90e+12    
    4.    1.90e+12    
    5.    1.90e+12    
            
    6.    1.90e+12    
    7.    1.90e+12    
    8.    1.91e+12    
    9.    1.91e+12    
    10.    1.91e+12
    Any suggestions to get the time variable into daily (YMD) will be appreciated

    Madu
    Last edited by Madu Abuchi; 27 Oct 2020, 19:05.

  • #2
    my guess is that you want the "dofc(tc)" function; see
    Code:
    help datetime##s6

    Comment


    • #3
      Thanks Rich for your suggestion, which worked.

      The solution is:

      Code:
      gen dob = dofc( year_of_birth )
      format %td dob
      list
              
          year_o~h    dob    
                  
      1.    1.90e+12    01may2020    
      2.    1.90e+12    01may2020    
      3.    1.90e+12    01may2020    
      4.    1.90e+12    01may2020    
      5.    1.90e+12    01may2020    
                  
      6.    1.90e+12    01may2020    
      7.    1.90e+12    01may2020    
      8.    1.91e+12    01jun2020    
      9.    1.91e+12    01jun2020    
      10.    1.91e+12    01jun2020
      Madu

      Comment


      • #4
        Rich Goldstein is correct. Changing the display format alone can't possibly help here. You have numbers that are of the order of 2 trillion and if you tell Stata that they are really yearly dates. that means roughly 2 trillion years from now.. You need to push numbers through dofc() and then assign a pertinent daily display format:


        Code:
        . di %td dofc(1.9039428e+12)
        01may2020
        More discussion at https://www.stata-journal.com/articl...article=dm0067

        Comment

        Working...
        X