Announcement

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

  • Filtering out fourth quarter observations

    Hello everybody,

    I have a panel data set with quarterly data. The time data is reported in the following manner:


    19900331
    19900630
    19900930
    19901231
    19910331
    19910630
    19910930
    19911231
    19920331

    The only observations I am interested in are the fourth quarter observations. Therefore, if my dataset was limited to the points in time described above, I wanted to only keep:

    19901231
    19911231

    How do I do this?

    Thank you in advance and best regards,



  • #2
    As in your other thread it is not clear exactly how your dates are held but in Stata there is no practical solution except to follow Stata rules for handling dates like these. help datetime is essential reading.

    I am guessing that your dates are just large integers. This shows some technique.

    Code:
    clear
    input long problemdate 
    19900331
    19900630
    19900930
    19901231
    19910331
    19910630
    19910930
    19911231
    19920331
    end 
    
    gen dailydate = daily(string(problemdate, "%8.0f"), "YMD")
    gen qdate = qofd(dailydate) 
    gen quarter = quarter(dailydate)
    format qdate %tq 
    format dailydate %td 
    
    list , sep(4) 
    
         +-----------------------------------------+
         | proble~e   dailydate    qdate   quarter |
         |-----------------------------------------|
      1. | 19900331   31mar1990   1990q1         1 |
      2. | 19900630   30jun1990   1990q2         2 |
      3. | 19900930   30sep1990   1990q3         3 |
      4. | 19901231   31dec1990   1990q4         4 |
         |-----------------------------------------|
      5. | 19910331   31mar1991   1991q1         1 |
      6. | 19910630   30jun1991   1991q2         2 |
      7. | 19910930   30sep1991   1991q3         3 |
      8. | 19911231   31dec1991   1991q4         4 |
         |-----------------------------------------|
      9. | 19920331   31mar1992   1992q1         1 |
         +-----------------------------------------+
    If I have guessed right

    Code:
    keep if quarter == 4
    is what you want.

    Comment


    • #3
      Thank you very much Nick. Is it possible as well to convert date variables such as 'qdate' to a variable indicating which quarter it is, in this case 'quarter'? Thank you in advance.

      Comment


      • #4
        Code in #2 does precisely that, so I can't see a different question.

        Comment

        Working...
        X