Announcement

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

  • Small question on date variables

    I have a rather simple (yet silly) question.
    Assume my data has a variable which is stored as a string with values such as: "1998q4", "2003q2", etc.
    How can I transform it to a proper quarterly-time variable for stata? I tried using the date() function, but the generated variable is missing on all observations.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 start
    "1998q4"
    "1999q3"
    "2003q4"
    "2009q2"
    "2003q1"
    end

  • #2
    The date() function is documented as yielding daily date variables. It won't yield quarterly dates or any other kind of non-daily dates. This confusion is so frequent that I commend use of the synonymous function daily() which is less likely to be misunderstood. You need quarterly(), e.g.

    Code:
    .  di quarterly("2017q2", "YQ")
    229
    
    .  di %tq  quarterly("2017q2", "YQ")
    2017q2
    In your case generate is needed.

    (The date() function in my view is now poorly named, but it goes back to the earliest date functionality in Stata, when daily dates were the only kind of date with dedicated support (years needing nothing special).)
    Last edited by Nick Cox; 02 May 2017, 10:13.

    Comment


    • #3
      I knew I was missing something simple. Thanks

      Comment

      Working...
      X