Announcement

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

  • Converting Date data to quarterly format

    Hi all,

    I'm sure this is a fairly basic question to answer but I'm relatively new to stata and can't seem to find an example of converting the data in a format like I have.
    I have a variable called quarters that has data from 2015q1 to 2021q4 in the format "151, 152, 153, etc." representing 2015q1, 2015q2, 2015q3, respectively. How do I convert this into stata's quarterly data format?

    Thanks in advance!

  • #2
    Stata dates are SIF values and 2015q1 maps to 220.

    . di tq(2015q1)
    220
    So if you state that 151 maps to 2015q1 in your current setting, then it is a matter of just adding a constant to each date. But this assumes that there are no holes in the sequence.

    Code:
    replace qdate= qdate+220-151
    format qdate %tq

    Comment


    • #3
      An alternative interpretation of this

      2015q1 to 2021q4 in the format "151, 152, 153, etc."
      is that 2021q1 is written as 211. Then you want

      Code:
      g qdate= yq(2000+ int(quarter/10), quarter-int(quarter/10)*10)
      format qdate %tq

      Last edited by Andrew Musau; 07 Dec 2022, 18:31.

      Comment


      • #4
        Thanks for the response Andrew!
        I see, so 2015q1 maps to 220 and each following quarter is 221, 222, etc.?
        I've run the code above and I get holes in the sequence because there are jumps in my numbers: 2015q4 is 154 but the next quarter, 2016q1, is coded as 161. It seems like an arithmetic function like the one you suggested might not work for this format.
        I'd love a way to just tell stata that the first two digits are the year (with a prefix "20") and the last digit is the quarter.
        Thanks again!

        Comment


        • #5
          Ah, your second post loaded as I was posting the above-- that will work! Much appreciated.

          Comment

          Working...
          X