Announcement

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

  • Changing date format changes the date completely

    Dear statalist members,

    I have a dataset with dates (variable name: observation_date) in the format %td even though the intervals are quarterly, e.g 01jan1970, 01apr1970, 01jul1970, etc. I want to change them in this form 1970Q1, 1970Q2, etc. When I try to change the format to %tq, the years change completely. Could you offer me some guidance on how to proceed please?

  • #2
    Daily date variables (which are what you have) are on a different measurement scale from quarterly date variables. Changing display formats changes the way Stata presents things to you visually, but it does not change the actual numeric content. When you change the format from %td to %tq it is like changing the reported measurement unit of some mass from grams to kg without correspondingly changing the numeric value.

    So what you need to do is create an actual quarterly date variable:
    Code:
    gen qdate = qofd(observation_date)
    format qdate %tq
    This variable will correctly carry the quarterly date information and display it readably for you.

    Comment


    • #3
      A daily date variable and a quarterly date variable are quite distinct. See

      Code:
      help datetime
      Code:
      clear
      input float ddate
      23410
      23411
      23412
      end
      format ddate %td
      
      gen wanted= qofd(ddate)
      format wanted %tq
      Res.:

      Code:
      . l
      
           +--------------------+
           |     ddate   wanted |
           |--------------------|
        1. | 04feb2024   2024q1 |
        2. | 05feb2024   2024q1 |
        3. | 06feb2024   2024q1 |
           +--------------------+
      Crossed with #2.

      Comment


      • #4
        ​​​​​Thank you for your help!

        Comment


        • #5
          #2 and =3 explain the problem concisely and precisely. There is a more leisurely discussion at https://journals.sagepub.com/doi/pdf...867X1201200415

          Comment

          Working...
          X