Announcement

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

  • drop few obs per year

    I'm using stata 13 with OS windows 10.

    I have a panel with quarterly data but some year don't have all four quarters and I'd like to drop if there is less than four quarter per year.
    Any idea how to do this?

  • #2
    you don't tell us much about your data; but, with suitable changes of variable names the following should help
    Code:
    bysort id year: gen byte count=_N
    drop if count<4

    Comment


    • #3
      Rich's code drops (id, year) pairs with less than 4 quarters. That's what you (seemingly) asked for. If you want to drop incomplete panels, there will be some maximum length you should know and

      Code:
      bysort id : gen count = _N 
      is the count to use.

      Comment


      • #4
        Hey Rich. Thanks for the reply. You code does exactly what I asked. Thanks.

        The thing is, what I asked don't quite solve my problem. I apologize for this. What I need exactly is to guarantee that I have four fiscal quarters for each firm in each year. I have an idea how to solve this, but I don't know how to code this. Let me give you an example with my data.

        permno: id
        anndats: earnings announcement day - Annual
        anndatsq: earnings annoucement day - quarter

        I can identify end of fiscal year when anndats = anndatsq. Thus, what I really need is to have exactly three observations between moments where anndats = anndatsq.


        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input long permno float(anndats anndatsq y) byte count
        18163 20299 20299 2015 3
        18163 20299 20201 2015 3
        18163 20299 20115 2015 3
        18244 16176 16176 2004 3
        18244 16580 16335 2004 3
        18244 16580 16260 2004 3
        18244 16580 16446 2005 2
        18244 16580 16580 2005 2
        end
        format %td anndats
        format %td anndatsq

        Comment

        Working...
        X