天天看點

文章2021_01_05_stata15在mac上的dta編碼問題和系統crash

stata15

macos 10.15.3

問題:無法unicode中文的dta資料,unicode invalid option時,出現系統crash

解決: 值标簽損壞導緻的crash, 區分标簽和内容分别轉碼。

https://www.statalist.org/forums/forum/general-stata-discussion/general/1488060-stata-15-crashes-when-using-unicode-translate

We have two users reporting the similar issue. Both are caused by the original dataset contains corrupted value label(s). The dataset works fine when the particular value label(s) are not used. But when -unicode translate- or other Stata commands try to use the corrupted value label(s), it will potentially crash Stata. 

To work around it, you may do the following, 

Code:

// I use test.dta as an example

// first we would like to save all value labels in test.dta to a do-file mylab.do
use "test.dta", clear
label save  _all using  mylab, replace

// then we drop all value labels from the dataset, and save the new dataset as test2.dta
label drop _all
save test2.dta, replace

// now we can translate test2.dta
clear
unicode encoding set gb18030
unicode translate "test2.dta", invalid(mark) transutf8

// now we translate the mylab.do
clear
unicode encoding set gb18030
unicode translate mylab.do, invalid(ignore)

// now we can re-attach value labels
use "test2.dta", clear
do mylab.do
           

Now test2.dta contains translated dataset with fixed value labels, Please email Stata tech support at [email protected] with the dataset attached if the problem persists.

# 據稱,stata14後的資料采用了unicode編碼,是以除了上面的crash問題,還有低版本和高版本資料的轉化問題,如stata5-12和stata13,stata14及以上之間的轉化問題。

首先,分析一下檔案編碼是必要的,如果确定原始檔案的編碼是gb18030,可以set。

gb18030,gb2312,GBK。

cd ...

unicode analyze test.dta

unicode encodinng set gb18030

unicode translate test.dta

https://www.bilibili.com/video/BV1pa4y1j7eF/?spm_id_from=trigger_reload

未解決的問題:stata中的科學計數數值轉到r中時,會變成字元。