stata - 将 Stata 变量标签中的 $ 替换为\textdollar

标签 stata

我的变量标签中有一些带有美元符号(即 $)的变量。这会导致我的代码下游出现一些问题(我后来修改了这些标签并将美元符号取消注册为空全局宏)。所以我想使用 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/

相关文章:

Stata 从字符串中删除整个单词

stata - Stata 中的数组/向量等价物

r - 在矩阵中查找公共(public)链接并通过公共(public)交集进行分类

date - 为特定日历日创建虚拟变量

stata - 按变量散点图颜色

stata - 如何创建从 1 到 n(增量为 1)的变量?

r - 将 R 文件转换为缺少字符串值的 Stata

stata - 你如何在 Stata 中使用 margins 命令存储边际效应?

string - 在 R 中循环图形的字符串向量

mysql - 将数据从 MySql 导入到 Stata