【问题标题】:Stata: Retrieve variable label in a macroStata:在宏中检索变量标签
【发布时间】:2015-06-09 13:42:34
【问题描述】:

我正在使用 do 文件为多个变量生成图表,我希望能够检索变量标签(以便我可以将其用作图表标题)。

在我的梦想中,类似这样的事情:

sysuse auto, replace
local pricelabel = varlab(price)
display "Label for price variable is `pricelabel'"

这会(在我的梦中)产生:

Label for price variable is Price

我查看了描述、总结以及标签部分的文档,但似乎找不到解决方案。

【问题讨论】:

    标签: variables stata labels


    【解决方案1】:

    有关本地/全局宏的扩展功能,请参阅帮助文件:help extended_fcn(其中extended_functionvariable label varname [您要求的] 或value label varname [不是您要求的,但可能有用])。 例如

    sysuse auto, clear
    local x : variable label foreign
    local y : value label foreign
    di "`x'"
    di "`y'"
    

    返回

    . sysuse auto, clear
    (1978 Automobile Data)
    
    . local x : variable label foreign
    
    . local y : value label foreign
    
    . di "`x'"
    Car type
    
    . di "`y'"
    origin
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-10
      • 2019-02-10
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多