*======================================
* 第二步: 清洗样本
*======================================
use 国有上市公司样本2008至2019.dta,clear
merge m:1 id using 公司基础数据.dta
drop if _merge==2
drop _merge
* 选择沪深A股
* 市场类型: 1=上海A,2=上海B,4=深圳A,8=深圳B,16=创业板,32=科创板
keep if inlist(市场类型, 1, 4, 16, 32)
* 剔除上市以前的数据
drop if year<real(substr(上市日期,1,4))
* 剔除金融业
gen Industry=substr(行业代码C, 1, 1)
replace Industry=substr(行业代码C, 1, 3) if Industry=="C"
drop if Industry=="J"
* 剔除已退市的
merge m:1 id using 已退市上市公司名单.dta
drop if _merge==2
drop _merge
drop if tuishiyear!=.
* 剔除当年ST、PT类股票
merge m:1 id year using 年末是否被ST或PT.dta
drop if _merge==2
drop _merge
drop if 年末是否ST或PT==1
keep id year control 证券代码 证券简称 行业代码C 行业名称C Industry
*初始样本构建成功
save 非国有股东治理数据2008至2019.dta,replace