【问题标题】:How to recode strings in Stata?如何在Stata中重新编码字符串?
【发布时间】:2021-04-26 09:12:19
【问题描述】:

我想更改我的国籍变量中的值。对于某些国家/地区,国家名称(“德国”和“德国”)后面有一个空格,因此在查看频率时它们看起来不是同一个国家。我尝试使用“编码”使值变为数字,以便我可以使用“重新编码”来更改值,但这给了我错误“规则中的未知 el Germany”。我附上了截图。 Screenshot of data

【问题讨论】:

    标签: string stata recode


    【解决方案1】:

    recode 仅用于数值变量,您可以使用replace

    replace Nationality = "Belgium" if Nationality == "Belgium "
    

    但是,解决手头问题的更方便的方法是strtrim(),它会删除前导和尾随空格。

    replace Nationality = strtrim(Nationality)
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多