Bootstrap VAR residuals

Questions and discussions on Vector Autoregressions
comac
Posts: 25
Joined: Mon Jun 29, 2009 7:31 am

Bootstrap VAR residuals

Unread post by comac »

Hi everybody.

I am trying to bootsrap VAR residuals in an i.i.d. fashion.

Particularly, I should use this i.i.d. bootstrap of the residuals to generate a given number (say 10.000) of data sets, each of the same lenght as the actual data (after throwing out the first 100 data points to diminish the effect of starting values). For each of the 10.000 samples I have to recalculate the VAR parameters. Then subtract the mean of these estimates from the original parameters to obtain the small sample bias.

Folloing W.Enders' programming notes I have attempted to program what explained above for the univariate case - AR(1), i.e.:

Code: Select all

all 50
seed 2001
set x = %uniform(5,15)
set y = x**0.5 + %ran(1)

nonlin alpha beta
frml monte y = beta*x**alpha
com alpha = 0.48, beta = 0.98
nlls(frml=monte) y / e

com alpha_hat = %beta(1) , beta_hat = %beta(2)
set alpha_star 1 1000 = 0.
set beta_star 1 1000 = 0.
set discrep1 1 1000 = 0.
set discrep2 1 1000 = 0.

do i = 1,1000
set e_star = e(fix(%uniform(1,51)))
set y_star = beta_hat*x**alpha_hat + e_star

nonlin alpha beta
frml monte y_star = beta*x**alpha
com alpha = alpha_hat, beta = beta_hat

nlls(frml=monte,noprint) y_star
com alpha_star(i) = %beta(1) , beta_star(i) = %beta(2)

*Compute the bias for the 1000 obs.

com discrep1(i) = %beta(1) - alpha_hat
com discrep2(i) = %beta(2) - beta_hat

end do i

table / discrep1 discrep2
Could anybody help with the extension to the multivariate case (or also is there any program already wrritten on this purpose in RATS)?
Any hint will be highly appreciated .

Many thanks

Corrado
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Bootstrap VAR residuals

Unread post by TomDoan »

This is an example out of the VAR course book (http://www.estima.com/courses_completed.shtml). Your application will be somewhat different because you want to sample a longer length than the original estimation and this is designed just to bootstrap the existing data set.

The adjustment you would need to make is to do this inside the loop:

Code: Select all

   @VARBootDraw(model=varmodel,resids=resids) rstart rend+100 rstart rend
   *
   * Estimate the model with resampled data
   *
   estimate(noprint,noftests) rstart+100 rend+100
This resamples the range from rstart to rend+100 given residual sets drawn from rstart to rend. (The residuals for all series at a given time period are drawn together), then does the estimation over the same number of entries as originally used, but shifted up 100.

Code: Select all

*
* IRF error bands by bootstrapping
*
open data e1.dat
calendar(q) 1960
data(format=prn,org=columns,skips=6) 1960:01 1982:04 invest income cons
*
set dinc  = log(income/income{1})
set dcons = log(cons/cons{1})
set dinv  = log(invest/invest{1})
*
system(model=varmodel)
variables dinv dinc dcons
lags 1 2
det constant
end(system)
estimate(sigma,resids=resids) * 1978:4
*
@VARBootSetup(model=varmodel) bootvar
*
compute rstart=%regstart()
compute rend  =%regend()
*
compute bootdraws=2000
compute nvar  =3
compute nsteps=8
declare vect[rect] %%responses
dim %%responses(bootdraws)
declare rect[series] impulses(nvar,nvar)
declare vect ix
*
infobox(action=define,progress,lower=1,upper=bootdraws) $
   "Bootstrap Simulations"
do draw=1,bootdraws
   @VARBootDraw(model=varmodel,resids=resids) rstart rend
   *
   * Estimate the model with resampled data
   *
   estimate(noprint,noftests)
   impulse(noprint,model=bootvar,factor=%identity(3),$
     results=impulses,steps=nsteps)
   *
   * Store the impulse responses
   *
   dim %%responses(draw)(nvar*nvar,nsteps)
   ewise %%responses(draw)(i,j)=ix=%vec(%xt(impulses,j)),ix(i)
   infobox(current=draw)
end do draw
infobox(action=remove)
*
@mcgraphirf(model=varmodel,center=median,percent=||.025,.975||,$
  shocks=||"Investment","Income","Consumption"||,$
  footer="95% other-percentile bootstrap bands")
Data file:
e1.dat
(2.64 KiB) Downloaded 1037 times
Supporting procedures:
varbootsetup.src
(1.91 KiB) Downloaded 1077 times
comac
Posts: 25
Joined: Mon Jun 29, 2009 7:31 am

Re: Bootstrap VAR residuals

Unread post by comac »

Tom -- this is helpful but I could obtain the small sample bias in the multivariate case?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Bootstrap VAR residuals

Unread post by TomDoan »

This will compute the matrix total as the bootstrapped estimate of the bias.

Code: Select all

open data e1.dat
calendar(q) 1960
data(format=prn,org=columns,skips=6) 1960:01 1982:04 invest income cons
*
set dinc  = log(income/income{1})
set dcons = log(cons/cons{1})
set dinv  = log(invest/invest{1})
*
system(model=varmodel)
variables dinv dinc dcons
lags 1 2
det constant
end(system)
estimate(sigma,resids=resids) * 1978:4
compute base=%modelgetcoeffs(varmodel)
compute total=%zeros(%rows(base),%cols(base))
*
@VARBootSetup(model=varmodel) bootvar
*
compute rstart=%regstart()
compute rend  =%regend()
*
compute bootdraws=2000
compute nvar  =3
compute nsteps=8
declare vect[rect] %%responses
dim %%responses(bootdraws)
declare rect[series] impulses(nvar,nvar)
declare vect ix
*
infobox(action=define,progress,lower=1,upper=bootdraws) $
   "Bootstrap Simulations"
do draw=1,bootdraws
   @VARBootDraw(model=varmodel,resids=resids) rstart rend
   *
   * Estimate the model with resampled data
   *
   estimate(noprint,noftests)
   compute total=total+(%modelgetcoeffs(bootvar)-base)
   infobox(current=draw)
end do draw
infobox(action=remove)
*
compute total=total/bootdraws
comac
Posts: 25
Joined: Mon Jun 29, 2009 7:31 am

Re: Bootstrap VAR residuals

Unread post by comac »

Dear Tom ,thanks a lot. Just one last question. What if I would want to use my bias corrected parameters (the one named 'total') to simulate a very long series (70,000 obs. + 1,000 starting values that are discarted)?

Is it correct to build a new loop where:

Code: Select all

@VARBootDraw(model=varmodel1,resids=resids) rstart rend+1000 rstart rend
   *
   * Estimate the model with resampled data
   *
   estimate(noprint,noftests) rstart+1000 rend+1000
*with  
compute varmodel1 = %modelsetcoeffs(varmodel,total)	
compute rstart=0
compute rend  =70.000
Many thanks and sorry for bothering so much.

Corrado
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Bootstrap VAR residuals

Unread post by TomDoan »

comac wrote:Dear Tom ,thanks a lot. Just one last question. What if I would want to use my bias corrected parameters (the one named 'total') to simulate a very long series (70,000 obs. + 1,000 starting values that are discarted)?

Is it correct to build a new loop where:

Code: Select all

@VARBootDraw(model=varmodel1,resids=resids) rstart rend+1000 rstart rend
   *
   * Estimate the model with resampled data
   *
   estimate(noprint,noftests) rstart+1000 rend+1000
*with  
compute varmodel1 = %modelsetcoeffs(varmodel,total)	
compute rstart=0
compute rend  =70.000
Corrado
rstart and rend are the actual limits of the estimated residuals. Those you can't change. It's the first two parameters on VARBootDraw that give the range of the simulated data. You can't start that earlier than rstart because of the need for lagged data, but you could do

@VARBootDraw(model=varmodel1,resids=resids) rstart rstart+69999 rstart rend

to generate a sample of size 70000. (Don't use punctuation like , or . in large integers).
Post Reply