Announcement

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

  • quarterly data for xtset

    Dear researchers,
    If I have quarterly data like the below:






    Is it okay to use the above data as a panel and use the below code:

    Code:
    ge id= _n
    encode Firms, gen(COMPANY)
    xtset COMPANY quarter, quarterly

    Or does the quarter data have a specific treatment?

    Many thanks in advance!
    Attached Files
    Last edited by Omar Shaher; 01 Apr 2022, 11:43.

  • #2
    You can't handle that data in that way. The problem is that what that table (which, pointedly, is not your Stata data--please show Stata data examples in the future, and use the -dataex- command* to do that) calls quarterly is actually daily dates that correspond to the final days of the quarters. What you need to do, after you import the data to Stata is use the -qofd()- function to get a real Stata internal format quarterly date variable from that. Then you can use that new variable in the -xtset- function with the -quarterly- option and you will be OK.

    *If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Dear Clyde,

      Thanks very much for the post above and for devoting some of your valuable time to answering the question. Greatly appreciated.

      Okay, I have used the dataex, and I have taken a picture for you to see the data below.







      Then I have used the below code to sort the data quarterly as below:

      Code:
      gen qdate = yq (year, q)
      format qdate %tq
      xtset id qdate


      So, can you please correct me if I have used the code correctly?

      Many thanks in advance!
      Attached Files

      Comment


      • #4
        I do not see any -dataex- output in your post; that would be more helpful than the screenshot. From the screenshot, it looks to me as if your code is incorrect. But I would also think that Stata would have given you an error message to let you know that you have it wrong, too. There is no variable you show named q. But perhaps Stata expands that to the variable quarter. The problem is that that variable is a string, and to serve as the second argument of the yq() function it has to be an integer from 1 to 4. And I don't see any variable in your data set that takes on the values 1, 2, 3, and 4.

        Based on what I see in the screenshot, I would do the following:
        Code:
        gen qdate = quarterly(yq, "YQ")
        format qdate %tq
        xtset id qdate

        Comment

        Working...
        X