1

How can I use local macros in the names of global macros in Stata 14?

For example:

global test1 = 250
local n = 1

. di $test1 // works
250

. di $test`n' // does not work (should be 250 and not 1)
1
Andreas
  • 33
  • 4
  • If you found my answer helpful, please consider up-voting it using the upper arrow. –  Sep 04 '18 at 14:03

1 Answers1

1

The 18 Programming Stata Manual explains:

"...You can mix global and local macros. Assume that local macro j contains 7. Then, ${x`j’} expands to the contents of $x7..."

So you just need to use curly brackets {} in your global macro:

. global test1 = 250
. local n = 1

. display $test1
250

. display ${test`n'}
250