Announcement

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

  • Quarter

    I'm getting a weird result when trying to apply the "quarter" and "year" commands to a date series. I generate the date series with:
    gen date = tq(2004q1) + _n-1
    format date %tq

    This gives me a date series starting from 1q2004.

    I then want to create a quarter variable that just shows the quarter - 1,2,3,4. I do this with

    gen quarter = quarter(date).

    What I end up with looks like this:

    +------------------+
    | date quarter |
    |------------------|
    1. | 2004q1 2 |
    2. | 2004q2 2 |
    3. | 2004q3 2 |
    4. | 2004q4 2 |
    5. | 2005q1 2 |
    |------------------|
    6. | 2005q2 2 |
    7. | 2005q3 3 |
    8. | 2005q4 3 |
    9. | 2006q1 3 |
    10. | 2006q2 3 |
    |------------------|
    11. | 2006q3 3 |
    12. | 2006q4 3 |
    13. | 2007q1 3 |
    14. | 2007q2 3 |


    What am I doing wrong with "quarter"?

    Thank you!

  • #2
    Dear Will,

    Welcome to the forum.
    Regarding your issue, it would be better to provide a data example of your dataset using
    Code:
    dataex
    Users of this forum can better understand your issue, providing specific guidance.



    Comment


    • #3
      Look again at the help for quarter(). It expects a daily date as argument. Therefore

      Code:
      replace quarter = quarter(dofq(date))

      Comment


      • #4
        Thank you! That took care of it.

        Comment


        • #5
          It's a side issue, but I recommend against even calling a daily date variable just date. I would use names like ddate, mdate, qdate That said, I too am inconsistent and would always prefer year to ydate.

          Comment

          Working...
          X