Indexed loop

The third form of loop construct offered in gretl is an indexed loop, using the internal variable i. You specify starting and ending values for i, which is incremented by one each time round the loop. The syntax looks like this: loop i=1..20. Example 7-3 shows one use of this construct. We have a panel data set, with observations on a number of hospitals for the years 1991 to 2000. We restrict the sample to each of these years in turn and print cross-sectional summary statistics for variables 1 through 4.

Example 7-3. Indexed loop example


	  open hospitals.gdt
	  loop for i=1991..2000
	    smpl -r (year=i)
	    summary 1 2 3 4
	  endloop