Announcement

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

  • Error with bootstrap program to get corrected SE's in a two-step procedure

    Dear All,

    I am trying to estimate a fixed-effects IV poisson equivalent using the control function approach advised by @Jeff Wooldridge here. I have a panel data where LgAneedc is my outcome, Lgm is the endogenous regressor of interest and LgrcxtotC is the instrument.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(LgAneedc Lgm LgrcxtotC) long id float year
     4.931884 11.599216 10.755259  5003 2001
            0 11.334538 11.070945  5003 2003
            0 10.918878 11.437474  5003 2005
            0  10.61348 10.564497  5003 2007
            0 10.765062 10.358118  5003 2009
            0 11.425528  10.21865  5003 2011
            0 11.290032  10.33008  5003 2013
            0  11.40166 10.431248  5003 2015
            0  11.40609 10.599012  5003 2017
            0 11.729268 11.806968  6004 2001
            0 11.085595 10.964026  6004 2003
            0 10.971986 11.361266  6004 2005
     4.775486 10.862973  10.83655  6004 2007
            0  11.12455 10.838668  6004 2009
            0 11.204343 10.602403  6004 2011
            0 11.139434  10.73576  6004 2013
            0 10.820865 10.519867  6004 2015
            0  10.98978  10.27652  6004 2017
     5.843838   12.3512 10.786705  6006 2001
            0 11.960934 11.236396  6006 2003
            0 12.428912  11.13863  6006 2005
            0  12.19357 10.521012  6006 2007
            0  11.91282 10.827817  6006 2009
            0  11.81625  10.49183  6006 2011
            0  12.28847  10.64877  6006 2013
            0 12.474733 10.750503  6006 2015
            0  12.41988 11.106917  6006 2017
            0 11.545062 10.411545  6030 2001
     4.888463  11.73737  10.86385  6030 2003
     6.625171 11.590188 11.186399  6030 2005
            0 11.644321 11.085802  6030 2007
     4.425613 11.913424 11.149463  6030 2009
     6.299826 11.986324 11.123384  6030 2011
     5.334969 12.031132 11.340435  6030 2013
      6.21779  12.37371  11.11862  6030 2015
     6.204095 12.397298 11.391512  6030 2017
            0  10.49827 10.017859  7004 2001
            0  9.740772  9.546296  7004 2003
            0   9.69968  9.931268  7004 2005
            0  9.634616  9.710717  7004 2007
            0 10.405068  9.711951  7004 2009
            0 10.392364  9.742559  7004 2011
            0 10.340804  9.741016  7004 2013
            0 10.310172 10.703634  7004 2015
            0   9.38021  9.558413  7004 2017
            0 10.667672  9.296714  7033 2001
            0  9.923084  9.116742  7033 2003
            0  9.459681  8.334874  7033 2005
            0 10.595987  9.197458  7033 2007
            0 10.963642  9.979009  7033 2009
            0 10.644748  9.658427  7033 2011
            0  9.751442  9.654863  7033 2013
            0  10.06172 9.5351305  7033 2015
            0  9.728492    9.8928  7033 2017
            0 10.208698  9.738981  7035 2001
            0  10.33924 10.186704  7035 2003
            0 10.411844  9.833261  7035 2005
            0  10.72443  9.819488  7035 2007
            0 10.167242  9.724209  7035 2009
    4.1929417 10.323373 10.377182  7035 2011
            0 10.738003 10.548703  7035 2013
            0  10.31622  9.997307  7035 2015
            0  8.544072  8.908122  7035 2017
            0  9.926491  9.499844 10003 2001
            0  9.234111  9.801512 10003 2003
            0  9.631241  9.670174 10003 2005
            0  10.21517   9.89855 10003 2007
            0  9.616987  10.16682 10003 2009
            0  9.828395 10.246012 10003 2011
            0  9.608812  10.00275 10003 2013
            0  9.614655  9.811955 10003 2015
            0  9.839711  9.788421 10003 2017
            0  10.01666  8.689496 10006 2001
            0   9.74325  9.640999 10006 2003
            0  9.017304  8.699591 10006 2005
            0  10.49909 10.233783 10006 2007
            0 10.598434 10.275494 10006 2009
            0 10.445745   9.83636 10006 2011
            0  10.51307  9.868604 10006 2013
            0 10.820985  9.530792 10006 2015
            0 10.558806  9.060495 10006 2017
            0 10.485355  9.279651 10007 2001
            0  10.47935  9.644846 10007 2003
            0 10.353577   9.77598 10007 2005
            0 10.339203  9.536077 10007 2007
            0 10.181932  9.620173 10007 2009
            0  10.22087  8.848678 10007 2011
            0 10.035196  9.139127 10007 2013
            0  8.344264  9.344272 10007 2015
            0  9.710689   8.87498 10007 2017
            0 11.431934  10.02675 11002 2001
            0  10.52496  10.02533 11002 2003
    4.1547513 10.495072 10.015833 11002 2005
            0 10.365026  10.28105 11002 2007
            0 10.527725  9.757092 11002 2009
            0  10.95044 10.082738 11002 2011
     6.248363 10.213922  9.578344 11002 2013
     3.932989  9.716777   9.86972 11002 2015
     3.246045  9.670991  9.428996 11002 2017
            0 10.694862  9.891031 11003 2001
    end
    But, when I run my boostrap command to estimate the corrected SE's I get the following error:

    Code:
    .         capture program drop myboot
    
    .         program define myboot, rclass
      1.                                                 
    .                         * first stage
    .                         xtset id year
      2.                         xtreg Lgm LgrcxtotC, fe cluster(newid)
      3.                         predict double LgrcxtotChat_fe, e
      4.                         * second stage                  
    .                         xtpoisson LgAneedc      Lgm      LgrcxtotChat_fe, fe vce(robust) 
      5.                         
    .                         return scalar bLgm = _b[Lgm]
      6.                         return scalar bLgrcxtotChat_fe = _b[LgrcxtotChat_fe]
      7.                         
    .                         return scalar seLgm = _se[Lgm]
      8.                         return scalar seLgrcxtotChat_fe = _se[LgrcxtotChat_fe]
      9.                         
    .                 end
    
    .         xtset, clear
    
    .         bootstrap r(bLgm) r(bLgrcxtotChat_fe) r(seLgm) r(seLgrcxtotChat_fe), reps(100) seed(123) cluster(id) idcluster(newid): myboot
    (running myboot on estimation sample)
    
    Bootstrap replications (100)
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    50
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   100
    insufficient observations to compute bootstrap standard errors
    no results will be saved
    r(2000);
    
    end of do-file
    
    r(2000);
    Any suggestions on what I may be doing wrong? I am new to bootstrap programs so I will be very grateful for suggested edits to the above to fix this, please.
    Many thanks,
    Sumedha

  • #2
    All the x's from bootstrap are telling you that all 100 runs failed for some reason. Perhaps if you run
    Code:
    bootstrap r(bLgm) r(bLgrcxtotChat_fe) r(seLgm) r(seLgrcxtotChat_fe), reps(1) noisily seed(123) cluster(id) idcluster(newid): myboot
    you will see output from the commands run within myboot that will shed some light on what is happening.

    Comment


    • #3
      Thank you so much for your suggestion, Prof. Lisowski. I followed your advice and got the following error(s) (reps must be an integer>1 so I ran 2):

      Code:
      .         capture program drop myboot
      
      .         program define myboot, rclass
        1.                                                 
      .                         * first stage
      .                         xtset id year
        2.                         xtreg Lgm LgrcxtotC, fe cluster(newid)
        3.                         predict double LgrcxtotChat_fe, e
        4.                         * second stage                  
      .                         xtpoisson LgAneedc      Lgm      LgrcxtotChat_fe, fe vce(robust) 
        5.                         
      .                         return scalar bLgm = _b[Lgm]
        6.                         return scalar bLgrcxtotChat_fe = _b[LgrcxtotChat_fe]
        7.                         
      .                         return scalar seLgm = _se[Lgm]
        8.                         return scalar seLgrcxtotChat_fe = _se[LgrcxtotChat_fe]
        9.                         
      .                 end
      
      .         xtset, clear
      
      .         bootstrap r(bLgm) r(bLgrcxtotChat_fe) r(seLgm) r(seLgrcxtotChat_fe), reps(2) noisily seed(123) cluster(id) idcluster(newid): myboot
      bootstrap: First call to myboot with data as is:
      
      . myboot
      
      Panel variable: id (strongly balanced)
       Time variable: year, 2001 to 2017, but with gaps
               Delta: 1 unit
      
      Fixed-effects (within) regression               Number of obs      =      6593
      Group variable: id                              Number of groups   =       733
      
      R-sq:  Within  = 0.0413                         Obs per group: min =         7
             Between = 0.7654                                        avg =       9.0
             Overall = 0.4683                                        max =         9
      
                                                      F(1,732)           =    173.06
      corr(u_i, Xb)  = 0.6892                         Prob > F           =    0.0000
      
                                      (Std. err. adjusted for 733 clusters in newid)
      ------------------------------------------------------------------------------
                   |               Robust
               Lgm | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
         LgrcxtotC |   .3340375   .0253919    13.16   0.000     .2841879    .3838872
             _cons |   7.741774   .2682211    28.86   0.000       7.2152    8.268349
      -------------+----------------------------------------------------------------
           sigma_u |   .6867625
           sigma_e |  .60806622
               rho |  .56055369   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      (4 missing values generated)
      note: you are responsible for interpretation of non-count dep. variable
      note: 169 groups (1519 obs) dropped because of all zero outcomes
      
      Iteration 0:   log pseudolikelihood = -10538.967  
      Iteration 1:   log pseudolikelihood = -10522.586  
      Iteration 2:   log pseudolikelihood = -10522.528  
      Iteration 3:   log pseudolikelihood = -10522.528  
      
      Conditional fixed-effects Poisson regression         Number of obs    =  5,074
      Group variable: id                                   Number of groups =    564
      
                                                           Obs per group:
                                                                        min =      8
                                                                        avg =    9.0
                                                                        max =      9
      
                                                           Wald chi2(2)     =  11.84
      Log pseudolikelihood = -10522.528                    Prob > chi2      = 0.0027
      
                                              (Std. err. adjusted for clustering on id)
      ---------------------------------------------------------------------------------
                      |               Robust
             LgAneedc | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
      ----------------+----------------------------------------------------------------
                  Lgm |   .3500179   .1302555     2.69   0.007     .0947217     .605314
      LgrcxtotChat_fe |  -.2547815   .1328746    -1.92   0.055    -.5152109    .0056479
      ---------------------------------------------------------------------------------
      
      Bootstrap replications (2)
      . myboot
      repeated time values within panel
      an error occurred when bootstrap executed myboot, posting missing values
      . myboot
      repeated time values within panel
      an error occurred when bootstrap executed myboot, posting missing values
      insufficient observations to compute bootstrap standard errors
      no results will be saved
      r(2000);
      
      end of do-file
      
      r(2000);
      
      .
      Any thoughts? Will be very grateful for help.
      Many thanks,
      S.

      Comment


      • #4
        repeated time values within panel
        That says it all. The bootstrap command by default resamples observations with replacement, and that leads to duplicated observations in the resulting data, which consequently no longer is able to be xtset as panel data.

        At the end of the discussion of Example 7 in the PDF documentation for the bootstrap command (linked to at the top of the output of help bootstrap) there is a technical note about what must be done to use bootstrap with panel data.

        Comment


        • #5
          Thank you so much! I got it!

          Comment

          Working...
          X