Announcement

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

  • Convert quarterly string to Stata date

    Hello,

    This may be really simple and I am just missing something from other examples I have seen, but I have a quarter string variable:
    Code:
    clear
    input str7 qtr
    "Q1 2016"
    "Q2 2016"
    "Q3 2016"
    "Q4 2016"
    end
    
    gen newqtr = quarterly(qtr, "QY")
    But when I try generating the newqtr variable I just get missing values, I have seen a similar example where the quarter was formatted like "2016 Q1" and they could use the quarterly() function with the mask being "YQ". Do I need to have my quarter variable reformatted for this to work? The data I get just gives it to me in this format so I was hoping I could just go straight into the conversion.

    Thank you in advance,

    Colton Tousey

    P.S. I am still using Stata14

  • #2
    quarterly(substr(qtr, 2, .), "QY") works. In other words, you have to ignore the "Q".

    From experience I'd say that the
    quarterly() and monthly() functions fail more easily than daily().

    numdate (SSC) does a little better with the use of an undocumented option:

    Code:
    numdate q foo = qtr, pattern(QY) clean

    Comment


    • #3
      Thank you, Nick. I generally get dates in excel format, so I have been able to use the date() function and then convert from daily to quarterly with relatively no problems. This data just happens to give me this string.

      Comment

      Working...
      X