Hi Statalist

I would like to run a loop for every value within a variable called "spell_count", and then run the whole do.file as a loop for different datasets, where the range for "spell_count" changes.

In file one the range is 1 - 82. So I can run

forvalues n = 1(1)82 {

if spell_count == `n' (etc etc)

}

but as the range in spell count changes across datasets, I would like to specify the range as a local, and then use this within the for values command.

I can define the range using a local, but then get an error when I put this in to forvalues:

quitetly sum spell_count
local max = `r(max)'
local min = `r(min)'

forvalues n = `min'(1)`max' {

if spell_count == `n' (etc etc)

}

Does anyone know what I am doing wrong?

Best Wishes

Joe