Chapter 10. Loop constructs

Table of Contents
Introduction
Loop control variants
Progressive mode
Loop examples

Introduction

The command loop opens a special mode in which gretl accepts a block of commands to be repeated one or more times. This feature is designed for use with Monte Carlo simulations, bootstrapping of test statistics, and iterative estimation procedures. The general form of a loop is:


      loop control-expression [ --progressive | --verbose ]
         loop body
      endloop

Five forms of control-expression are available, as explained below. In the loop body the following commands are accepted: genr, ols, print, printf, pvalue, sim, smpl, store, summary, if, else and endif.

By default, the genr command operates quietly in the context of a loop (without printing information on the variable generated). To force the printing of feedback from genr you may specify the --verbose option to loop.

The --progressive option to loop modifies the behavior of the commands ols, print and store in a manner that may be useful with Monte Carlo analyses (see the Section called Progressive mode).

The following sections explain the various forms of the loop control expression and provide some examples of use of loops.

Tip: If you are carrying out a substantial Monte Carlo analysis with many thousands of repetitions, memory capacity and processing time may be an issue. To minimize the use of computer resources, run your script using the command-line program, gretlcli, with output redirected to a file.