I am trying to design a for loop that can be easily adapted for the input values but cannot work out a way to use global variables within my for loop. I have developed a very simple example to help isolate the problem. Essentially, this is the basic code:
And now i want to make it more flexible by changing the lower, sensitivity and upper bounds of the forvalues loop:
However, when i run this i get an error saying:
Why am I getting this error and how do i fix it?
Code:
clear all sysuse auto.dta gen tax = 0 forvalues y = 0(1)10 { replace tax = `y' // other code... }
Code:
sysuse auto.dta gen tax = 0 global low = 0 global sensitivity = 1 global high = 10 forvalues y = ${low}(${sensitivity})${high} { replace tax = `y' }
program error: code follows on the same line as open brace
Comment