Announcement

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

  • Bootstrap local projections impulse responses/historical decompositions

    Dear Statalisters,

    I am trying to bootstrap the impulse response function that I obtain from a local projection. The tricky bit is that the object I want to bootstrap is a vector. This is the code that I have so far:

    Code:
    clear
    
    set obs 200
    
    set seed 12
    
    gen xx=runiform()
    
    gen e=rnormal(0,1)
    
    gen lindpro=0.5*x+e
    
    g time =_n
    tsset time
    
    local nlags 3
    local irflag = 36
    capture program drop lpirf
    program lpirf, eclass
        args xx lindpro nlags irflag
        
        * compute IRFs
        local irflagp1 = `irflag'+1
        mat bbb = J(`irflagp1',1,0)
    
        forvalues h = 0/`irflag' {
            local hp1 = `h'+1
            qui reg F`h'.xx L(0/`nlags').xx L(1/`nlags').lindpro, r
            mat bbb[`hp1',1] = _b[xx]
        }
      
        tempname bb
        matrix `bb'=bbb'
        ereturn clear
        ereturn post `bb'
        ereturn local cmd="bootstrap"
    
    end
    
    lpirf xx lindpro `nlags' `irflag'
    
    matrix list e(b)
    
    bootstrap _b, reps(100) nowarn nodrop: lpirf xx lindpro `nlags' `irflag'
    While the code successfully produces the impulse response, unfortunately, it does not work with the bootstrap. I get the error message "insufficient observations to compute bootstrap standard errors no results will be saved".

    Now, I could easily compute the standard errors of the impulse responses in a different way, however, ultimately I want to bootstrap the historical decomposition, which is yet again a function of the impulse responses and the data:

    Code:
    cap drop hdlindpro
    gen hdlindpro = 0
    forvalues h = 1/`irflag' {
            qui replace hdlindpro = hdlindpro + bbb[`h',1]*L`h'.xx
    }
    mkmat hdlindpro if hdlindpro!= . , matrix(histdec)
    Therefore, I think I have to do it this way. Does anyone have an idea what the problem could be? I tried to include the nodrop option but with no avail.

    Many thanks in advance and all the best,

    Diego

  • #2
    I think I have figured out the problem that occurred when trying to bootstrap the impulse responses. It seems that bootstrap does not like the lag "L" and lead "F" operators. When computing the necessary leads and lags manually, it works:

    Code:
    clear
    
    set obs 200
    
    set seed 12
    
    gen xx=runiform()
    
    gen e=rnormal(0,1)
    
    gen lindpro=0.5*xx+e
    
    g time =_n
    tsset time
    
    local nlags 3
    local irflag = 36
    
    * compute necessary leads and lags
    forvalues lag = 1/`nlags' {
        foreach yy of varlist xx lindpro e {
            cap drop `yy'L`lag'
            g `yy'L`lag' = `yy'[_n-`lag']
        }
    }
    
    foreach yy of varlist xx lindpro {
        forvalues hh = 0/`irflag' {
    
            cap drop `yy'F`hh'
            g `yy'F`hh' = `yy'[_n+`hh']
        }
    }
    
    forvalues hh = 1/`irflag' {
        cap drop xxL`hh'
        g xxL`hh' = xx[_n-`hh']
    }
    
    capture program drop lpirf
    program lpirf, eclass
        args nlags irflag
        
        * compute IRFs
        local irflagp1 = `irflag'+1
        mat bbb = J(`irflagp1',1,0)
    
        forvalues h = 0/`irflag' {
            local hp1 = `h'+1
            
            qui reg xxF`h' xx xxL* lindproL*, r
            mat bbb[`hp1',1] = _b[xx]
        }
        
        tempname bb
        matrix `bb'=bbb'
        ereturn clear
        ereturn post `bb'
        ereturn local cmd="bootstrap"
    
    end
    
    lpirf `nlags' `irflag'
    
    matrix list e(b)
    
    bootstrap _b, reps(100) nodrop: lpirf `nlags' `irflag'
    However, when I try to bootstrap the historical decomposition, which is a function of the impulse responses and the data, I get that the bootstrap fails in many (about half) of the replications

    Click image for larger version

Name:	bootstrap erro.png
Views:	1
Size:	8.6 KB
ID:	1675496

    It computes the standard errors though, however, they are only based on the 48 successful replications. The error I get is "captured error in _b[rxxx], posting missing value. Does anyone have an idea what the issue could be?

    The code for the historical decomposition is

    Code:
    capture program drop histdeco
    program histdeco, eclass
        args nlags irflag
        
        * compute IRFs
        local irflagp1 = `irflag'+1
        mat bbb = J(`irflagp1',1,0)
    
        forvalues h = 0/`irflag' {
            local hp1 = `h'+1
            
            qui reg xxF`h' xx xxL* lindproL*, r
            mat bbb[`hp1',1] = _b[xx]
        }
        
        
        * compute HD
        cap drop xx_hd
        gen xx_hd = 0
        
        forvalues h = 1/`irflag' {
            qui replace xx_hd = xx_hd + bbb[`h',1]*xxL`h'
        }
        mkmat xx_hd if xx_hd != ., matrix(histdec)
    
        tempname bb
        matrix `bb'=histdec'
        ereturn clear
        ereturn post `bb'
        ereturn local cmd="bootstrap"
    
    end
    
    lpirf `nlags' `irflag'
    
    matrix list e(b)
    
    bootstrap _b, reps(100) noisily nodrop: histdeco `nlags' `irflag'

    Comment

    Working...
    X