Announcement

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

  • Balanced panel data with consecutive observations and distinct starting point

    Hi all,

    Using Stata 15.1, I am trying to keep consecutive observations per gvkey close to the announcement date of a transaction. Announcementdummy=1 is the closest observation to the transaction and this is my distinct starting point. Using the below codes, I still end up with an unbalanced panel. What can be improved?

    Thanks in advance.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long gvkey byte(announcementdummy _spell _seq) float length
    1082 1 1 1  8
    1082 2 1 2  8
    1082 3 1 3  8
    1082 4 1 4  8
    1382 1 1 1  9
    1382 2 1 2  9
    1382 3 1 3  9
    1382 4 1 4  9
    2290 1 1 1  9
    2290 2 1 2  9
    2290 3 1 3  9
    2290 4 1 4  9
    2589 1 1 1  6
    2589 2 1 2  6
    2589 3 1 3  6
    2589 4 1 4  6
    2597 1 1 1  5
    2597 2 1 2  5
    2597 3 1 3  5
    2597 4 1 4  5
    3116 1 1 1  7
    3116 2 1 2  7
    3116 3 1 3  7
    3116 4 1 4  7
    3169 1 1 1  5
    3169 2 1 2  5
    3169 3 1 3  5
    3169 4 1 4  5
    3310 1 1 1 15
    3310 2 1 2 15
    3310 3 1 3 15
    3310 4 1 4 15
    3497 1 1 1  8
    3497 2 1 2  8
    3497 3 1 3  8
    3497 4 1 4  8
    3612 1 1 1  9
    3612 2 1 2  9
    3612 3 1 3  9
    3612 4 1 4  9
    end
    
    
    . tsset gvkey announcementdummy
           panel variable:  gvkey (unbalanced)
            time variable:  announcemen~y, 1 to 22, but with gaps
                    delta:  1 unit
    
    . xtset gvkey announcementdummy
           panel variable:  gvkey (unbalanced)
            time variable:  announcemen~y, 1 to 22, but with gaps
                    delta:  1 unit
    
    . tsspell, f(L.announcementdummy==.)
    warning: data contain gaps; see help on tsspell
    
    . egen length = max(_seq), by(gvkey _spell) 
    
    . keep if length >=4
    (3,155 observations deleted)
    
    . keep if inrange(announcementdummy, 1, 4)
    (6,898 observations deleted)
    
    . tab announcementdummy
    
    announcemen |
        t dummy |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |      1,670       24.80       24.80
              2 |      1,681       24.96       49.76
              3 |      1,688       25.06       74.82
              4 |      1,696       25.18      100.00
    ------------+-----------------------------------
          Total |      6,735      100.00

  • #2
    I already figured it out. Was plain simple. Had to use a different order of coding.

    Code:
    tsset gvkey announcementdummy
    xtset gvkey announcementdummy
    keep if inrange(announcementdummy, 1, 4)
    tsspell, f(L.announcementdummy==.)
    egen length = max(_seq), by(gvkey _spell) 
    keep if length >=4

    Comment

    Working...
    X