RATS 11.1
RATS 11.1

Monte Carlo Integration, Gibbs Sampling and related methods assume data have a known distribution and make random draws from it. By contrast, bootstrapping and other resampling techniques reshuffle an existing set of numbers and thus do not make a specific assumption about the distributiion of those numbers. The key instruction is BOOT, which draws a random set of integers. By default, BOOT draws with replacement, but with the option NOREPLACE will do the draws without replacement.

 

A draw of random integers will give you the entry numbers you need to sample from a data set. You then use SET instructions to generate the resampled data. For instance, the following draws entry numbers between 1950:1 and 2017:12 (the estimation range) and puts them into 2018:1 to 2018:12 of the SERIES[INTEGER] named ENTRIES. The series PATH1, PATH2 and PATH3 will then be random samples from RESIDS1, RESIDS2 and RESIDS3 over 1950–2017. Note that the three residual series are sampled together. The resampling thus retains any contemporaneous relationship that is present in the data set.

 

group  model5 x1eq>>fx1 x2eq>>fx2 x3eq>>fx3 x4id>>fx4 x5id>>fx5

smpl 2018:1 2018:12

do draw=1,ndraws

   boot  entries / 1950:1 2017:12           

   set path1 = resids1(entries)

   set path2 = resids2(entries)

   set path3 = resids3(entries)

   forecast(model=model5,paths)

   # path1 path2 path3

   ... bookkeeping ...

end do draw

smpl

 

If you have a single equation, and just want a simple bootstrap based upon the residuals, you can use UFORECAST with the BOOTSTRAP option. For instance, in the example above, if we just wanted to bootstrap X1EQ, we could just do

 

do draw=1,ndraws

   uforecast(boot,equation=x1eq) fx1 2018:1 2018:12

   ... bookkeeping ...

end do draw

 

Bootstrapping can be used many different ways:

It can be used to do simulate the distribution of a test statistic in a particular sample.

It can be used to simulate the distribution of out-of-sample forecasts by randomly drawing residuals from the estimation period.

It can be used to estimate the moments or distribution of an estimator.

 

In all of these cases, there is an analogous calculation which uses random draws from an assumed distribution (typically Normal or Student-t). For instance, Monte Carlo Integration for a Vector Autoregression generates draws for the coefficients and covariance matrix of a VAR assuming Normal residuals. Bootstrapping doesn't assume the residuals have any particular distribution.

 

 In addition to the BOOT instruction, there are several functions which choose a random integer or set of integers.

%raninteger(l,u)

draws an integer uniformly from \(\{ l,l + 1, \ldots ,u\} \)

%ranpermute(n)

returns a VECTOR[INTEGER] with a random permutation (ordering) of the numbers {1,...,n}

%rancombo(n,k)

returns a VECTOR[INTEGER] with a random combination of k values from {1,...,n} drawn without replacement.

%ranbranch(p)

returns a randomly selected “branch” from {1,...,dim(p)} where p is a VECTOR giving the (relative) probabilities of the different branches.

 

For instance, the following draws a “poker hand”, a combination of 5 numbers from 1 to 52:

 

compute cards = %rancombo(52,5)

 

If PPOST is an n–vector with relative probabilities of a “break” at a given location in the interval LOWER and LOWER+N-1, then

 

compute break = %ranbranch(ppost)+lower-1

 

will choose a random break point in that range with probabilities weighted according to the values in PPOST.


Copyright © 2026 Thomas A. Doan