string 如何在Stata中将字符串变量转换为数字变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17881054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert string variables to numeric variables in Stata?
提问by Exodia16
I have two variables in Stata, both numeric variables that have somehow been recorded as string variables. I need them converted to numeric variables so that I can generate a new variable with them.
我在 Stata 中有两个变量,这两个数字变量都以某种方式被记录为字符串变量。我需要将它们转换为数字变量,以便我可以用它们生成一个新变量。
When I tried, it said type mismatch
I have tried the real
and the encode
commands, none of which are working.
当我尝试时,它说type mismatch
我已经尝试了real
和encode
命令,但没有一个有效。
采纳答案by Metrics
Try destring var, replace
in Stata if you want to convert var
into numeric
destring var, replace
如果您想转换var
为数字,请尝试在 Stata 中
Or,
或者,
encode var, generate(var1)