代码拉取完成,页面将自动刷新
同步操作将从 连享会/readWind 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
*===============================================================================
* Program: readWind.ado
* Purpose: Reading data download from the wind into stata in a cleaning format
* Version: 2.0 (2019/04/13)
* Author: Devin Chu
* Website: http://www.github.com/zhbsis/readWind
*===============================================================================
capture program drop readWind
program define readWind
version 14.0
syntax namelist(min=1), key(str) timeType(str) t0(str) tn(str) [type(str) sheet(integer 1) encoding(str) tostring]
//1 readFile
local n=wordcount("`namelist'")
readFile, key(`key') type(`type') sheet(`sheet') encoding(`encoding') `tostring'
//2 tokenize
local var ""
foreach tempVar of varlist _all{
local var "`var' `tempVar'" //
}
tokenize `var' //
local first `1' `2' //
macro shift 2 //
local rest `*' //
/*rename stkcd comp*/
rename (`first') (stkcd comp)
local i=1
foreach var in `rest'{
rename `var' x`i'
local i=`i'+1
}
fastreshape long x, i(stkcd) j(time)
//3 if function
gen date=.
gen var=.
if("`timeType'"=="y"){
local t0=`t0'
local tn=`tn'
local dif = `tn'-`t0'+1
}
if("`timeType'"=="q"){
local t0=q(`t0')
local tn=q(`tn')
local dif = `tn'-`t0'+1
}
if("`timeType'"=="m"){
local t0=m(`t0')
local tn=m(`tn')
local dif = `tn'-`t0'+1
}
if("`timeType'"=="d"){
local t0=date("`t0'","YMD")
local tn=date("`tn'","YMD")
local dif = `tn'-`t0'+1
}
//4 main function
forvalues i=1(1)`n'{
local low = 1+(`i'-1)*`dif'
local up = `dif'+(`i'-1)*`dif'
local j=`i'-1
qui bys stkcd: replace date = `t0' + _n - 1 - `j'*`dif' if time <= `up' & time >= `low'
qui replace var=`i' if time <= `up' & time >= `low'
}
//5 format time index
if("`timeType'"=="q"){
format date %tq
}
if("`timeType'"=="m"){
format date %tm
}
if("`timeType'"=="d"){
format date %td
}
//6 reshape and cleaning
qui drop if stkcd=="" | stkcd=="数据来源:Wind"
qui gen stkcd_date=stkcd+"_"+string(date)
qui fastreshape wide x, i(stkcd_date) j(var)
qui drop time stkcd_date
qui order stkcd comp date
//7 rename
local i=1
foreach var in `namelist'{
qui rename x`i' `var'
local i=`i'+1
qui label var `var' ""
}
end
*cd "K:\readWind\"
*readWind ROA roe, key(ROA) timeType(q) t0(1995q1) tn(2017q4)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。