楼主: hkingwang
11668 9

[数据管理求助] 为什么stata中有的变量把中文名字改成英文名字正常,有的却显示invalid name? [推广有奖]

  • 1关注
  • 0粉丝

博士生

38%

还不是VIP/贵宾

-

威望
0
论坛币
6515 个
通用积分
11.0427
学术水平
5 点
热心指数
0 点
信用等级
0 点
经验
2106 点
帖子
63
精华
0
在线时间
397 小时
注册时间
2014-2-26
最后登录
2023-10-9

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
为什么stata中有的变量把中文名字改成英文名字正常,有的却显示invalid name?
比如 变量“_社区(居委会)”可以改成英文,但是“邮政编码”就不可以
貌似和变量前面带不带下划线有关系
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:invalid Valid Stata 中文名字 英文名字 英文名字 中文名字 invalid

沙发
黃河泉 在职认证  发表于 2017-5-2 10:18:24 |只看作者 |坛友微信交流群
请把指令与错误讯息完整写出来,以供判断!

使用道具

藤椅
蓝色 发表于 2017-5-2 12:02:30 |只看作者 |坛友微信交流群
第一个字符 不能是汉字, 所以后续许多操作无法进行。检验还是先在excel里面改成字母,然后在在stata中运行

看stata中的命名规则
Title

    varname (from [U] 11.4 varlists)


Description

    A varname is one variable name, such as

        x
        myvar
        Myvar
        inc92
        ausl渀搀椀猀挀栀
        reciprocal_of_miles_per_gallon
        _odd
        _1994

    When we use the term varname, we usually mean an existing varname -- a variable that
    already exists in the dataset.  The alternative would be a newvar.

    When referring to an existing varname, we can abbreviate -- use only some of the leading
    characters -- as long as we specify enough to uniquely identify the variable:

        Myv might be a unique abbreviation for Myvar.

        reciprocal might be a unique abbreviation for reciprocal_of_miles_per_gallon.

    Sometimes we can use the full varlist notation, but it must identify one variable:

        my*r might uniquely identify myvar

        r*gallon might uniquely identify reciprocal_of_miles_per_gallon.

    In the varlist notation, * means that zero or more characters go here.

    Varnames are often specified inside options, and then sometimes the varlist notation is
    allowed and sometimes it is not.  Abbreviations are always allowed, however, assuming
    that you have not turned them off; see set varabbrev.

    Note that variable names may be 1 to 32 Unicode characters long and must start with a
    Unicode letter or _, and the remaining characters may be Unicode letters, _, or Unicode
    number digits.  Examples of Unicode letters are "a", "Z", and "é"; examples of Unicode
    digits are 0, 1, and 9.

    The formal definition of a Unicode letter is a Unicode character for which uisletter()
    returns 1.  A Unicode digit is a Unicode character for which uisdigit() returns 1.

    An invalid UTF-8 sequence is allowed in the variable name and is counted as one
    character.  This is mainly for backward compatibility reasons.  For example, capital
    letter "E" with a grave accent is encoded as char(200) in ISO-Latin-1 encoding, which
    may appear in variable names of older versions of Stata, but char(200) alone is an
    invalid UTF-8 sequence.  See [U] 12.4.2.6 Advice for users of Stata before version 14
    for details.



使用道具

板凳
jianggenghua 发表于 2017-6-19 09:51:23 |只看作者 |坛友微信交流群
解决了吗?我也遇到同样的问题了

使用道具

报纸
黃河泉 在职认证  发表于 2017-6-19 09:59:59 |只看作者 |坛友微信交流群
jianggenghua 发表于 2017-6-19 09:51
解决了吗?我也遇到同样的问题了
我用的 Stata 14.2,是可以 rename 的!
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input str20(_社区(居委会) 邮政编码)
  4. "1" "2"
  5. "3" "4"
  6. end

  7. ren _社区(居委会) x1
  8. ren 邮政编码 x2

  9. list
复制代码
结果为
  1. . list

  2.      +---------+
  3.      | x1   x2 |
  4.      |---------|
  5.   1. |  1    2 |
  6.   2. |  3    4 |
  7.      +---------+
复制代码

使用道具

地板
jianggenghua 发表于 2017-6-19 21:27:12 |只看作者 |坛友微信交流群
黃河泉 发表于 2017-6-19 09:59
我用的 Stata 14.2,是可以 rename 的!结果为
请问state13有方法解决吗

使用道具

7
黃河泉 在职认证  发表于 2017-6-20 06:50:26 |只看作者 |坛友微信交流群
jianggenghua 发表于 2017-6-19 21:27
请问state13有方法解决吗
这我就不知道了!

使用道具

8
Cloud_Snake 学生认证  发表于 2017-6-20 15:33:11 |只看作者 |坛友微信交流群
之前的版本只有数据导出重来一遍,你ren个中文名他不认识

使用道具

9
hkingwang 发表于 2017-7-6 16:38:02 |只看作者 |坛友微信交流群
蓝色 发表于 2017-5-2 12:02
第一个字符 不能是汉字, 所以后续许多操作无法进行。检验还是先在excel里面改成字母,然后在在stata中运行
...
多谢!!!

使用道具

10
hkingwang 发表于 2017-7-6 16:39:00 |只看作者 |坛友微信交流群
黃河泉 发表于 2017-6-20 06:50
这我就不知道了!
貌似只能stata14可以,13的话只能导出来

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 08:40