F. Di Iorio, S. Fachin
1.1
2017-02-16
Stationary Bootstrap resampling of time series
C10 C32
This function creates bootstrap pseudo-data resampling a set of zero mean
stationary time series using the Stationary Bootstrap by
D.N. Politis and J.P. Romano, "The Stationary Bootstrap", Journal of the
American Statistical Association, vol. 89, 1994, pp. 1303-1313.
inputs:
x: matrix, data to be resampled. Rows: time periods, columns: variables
b: scalar, mean block size; if b=0: use rule-of-thumb b = round(1.75*(T^
(1/3))
as in Palm, F.C., S. Smeekes, , J.P. Urbain (2011) "Cross-sectional
dependence
robust block bootstrap panel unit root tests" Journal of Econometrics, 163,
85-104.
output:
x_b: matrix of I(0) bootstrap pseudodata of the same dimensions of the
input matrix
contacts:
Francesca Di Iorio, fidiiorio@unina.it
Stefano Fachin, stefano.fachin@uniroma1.it
data to be resampled
block size
```
n=rows(x)
# initial check
if n <= 0
funcerr "data input error, check data"
else
if b < 0
funcerr "block input error, check mean block size"
else
# if required set mean block size to rule-of-thumb value
if b==0
b = round(1.75*(n^(1/3)))
endif
scalar prob = 1/(1+b)
# starting points, block sizes, end points
start_v = ceil(muniform(n,1)*n)
sizes=ceil(log(muniform(n,1))/log(1-prob))
end_v=start_v+sizes
x_b = {}
# resampling
loop for i=1..(n-1) --quiet
if end_v[i] <= n
x_b = x_b|x[start_v[i]:end_v[i],]
else
ebb=end_v[i]-n
if ebb <=n
x_b = x_b|x[start_v[i]:n,]|x[1:ebb,]
else
x_b = x_b|x[start_v[i]:n,]|x[1:,]
endif
endif
endloop
# pseudo-data of same length of data
x_b = x_b[1:n,]
endif # close block check
endif # close data check
return x_b
```

set messages off
set echo off
include SB.gfn
# load Johansen macroeconomic data
open denmark.gdt
nboot=200
/*
This example estimates 95% bootstrap confidence intervals for the cointegrating coefficients of a relationship estimated on
Johansen's danish data supplied as Gretl example dataset. A rather small number of redrawings is used, in actual empirical work a much larger number,
at least 1000 and up to 5000, is recommended.
Real money, real income and bond rate are found to cointegrate by an Engle-Granger test, hence the OLS residuals are stationary. However, they will
generally be weakly dependent, so that simple redrawing as carried out by the Gretl function "resample" cannot be applied, while block bootstrap as
carried out by "resample" with the optional "b" argument would be legitimate. However, the block bootstrap is not guaranteed to produce stationary
pseudo-residuals. This will have serious consequences in this context, see the comment below.
Reference:
Politis, D.N., J.P. Romano (1994) "The Stationary Bootstrap" Journal of the American Statistical Association, 89, 1303-1313.
*/
# run OLS with real money as dependent variable, real income and bond rate as explanatory variables.
list lx=LRY IBO
ols LRM 0 lx
bhat=$coeff
lrmh=$yhat
uh={$uhat}
# construct bootstrap pseudodata using rule-of-thumb block size, estimate model nboot times and store estimated coefficients in the matrix bb
matrix bb=zeros(nboot,$ncoeff)
loop boot=1..nboot --quiet
ub=SB(uh,0)
series ubs=ub[,1]
series lrmb=lrmh+ubs
/*
Note that since ubs is guaranteed to be stationary lrmb and lx cointegrate by construction. With the block bootstrap this is not true, and some
of the nboot regressions of lrmb on lx may be spurious
*/
ols lrmb 0 lx --quiet
bb[boot,]=$coeff'
endloop
# take percentiles of distribution of bootstrap estimates
bb05=quantile(bb,0.05)
bb95=quantile(bb,0.95)
print ""
print "******************************************************************************* "
print ""
printf "estimated coefficients %10.2f", bhat'
print ""
print "95% bootstrap confidence intervals"
print ""
printf "Lower limits %15.2f", bb05
printf "Upper limits %15.2f", bb95
print ""
print "******************************************************************************* "