I have always been believing that using {} around global macros is a good practice until I encountered this issue. I feel this is a bug that Stata should correct.
An example: running
global numcohort 3
global numperiod 2
forvalues g = 1(1)${numcohort}{
forvalues t = 1(1)${numperiod} {
di "text"
}
}
would lead to the error message program error: code follows on the same line as open brace
Dropping the {} around numcohort will make the codes work. My guess is that the outmost forvalues interpret the first { it detects as the beginning of the commands for loop. Interestingly, the braces around numperiod does not cause any problem. This inconsistency is why I think the issue is a bug. But I am no expert in developing programing.
An example: running
global numcohort 3
global numperiod 2
forvalues g = 1(1)${numcohort}{
forvalues t = 1(1)${numperiod} {
di "text"
}
}
would lead to the error message program error: code follows on the same line as open brace
Dropping the {} around numcohort will make the codes work. My guess is that the outmost forvalues interpret the first { it detects as the beginning of the commands for loop. Interestingly, the braces around numperiod does not cause any problem. This inconsistency is why I think the issue is a bug. But I am no expert in developing programing.
Comment