可以使用命令'tostring' 将数值型变量转换为文本型变量。

语法:

tostring varname [, format(string) replace]

其中,'varname' 是要转换的变量名,'format' 是可选的参数,用于指定文本格式。

示例:

将数值型变量'age' 转换为文本型变量,并将其存储在新变量'age_str' 中:

tostring age, gen(age_str)

将数值型变量'income' 转换为文本型变量,并用'$' 符号表示货币格式:

tostring income, format('$%9.0fc') gen(income_str)

Stata 中如何将数值型变量转换为文本型变量

原文地址: https://www.cveoy.top/t/topic/l0xm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录