券商的名称在数据库的记录中并不统一,很多公司有很多名称,并不利于统一管理。
本文的程序用于处理CSMAR数据库中分析师评级数据下券商名称字段。
/*##############################################################################
*函数名称: BankNameSimplify
*函数功能: 简化券商名称 具体包括:
1)剔除非券商公司;2)券商名改为简称 3)默认保留全部变量,
增加变量后的新文件驻留内存
*函数参数: 1)Broker - 确定数据中券商名称变量(对应varlist)
* 2)NewBroker - 新的变量名 (对应newvar)
* 3)新文件存放的位置
*函数返回值:无
*
*作者:financexx
*修改记录
*编号 日期 修改内容
*------------------------------------------------------------------
*1 2015-06-15 1st version
*
*#############################################################################*/
capture program drop BankNameSimplify
program define BankNameSimplify,rclass
version 14
syntax varname(string) ,generate(string)
*生成新变量
gen `generate' = `varlist'
*Step1:剔除信托、保险、银行
disp "Step1"
drop if strpos(`generate',"信托")|strpos(`generate',"保险")|strpos(`generate',"银行")
drop if (strpos(`generate',"资产管理公司")|strpos(`generate',"财务公司")|strpos(`generate',"投资公司")|strpos(`generate',"财务管理")|strpos(`generate',"投资咨询"))
drop if strpos(`generate',"证券部")
drop if !strpos(`generate',"证券")
disp "Step1 end"
*
*Step2: 简化证券公司名称
disp "Step2"
replace `generate' = subinstr(`generate',"经济特区","",.)
replace `generate' = subinstr(`generate',"证券有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券股份有限公司","证券",.)
replace `generate' = subinstr(`generate',"证券股份有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券经纪有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券有限公司","证券",.)
replace `generate' = subinstr(`generate',"有限证券公司","证券",.)
replace `generate' = subinstr(`generate',"有限股份公司","证券",.)
replace `generate' = subinstr(`generate',"证券研究所有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券经纪有限公司","证券",.)
replace `generate' = subinstr(`generate',"证券承销保荐有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券承销保荐有限公司","证券",.)
replace `generate' = subinstr(`generate',"证券有限公司","证券",.)
replace `generate' = subinstr(`generate',"证券研究所有限责任公司","证券",.)
replace `generate' = subinstr(`generate',"证券经纪有限公司","证券",.)
replace `generate' = subinstr(`generate',"投资资讯有限公司","",.)
replace `generate' = subinstr(`generate',"证券公司","证券",.)
replace `generate' = subinstr(`generate',"股份有限公司","",.)
replace `generate' = subinstr(`generate',"(集团)","",.)
replace `generate' = subinstr(`generate',"(集团)","",.)
*
*Step 3: 简化地域名称
replace `generate' = subinstr(`generate',"省证券","证券",.)
replace `generate' = subinstr(`generate',"市证券","证券",.)
replace `generate' = subinstr(`generate',"宁夏回族自治区","宁夏",.)
replace `generate' = subinstr(`generate',"新疆维吾尔自治区","新疆",.)
replace `generate' = subinstr(`generate',"内蒙古自治区","内蒙古",.)
replace `generate' = subinstr(`generate',"广西壮族自治区","广西",.)
*Step 4: 去除不必要地域名称 以及根据习惯简写
replace `generate' = "万国证券" if `generate' == "上海万国证券"
replace `generate' = "海通证券" if `generate' == "上海海通证券"
replace `generate' = "申银证券" if `generate' == "上海申银证券"
replace `generate' = "群益证券" if index(`generate',"群益证券")
replace `generate' = "中金公司" if `generate' == "中国国际金融有限公司"
replace `generate' = "中金公司" if `generate' =="中国国际金融香港证券"
replace `generate' = "中国建投" if `generate' == "中国建银投资有限责任公司"|`generate' =="中国建银投资证券"
replace `generate' = "中银国际" if `generate' =="中国银行国际证券公司"|`generate' =="中银国际证券"
replace `generate' = "科技证券" if `generate' == "中国科技证券"
replace `generate' = "民族证券" if `generate' == "中国民族证券"
replace `generate' = "银河证券" if `generate' == "中国银河证券"
replace `generate' = "中投证券" if `generate' == "中国中投证券"
replace `generate' = "南方证券" if `generate' == "中国南方证券"
replace `generate' = "国泰证券" if `generate' == "中国国泰证券"
replace `generate' = "广发证券" if `generate' == "广东广发证券"
replace `generate' = "金信证券" if `generate' == "上海金信证券"
replace `generate' = "远东证券" if `generate' == "上海远东证券"
replace `generate' = "财达证券" if `generate' == "河北财达证券"
replace `generate' = "北京高华" if `generate' == "北京高华证券"
replace `generate' = "第一创业" if `generate' == "第一创业证券"
replace `generate' = "第一上海" if `generate' == "第一上海证券"
replace `generate' = "广发华福" if `generate' == "广发华福证券"
replace `generate' = "华泰联合" if `generate' == "华泰联合证券"
replace `generate' = "申银万国" if `generate' == "申银万国证券"
replace `generate' = "中信建投" if `generate' == "中信建投证券"
replace `generate' = "中信金通" if `generate' == "中信金通证券"
replace `generate' = "国泰君安" if `generate' == "国泰君安证券"
replace `generate' = "财富证券" if `generate' == "财富里昂证券"
replace `generate' = "兴业证券" if `generate' == "福建兴业证券"
replace `generate' = "华福证券" if `generate' == "福建省华福证券"
replace `generate' = "闽发证券" if `generate' == "福建省闽发证券"
replace `generate' = "国投证券" if `generate' == "深圳国投证券"
replace `generate' = "国投证券" if `generate' == "深圳国投证券营业部"
replace `generate' = "国泰证券" if `generate' == "深圳国泰证券"
replace `generate' = "有价证券" if `generate' == "重庆有价证券"
replace `generate' = "申银万国证券" if `generate' == "上海申银万国证券"
replace `generate' = "天风证券" if `generate' == "四川省天风证券"
replace `generate' = "北方证券" if `generate' == "沈阳北方证券"
replace `generate' = "万通证券" if `generate' == "青岛万通证券"
*
*Step 5:将过长的公司去掉证券二字
replace `generate' = subinstr(`generate',"证券","",.) if strlen(`generate')>=18
end