Stata:在宏中检索变量标签
Stata: Retrieve variable label in a macro
我正在使用 do-file 为多个变量生成图表,我希望能够检索变量标签(以便我可以将其用于图表标题)。
在我的梦里,是这样的:
sysuse auto, replace
local pricelabel = varlab(price)
display "Label for price variable is `pricelabel'"
这会(在我的梦想中)产生:
Label for price variable is Price
我查看了 describe、summarize 和 labels 部分的文档,但似乎找不到解决方案。
查看local/global宏扩展功能的帮助文件:help extended_fcn
(其中extended_function
是variable label varname
[你要求的]或value label varname
[不是你要求的,但可能有用])。 例如:
sysuse auto, clear
local x : variable label foreign
local y : value label foreign
di "`x'"
di "`y'"
returns
. sysuse auto, clear
(1978 Automobile Data)
. local x : variable label foreign
. local y : value label foreign
. di "`x'"
Car type
. di "`y'"
origin
我正在使用 do-file 为多个变量生成图表,我希望能够检索变量标签(以便我可以将其用于图表标题)。
在我的梦里,是这样的:
sysuse auto, replace
local pricelabel = varlab(price)
display "Label for price variable is `pricelabel'"
这会(在我的梦想中)产生:
Label for price variable is Price
我查看了 describe、summarize 和 labels 部分的文档,但似乎找不到解决方案。
查看local/global宏扩展功能的帮助文件:help extended_fcn
(其中extended_function
是variable label varname
[你要求的]或value label varname
[不是你要求的,但可能有用])。 例如:
sysuse auto, clear
local x : variable label foreign
local y : value label foreign
di "`x'"
di "`y'"
returns
. sysuse auto, clear
(1978 Automobile Data)
. local x : variable label foreign
. local y : value label foreign
. di "`x'"
Car type
. di "`y'"
origin