全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
50193 43
2015-07-30
我在STATA14中打开一个数据文件,结果是乱码。然后我用unicode analyze 对其进行分析,结果说该文件需要进行 unicode translate。于是用该命令对其进行转换,结果出现如下结果:
2 variable labels okay, ASCII
        0 variable labels okay, already UTF-8
      239 variable labels cannot be translated
      all str# variables okay, ASCII
          --------------------------------------------------------------------------------------
          File not translated because it contains unconvertable characters;
             you might need to specify a different encoding, but more likely you need to run
             unicode translate with the invalid option

  File 000004.dta still needs translation

  File summary:
      all files not translated because they contain unconvertable characters;
             you might need to specify a different encoding, but more likely you need to run
             unicode translate with the invalid option
结果是说所有文件都没被转换,原因是包含不可转换的字母。如果添加invalid选项,那么所有标签仍然是怪异的符号。请路过的高人指点一下,原因何在?谢谢!

二维码

扫码加我 拉你入群

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

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

全部回复
2015-7-30 14:16:44
这个问题我自己已经解决。关键是要设对需要转换文件的原始编码类型。例如,如果原始数据中变量标签为中文,用stata14打开时,变量标签无法识别。此时,需要设定编码类型。命令为 unicode encoding set gb18030,即设定编码类型为国标18030,即简体中文。然后,用unicode analyze filename.dta 分析文件是否需要转换,如结果为需要,那么继续用unicode translate filename.dta来转换数据文件中不可识别的中文汉字。成功以后,原始数据中不能识别的中文则可以在stata14中识别了。
二维码

扫码加我 拉你入群

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

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

2015-9-26 11:53:04
adamesky 发表于 2015-7-30 14:16
这个问题我自己已经解决。关键是要设对需要转换文件的原始编码类型。例如,如果原始数据中变量标签为中文, ...
楼主,问下分析完如何从14的do文档修改为13可以看的。
二维码

扫码加我 拉你入群

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

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

2015-9-26 21:53:32
stata13变成stata14现在可以实现
反过来不行

所以,如果要有14就全部用stata14
不要stata13和stata14混用
二维码

扫码加我 拉你入群

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

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

2015-12-12 17:50:12
adamesky 发表于 2015-7-30 14:16
这个问题我自己已经解决。关键是要设对需要转换文件的原始编码类型。例如,如果原始数据中变量标签为中文, ...
楼主,问一下,如果是变量中的中文怎么办? 如国家名什么的 谢谢
二维码

扫码加我 拉你入群

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

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

2016-1-23 22:13:35

cd "D:\long term care\CHARLS\stata\data\household_and_community_questionnaire_data" 【先设置你的working directory】unicode analyze psu.dta  (Directory ./bak.stunicode created; please do not delete)  File summary (before starting):        1  file(s) specified        1  file(s) to be examined ...  File psu.dta (Stata dataset)        2 str# variables need translation          ----------------------------------------------------------------------------------------------------------          File needs translation.  Use unicode translate on this file.  File psu.dta needs translation  File summary:        1 file(s) need translation【总结:Stata告诉你,你这个file需要转换】unicode encoding set "GB18030"   (default encoding now GB18030)【这里是告诉Stata这数据本来的unicode encoding是怎么样的,我死活找不到CHARLS的unicode encoding,后来在国外网站说中文一般用GB18030都可以,就试了试。之前我还用过据说很常用的Windows-1252,但在这里没有用!!!】unicode retranslate psu.dta, transutf8  (using GB18030 encoding)  File summary (before starting):        1  file(s) specified        1  file(s) to be examined ...  File psu.dta (Stata dataset)      all variable names translated      all data labels translated      all variable labels translated      all value-label names translated      all value-label contents translated      all characteristic names translated      all characteristic contents translated      all str# variables translated          ----------------------------------------------------------------------------------------------------------          File successfully translated  File summary:      all files successfully translated【这里就是让Stata把数据转换为支持中文的UTF-8,转换完毕后,检查数据,中文终于不是乱码了,大功告成!】如果要一次性搞定不止多个数据库,也可以尝试:unicode analyze *unicode encoding set "GB18030"unicode retranslate *, transutf8这样你working directory里的所有数据库都被一次性转换完成了。如果出了问题,也没有关系。反正转换完成之后,还可以使用以下命令来恢复或者调整。unicode restore filespec 或者unicode retranslate filespec
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群