我的变量标签中有一些带有美元符号(即 $
)的变量。这会导致我的代码下游出现一些问题(我后来修改了这些标签并将美元符号取消注册为空全局宏)。所以我想使用 Stata 的 subinstr()
函数用 LaTeX 的 \textdollar
替换这些美元符号。
但是我想不通。这可能吗?或者我应该放弃更多地手动执行此操作?或者通过在变量标签中的 $
附近或周围查找其他字符?
clear
set obs 10
generate x = runiform()
label variable x "Label with $mil"
generate y = runiform()
label variable y "Another label with $mil"
describe
foreach v of varlist * {
local name : variable label `v'
local name `=subinstr("`name'", "$mil", "\textdollar", .)'
label variable `v' "`name'"
}
describe
这会完全删除标签。
最佳答案
您在 subinstr()
中缺少一个参数,在 help
中显示为 n
:
clear
set obs 10
generate x = runiform()
label variable x "Label with $"
local name: variable label x
local name = subinstr("`name'", "$", "\textdollar", .)
label variable x "`name'"
describe
关于stata - 将 Stata 变量标签中的 $ 替换为\textdollar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27504133/