在全局宏的名称中使用局部宏

Using local macros in names of global macros

如何在 Stata 14 的全局宏名称中使用局部宏?

例如:

global test1 = 250
local n = 1

. di $test1 // works
250

. di $test`n' // does not work (should be 250 and not 1)
1

18 Programming Stata 手册说明:

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

所以你只需要在你的全局宏中使用花括号{}:

. global test1 = 250
. local n = 1

. display $test1
250

. display ${test`n'}
250