Announcement

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

  • bootstrap standard errors - panel data - repeated time values within panel error

    I am trying to bootstrap standard errors on a panel data set. There are no firm-year duplicates in the panel.

    I have searched for an answer for this throughout the forum and have not found it. Although many people seem to have this problem.

    Code:
    clear
    input firmid year y x
    1 1 7 3
    1 2 5 8
    1 3 6 4
    1 4 9 4
    1 5 6 3
    1 7 7 2
    2 1 4 7
    2 2 5 8
    2 3 4 6
    2 4 9 4
    2 5 4 6
    2 6 8 4
    end
    
    duplicates drop firmid year, force
    sort firmid year
    xtset firmid year
    
    reg y x
    bootstrap, cluster(firmid) r(50) idcluster(firmid_cl) seed(123): reg y x
    I get the

    Code:
    repeated time values within panel
    the most likely cause for this error is misspecifying the cluster(), idcluster(), or group() option
    r(451);
    Error everytime.

    Is the solution as simple as:

    Code:
    clear
    input firmid year y x
    1 1 7 3
    1 2 5 8
    1 3 6 4
    1 4 9 4
    1 5 6 3
    1 7 7 2
    2 1 4 7
    2 2 5 8
    2 3 4 6
    2 4 9 4
    2 5 4 6
    2 6 8 4
    end
    
    duplicates drop firmid year, force
    sort firmid year
    xtset firmid year
    
    reg y x
    xtset, clear
    xtset firmid
    bootstrap, cluster(firmid) r(50) idcluster(firmid_cl) seed(123): reg y x
    Thanks for the help.

  • #2
    Wouldn't you want to be using an estimation command tailored to panel data? Perhaps something like
    Code:
    set seed `=strreverse("1585475")'
    xtreg y c.(year x), i(firmid) fe vce(bootstrap, reps(1000) nodots)
    Using the vce(bootstrap) option with a command that's designed with panel data in mind handles clustering seamlessly.

    Comment


    • #3
      Kyle:
      as an aside to Joseph's helpful advice, I do not think you estimated a panel data regression in your first code.
      Looking at the following toy-example, regression coefficient are not the same if you use -regress- or -xtreg-:
      Code:
      . use "https://www.stata-press.com/data/r16/nlswork.dta"
      (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
      
      . reg ln_wage c.age##c.age, vce(cluster idcode)
      
      Linear regression                               Number of obs     =     28,510
                                                      F(2, 4709)        =     701.39
                                                      Prob > F          =     0.0000
                                                      R-squared         =     0.0882
                                                      Root MSE          =     .45654
      
                                   (Std. Err. adjusted for 4,710 clusters in idcode)
      ------------------------------------------------------------------------------
                   |               Robust
           ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               age |   .0855891   .0046943    18.23   0.000     .0763861    .0947922
                   |
       c.age#c.age |  -.0010982   .0000798   -13.76   0.000    -.0012547   -.0009417
                   |
             _cons |   .1647917   .0655679     2.51   0.012      .036248    .2933354
      ------------------------------------------------------------------------------
      
      . xtreg ln_wage c.age##c.age, vce(cluster idcode)
      
      Random-effects GLS regression                   Number of obs     =     28,510
      Group variable: idcode                          Number of groups  =      4,710
      
      R-sq:                                           Obs per group:
           within  = 0.1087                                         min =          1
           between = 0.1015                                         avg =        6.1
           overall = 0.0870                                         max =         15
      
                                                      Wald chi2(2)      =    1258.33
      corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
      
                                   (Std. Err. adjusted for 4,710 clusters in idcode)
      ------------------------------------------------------------------------------
                   |               Robust
           ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               age |   .0590339   .0041049    14.38   0.000     .0509884    .0670795
                   |
       c.age#c.age |  -.0006758   .0000688    -9.83   0.000    -.0008107    -.000541
                   |
             _cons |   .5479714   .0587198     9.33   0.000     .4328826    .6630601
      -------------+----------------------------------------------------------------
           sigma_u |   .3654049
           sigma_e |  .30245467
               rho |  .59342665   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      
      . xtreg ln_wage c.age##c.age, fe vce(cluster idcode)
      
      Fixed-effects (within) regression               Number of obs     =     28,510
      Group variable: idcode                          Number of groups  =      4,710
      
      R-sq:                                           Obs per group:
           within  = 0.1087                                         min =          1
           between = 0.1006                                         avg =        6.1
           overall = 0.0865                                         max =         15
      
                                                      F(2,4709)         =     507.42
      corr(u_i, Xb)  = 0.0440                         Prob > F          =     0.0000
      
                                   (Std. Err. adjusted for 4,710 clusters in idcode)
      ------------------------------------------------------------------------------
                   |               Robust
           ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               age |   .0539076    .004307    12.52   0.000     .0454638    .0623515
                   |
       c.age#c.age |  -.0005973    .000072    -8.30   0.000    -.0007384   -.0004562
                   |
             _cons |    .639913   .0624195    10.25   0.000     .5175415    .7622845
      -------------+----------------------------------------------------------------
           sigma_u |   .4039153
           sigma_e |  .30245467
               rho |  .64073314   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      
      .
      In addition, if your were intended to estimate a fixed effect panel data regression with -regress- instead of -xtreg,fe- (an approach that I would not recommend, though), your code should have beeb something like:
      Code:
      regress y x i.firmid_cl. vce(cluster firmid_cl)
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Originally posted by Carlo Lazzaro View Post
        . . . I do not think you estimated a panel data regression in your first code.
        Looking at the following toy-example, regression coefficient are not the same if you use -regress- or -xtreg-:
        So, I guess that that means that the OP's use here, in the context of clustered bootstrapping, of
        Code:
        xtgee . . ., . . . corr(independent) . . .
        which is the equivalent of regress (or more accurately, of glm for the default normal linear model), wasn't really accomplishing what he wanted?

        Comment


        • #5
          Joseph:
          it's difficult to say (for me, at least) without further details form the OP.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment

          Working...
          X