Announcement

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

  • Set data quarterly: Error with quarters (time, "YQ")

    Dear all,

    I want to conduct a panel data analysis using a very large dataset with close to 2b observations. I am using Stata 16 for Windows.

    My time variable is in string format and and the data looks as follows:
    ID time price
    AB123 2010Q1 10
    AB123 2010Q2 11
    BG235 2011Q2 500
    BG235 2011Q3 550
    QWE89 2016Q4 1000


    Here, I attempted to use time as a time variable using the following command:

    gen time2 =quarter(time, "YQ")
    format time2 %tq


    However, I always receive the error message:

    time, "YQ" invalid name
    r(198),

    I am not sure where this error comes from as this solution had been successfully implemented in similar previous posts. Hence, I would kindly like to ask you how to circumvent this problem.

    Thank you very much for your advice in advance!

    Best regards,


  • #2
    quarter() is the function to extract quarters from daily dates. quarterly() is the function to convert quarterly dates stored as strings to Stata Internal Format dates. You should use the latter:

    Code:
    . gen time2 =quarterly(time, "YQ")
    
    . gen time3 =quarter(dofq(time2))
    
    . format time2 %tq
    
    . list time*
    
         +-------------------------+
         |   time    time2   time3 |
         |-------------------------|
      1. | 2010Q1   2010q1       1 |
      2. | 2010Q2   2010q2       2 |
      3. | 2011Q2   2011q2       2 |
      4. | 2011Q3   2011q3       3 |
      5. | 2016Q4   2016q4       4 |
         +-------------------------+
    Last edited by Ali Atia; 15 Apr 2021, 10:17.

    Comment


    • #3
      Wonderful! Thank you very much, I must have overlooked the ending so far. It worked out perfectly.

      Comment

      Working...
      X