Announcement

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

  • Working with data prior to 1960

    In Stata, I am aware that the numeric encoding that Stata uses is centred on the first millisecond of 01jan1960, that is, 01jan1960 00:00:00.000. However, the current data set I am using is centre around 1800-01-01 00:00:00, with date calculated as hours since this date. Can I change the numeric encoding that Stata uses to 1800-01-01 00:00:00 rather than 01jan1960 00:00:00.000?

    Thanks.

  • #2
    no, you have to change the data instead. So here is an example of how to do that:

    Code:
    . clear
    
    . input otherdate
    
         otherdate
      1. 0
      2. 15
      3. 23
      4. end
    
    .
    . //How many hours is there between 1-1-1800 and 1-1-1960
    .  di clock("01 Jan 1800 00:00:00.000", "DMYhms")/(60*60*1000)
    -1402512
    
    .  
    .  // so that is the number we need to add to move to 1-1-1960
    .  // to measure it in milisecons instead of hours we need to multiply by 60*60*1000
    .  // These are very large numbers, so remember to store it as double
    .  
    .  gen double newdate = (otherdate - 1402512)*60*60*1000
    
    .  
    .  // Let Stata show those numbers as date time that humans can read
    .  format newdate %tc
    
    .  
    .  //admire the result
    .  list
    
         +-------------------------------+
         | otherd~e              newdate |
         |-------------------------------|
      1. |        0   01jan1800 00:00:00 |
      2. |       15   01jan1800 15:00:00 |
      3. |       23   01jan1800 23:00:00 |
         +-------------------------------+
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      There is nothing to stop you using your own units of hours from any origin you choose. What you miss out on then starts with the lack of a specific Stata display format. For display you could use a corresponding string variable, but it would be a little fiddly to code up.

      Better on the whole to shift the origin, as Maarten Buis advises.

      Comment


      • #4
        Originally posted by Maarten Buis View Post
        no, you have to change the data instead. So here is an example of how to do that:

        Code:
        . clear
        
        . input otherdate
        
        otherdate
        1. 0
        2. 15
        3. 23
        4. end
        
        .
        . //How many hours is there between 1-1-1800 and 1-1-1960
        . di clock("01 Jan 1800 00:00:00.000", "DMYhms")/(60*60*1000)
        -1402512
        
        .
        . // so that is the number we need to add to move to 1-1-1960
        . // to measure it in milisecons instead of hours we need to multiply by 60*60*1000
        . // These are very large numbers, so remember to store it as double
        .
        . gen double newdate = (otherdate - 1402512)*60*60*1000
        
        .
        . // Let Stata show those numbers as date time that humans can read
        . format newdate %tc
        
        .
        . //admire the result
        . list
        
        +-------------------------------+
        | otherd~e newdate |
        |-------------------------------|
        1. | 0 01jan1800 00:00:00 |
        2. | 15 01jan1800 15:00:00 |
        3. | 23 01jan1800 23:00:00 |
        +-------------------------------+
        Thanks, this works!

        Comment

        Working...
        X