Announcement

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

  • Error in panel bootstrap program.

    Dear All,
    I want to estimate a Poisson FE IV using the approach suggested by Jeff Wooldridge in C:\Users\wooldri1\Dropbox\semin (weilinmetrics.com). Following a previous post ivpoisson with panel-data fixed effects - Statalist I am trying to get the corrected standard error using panel boostrap. I need to run it on a few different samples and specifications so I try to run it in a loop as follows:

    Code:
    . local IFFY1     "if (numbersibs>1)"     // Just the sibling sub-sample
    
    . local IFFY2 ""  // Entire sample
    
    . 
    . foreach C in id sibid{
      2. foreach S in 1 2{
      3. 
    .         capture program drop myboot
      4.         program define myboot, rclass
      5.                 preserve
      6.                         bsample
    
    
      7.                         xtset `C' year
      8.                         xtreg LgrcxtotC c.year `IFFY`S'', fe
      9.                         predict double LgrcxtotChat_fe, e
     10.                                                 
    .                         xtpoisson LgAneedc      Lgm      LgrcxtotChat_fe i.year `IFFY`S'', fe vce(robust) 
     11.                         
    .                         return scalar bLgAneedc = _b[LgAneedc]
     12.                         return scalar bLgm = _b[Lgm]
     13.                         return scalar bLgrcxtotChat_fe = _b[LgrcxtotChat_fe]
     14.                         
    .                         return scalar seLgAneedc = _se[LgAneedc]
     15.                         return scalar seLgm = _se[Lgm]
     16.                         return scalar seLgrcxtotChat_fe = _se[LgrcxtotChat_fe]
     17.                         
    .                 restore
     18.         end
    --Break--
    r(1);
    
    end of do-file
    
    --Break--
    r(1);
    I am trying to return the coefficient estimates and the corrected SEs. But it simply stops; not sure why. It is likely something embarrassingly silly that I am doing wrong. Will be grateful for any help anyone may be able to offer to get this to run.
    Many thanks in advance.
    Sincerely,
    Sumedha.

  • #2
    I think the current approach has some fatal flaws.

    1. Defining a program within a loop begs for problems. Write the program once, use syntax to make it flexible enough and then call the program repeatedly from a loop.

    2. I assume your bootstrap sampling approach is currently wrong. You simply use bsample, which is not adequate for panel data. Here, you need to draw not observations randomly but panel members. The general approach is described here: https://www.stata.com/support/faqs/s...th-panel-data/
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      Hi Felix,
      Thank you for your response. I can easily move the bootstrap out of the loop; thank you for the suggestion. But, unfortunately the link you shared does not provide an example of how bsample should be correctly specified. Might you be able to suggest how to specify it, please?

      Sincerely,
      Sumedha.

      Comment


      • #4
        See my PM for an example.
        Best wishes

        (Stata 16.1 MP)

        Comment


        • #5
          Thank you Felix for your DM and sharing your book example. The example you pointed out is helpful in thinking about why the bsample should specify the panel structure but I am not sure exactly what the solution should be. I am sorry knowing my code is wrong is not helping me figure out how to make it right

          I would be very grateful if anyone may have direct advise on how I can correct the code above...

          Many thanks in advance,
          Sincerely,
          Sumedha.

          Comment


          • #6
            The only thing you need is the ID that identifies a person in your original data. As you have panel data, you have multiple individuals, each with multiple rows in the dataset. Then you can write this as follows:

            Code:
            cap program test1
            program define test1, rclass
                syntax, id(varname)
                xtset `id' year
                xtreg...
                return scalar ret
            end
            
            
            bootstrap r(ret), cluster(old_id) idcluster(new_id): test1, id(new_id)
            Here I assume that the ID in your dataset is called old_id. The bootstrap program now selects a number of individuals and draws their entire history. It then assigns a new ID, which I called new_id. This new ID is then given to the main program and used for xtset.
            Best wishes

            (Stata 16.1 MP)

            Comment

            Working...
            X