日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stata15中文乱码_一次性解决Stata中文乱码问题

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stata15中文乱码_一次性解决Stata中文乱码问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在導入Stata時可能存在中文亂碼問題,在stata15中可以通過unicode來解決:

help unicode

按照help文檔,核心的轉碼步驟其實就三步

但是僅按照help文檔無法對文檔進行批量處理,而下載的數據中大多有多個需要轉碼的文件。對此,連老師已經寫了ua程序來解決。不過ua程序仍然需要兩步,為了進一步簡化流程,想達到只需要告訴文件夾路徑,就轉碼文件夾下面所有文件的效果,嘗試參照ua命令寫了如下的程序供大家參考,冒昧叫uaone吧。

使用方法如下:

uaone, d("E:\數據") // 默認轉碼為gb18030

* 如果需要對特定的.dta文件類型進行編碼

uaone, d("E:\數據") f(dta)

* 采用其他編碼類型

uaone, d("E:\數據") set(ibm-1392)

源代碼如下,由于沒有發布,需要大家把代碼copy到Stata的"Do-file"里面運行一次,然后就可以正常使用啦。

使用過程中肯定存在很多bug,請多多賜教。。。

cap program drop uaone

program uaone

version 13.0

syntax [anything(everything)], Direction(string asis) [set(string asis) RETRanslate ///

TRansoption(string asis) Filetype(string asis)]

/*

Direction: Direction of the folder containing ".dta" files needing translation.

set: Set an encoding type. Please type "unicode encoding list" for details.

TRansoption: Options of "encoding translate", including "invalid(escape|mark|ignore)"

"transutf8" "nodata" "replace (only when "reranslate" is specified)".

RETRanslate: To do "unicode retranslate"

Filetype: Default is to translate all file types.

*/

preserve

clear

*test

capture cd `direction'

if _rc != 0{

di as error ///

"Unable to load the directions. Please double check the {bf:direction} you entered."

exit 111

}

*Options settings

local currdir `c(pwd)'

local set gb18030

local option

local transchoice "translate"

local file "*"

if "`transoption'"!= ""{

local option "`transoption'"

}

if "`set'"!=""{

local setting "`set'"

}

if `"`retranslate'"'!=`""'{

local transchoice "retranslate"

}

if `"`filetype'"'!=`""'{

local file "*.`filetype'"

}

di in w _dup(35) "="

di "{it: Translate Start}"

di in w _dup(35) "="

di _n(1)

di in w "Files in the following directories"

di in w "are to be analyzed or translated:"

cap ssc install rcd

rcd // get the list of all sub-directories

forvalues i = 1(1)`r(tdirs)'{

local dir`i' `"`r(ndir`i')'"'

}

di _n

di in w _dup(35) "-"

di "translating"

di in w _dup(35) "-"

forvalues i = 1(1)`r(tdirs)'{

qui cd `"`dir`i''"'

local filename: dir . files "`file'",respectcase

if `"`filename'"' != ""{

foreach fn of local filename{

qui unicode encoding set "`set'"

qui unicode `transchoice' `"`fn'"',`option'

di _n

di "■" _s(2) `"`fn' {it:`transchoice' completed}"'

}

}

else{

continue

}

}

di _n(1)

di in w _dup(35) "="

di "{it: Translation Completely}"

di in w _dup(35) "="

restore

qui cd `currdir'

end

總結

以上是生活随笔為你收集整理的stata15中文乱码_一次性解决Stata中文乱码问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。