Stata学习:如何构建融资融券标的变量?
文献来源
李志生等(2015)、Ni和Yin(2020)定义,如果时间t时某股票为融券标的,则Short取值1,否则取值0。注意,买空(多头交易)对应的是融资,卖空(空头交易)对应的是融券。
- 李志生,陈晨,林秉旋.卖空机制提高了中国股票市场的定价效率吗?——基于自然实验的证据[J].经济研究,2015,50(04):165-177.
- Ni, X., & Yin, S. (2020).The unintended real effects of short selling in an emerging market. Journal of Corporate Finance, 64, 101659.
数据来源
国泰安
- 下载表名 融资融券标的信息表(日)
- 数据区间
- 2010-03-29 至 2013-12-31
- ……
- 2018-01-01 至 2021-12-31
- 选择代码 全部代码
- 输出类型 Excel2007格式(*.xlsx)
- 选择字段 交易所代码[Exchangecode] 信用交易日期[Mtdate] 股票代码[Stockcode] 股票简称[Stockname] 可融资标识[Financeavailable] 可融券标识[Shortavailable]
清洗数据
cap pr drop A
pr def A
qui{
cd D:\Download
foreach var of var * {
label variable `var' "`=`var'[1]'"
replace `var' = "" if _n == 1
}
drop in 1/2
foreach var of var * {
cap destring `var', replace
}
}
end
********
loc j = 0
foreach i in 155206119 155340779 155409181{
import excel "D:\Download\融资融券标的信息表(日)`i'\CHN_Stkmt_dunderlyings.xlsx", sheet("sheet1") firstrow clear
A
loc ++j
save `j', replace
}
foreach i in 155409181{
import excel "D:\Download\公司公告事件表`i'\CHN_Stkmt_dunderlyings1.xlsx", sheet("sheet1") firstrow clear
A
loc ++j
save `j', replace
}
********
use 1, clear
forv x = 2/`j'{
append using `x'
}
tab Financeavailable Shortavailable,m
tab Exchangecode Financeavailable, m
tab Exchangecode Shortavailable, m
save 融资融券标的信息表, replace
得到:
| 可融券标识
可融资标识 | N Y | Total
----------------+----------------------+----------
N | 80 407 | 487
Y | 0 2,110,646 | 2,110,646
----------------+----------------------+----------
Total | 80 2,111,053 | 2,111,133
| 可融资标识
交易所代码 | N Y | Total
----------------+----------------------+----------
SHSE | 0 935,511 | 935,511
SZSE | 487 1,175,135 | 1,175,622
----------------+----------------------+----------
Total | 487 2,110,646 | 2,111,133
| 可融券标识
交易所代码 | N Y | Total
----------------+----------------------+----------
SHSE | 0 935,511 | 935,511
SZSE | 80 1,175,542 | 1,175,622
----------------+----------------------+----------
Total | 80 2,111,053 | 2,111,133
继续:
use 融资融券标的信息表, clear
g Short = (Short == "Y")
ren Stockcode Stkcd
g year = substr(Mtdate,1,4)
destring y, force replace
tab y Short
tab M if Short == 0
得到:
| Short
year | 0 1 | Total
-----------+----------------------+----------
2010 | 80 16,650 | 16,730
2011 | 0 25,860 | 25,860
2012 | 0 69,591 | 69,591
2013 | 0 130,914 | 130,914
2014 | 0 188,093 | 188,093
2015 | 0 222,804 | 222,804
2016 | 0 220,914 | 220,914
2017 | 0 236,227 | 236,227
2018 | 0 166,517 | 166,517
2019 | 0 212,434 | 212,434
2020 | 0 288,865 | 288,865
2021 | 0 332,184 | 332,184
-----------+----------------------+----------
Total | 80 2,111,053 | 2,111,133
信用交易日期 | Freq. Percent Cum.
-------------------+-----------------------------------
2010-03-29 | 40 50.00 50.00
2010-03-30 | 40 50.00 100.00
-------------------+-----------------------------------
Total | 80 100.00
数据有点奇怪。
补充数据
为此,本文另从锐思下载了数据:
- 融资融券标的证券 MTMARSSUDLSECU
- 数据开始日期 2010-02-12
- 数据结束日期 2022-11-01
- 总记录数 7,357
- 标的类别:10-融资买入标的;20-融券卖出标的
cd D:\Download
import excel "D:\Download\RESSET_MTMARSSUDLSECU_1.xlsx", sheet("MTMARSSUDLSECU") firstrow
ren 标的证券代码 Stkcd
ren 入 InDt
ren 剔 OutDt
ren 标的类别 Type
keep S I O T
destring S, force replace
su
d
list in 1/5
save 融资融券标的进出日期
得到:
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
Stkcd | 7,357 375527.1 263362.5 1 689009
Type | 7,357 15.01019 5.000329 10 20
InDt | 0
OutDt | 0
Contains data from 融资融券标的进出日期.dta
Observations: 7,357
Variables: 4 15 Dec 2022 09:11
----------------------------------------------------------------------
Variable Storage Display Value
name type format label Variable label
----------------------------------------------------------------------
Stkcd long %10.0g 标的证券代码_UdlSecuCd
Type byte %10.0g 标的类别_UdlCtgy
InDt str10 %10s 入选日期_InDt
OutDt str10 %10s 剔除日期_OutDt
----------------------------------------------------------------------
+-----------------------------------+
| Stkcd Type InDt OutDt |
|-----------------------------------|
1. | 1 20 2010-03-29 |
2. | 1 10 2010-03-29 |
3. | 2 20 2010-03-29 |
4. | 2 10 2010-03-29 |
5. | 6 20 2013-01-31 |
+-----------------------------------+
汇总为年度数据:
forv i = 10(10)20{
use 融资融券标的进出日期, clear
keep if T == `i'
g year0 = substr(I,1,4)
g year1 = substr(O,1,4)
destring year*, force replace
qui forv x = 2010/2022{
cap drop Year`x'
g Year`x' = 0
replace Year`x' = 1 if year1 == . & year0 <= `x'
replace Year`x' = 1 if year1 != . & year0 <= `x' & year1 >= `x'
}
gather Y*
drop year*
g year = substr(var,5,.)
destring y, force replace
keep S y val
order S y
sort S y
ren v v`i'
duplicates drop S y, force
save 融资融券_`i', replace
}
use 融资融券_10, clear
merge 1:1 S y using 融资融券_20, nogen keep(1 3)
ren v10 融资标的
ren v20 融券标的
su
tab *的
save 融资融券标的_锐思, replace
得到结果
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
Stkcd | 45,344 375409.4 263397.7 1 689009
year | 45,344 2016 3.741699 2010 2022
融资标的 | 45,344 .3360312 .4723549 0 1
融券标的 | 45,344 .3362738 .4724391 0 1
融资标 | 融券标的
的 | 0 1 | Total
-----------+----------------------+----------
0 | 29,772 335 | 30,107
1 | 324 14,913 | 15,237
-----------+----------------------+----------
Total | 30,096 15,248 | 45,344
(完)