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:
Code:
clear all
sysuse auto.dta
gen tax = 0
forvalues y = 0(1)10 {
replace tax = `y'
// other code...
}
And now i want to make it more flexible by changing the lower, sensitivity and upper bounds of the forvalues loop:
Code:
sysuse auto.dta
gen tax = 0
global low = 0
global sensitivity = 1
global high = 10
forvalues y = ${low}(${sensitivity})${high} {
replace tax = `y'
}
However, when i run this i get an error saying:
program error: code follows on the same line as open brace
Why am I getting this error and how do i fix it?
0 Response to Using global variables within forvalue loops
Post a Comment