Dear Statalisters,
I use foreach and forvalues often in my syntax and now I want to call globals consecutively, but I do have a problem with that (using Stata 14). Let me first explain briefly what I want to do (without using data). My most simple code running normally is:
Next, use code to loop from 1 to 3, and display it:
Which leads to the code that I thought would do the same so that the string of each global is displayed:
But that does not happen, I now only get the numbers:
1
2
3
Probably this is a awfully simple error, but I fail to solve it. Where did the string [$vars] go? I mean, if this code is wrong, why does it not generate an error?
And, does anyone know how to code properly so that multiple globals can be used consecutively in a forvalues loop (e.g. for running regressions, generating graphs)?
I use foreach and forvalues often in my syntax and now I want to call globals consecutively, but I do have a problem with that (using Stata 14). Let me first explain briefly what I want to do (without using data). My most simple code running normally is:
Code:
global vars1 "var1 var2 var3 var4" global vars2 "var5 var6 var7 var8" global vars3 "var9 var10 var11 var12" // display the strings in Stata result window: dis "$vars1" dis "$vars2" dis "$vars3"
Code:
forvalues i = 1/3 { dis `i' }
Code:
forvalues i = 1/3 { dis "$vars`i'" }
1
2
3
Probably this is a awfully simple error, but I fail to solve it. Where did the string [$vars] go? I mean, if this code is wrong, why does it not generate an error?
And, does anyone know how to code properly so that multiple globals can be used consecutively in a forvalues loop (e.g. for running regressions, generating graphs)?
Comment