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中文乱码问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ad中电容用什么封装_用什么来降低噪声?
- 下一篇: 【软件开发底层知识修炼】二十五 ABI之