选取云南白药(000538),基于深成指对云南白药2015-2017年股票进行估计
cntrade 000538
use "000538.dta",clear
global id="000538"
cntrade $id
global nn=stknme[1]
use "$id.dta",clear
tsset date
tsline clsprc,xlabel(,angle(60)) subtitle("$nn $id")
foreach i in "399001" "000001" "000300"{
cntrade `i',index
rename rmt retmkt_`i'
save index_`i'.dta,replace
erase `i'.dta
}
use "index_399001.dta",clear
merge 1:1 date using "$id.dta",nogen
gen year=year(date)
order date year index* stk* ret*
save "merge_$id.dta",replace
use "merge_$id.dta",clear
global yr_1=2014
global yr_2=2018
reg rit retmkt if year<$yr_2 & year>$yr_1 //对2015-2017年进行回归
aaplot rit retmkt if e(sample), xline(0,lp(dash) lc(red)) ///
yline(0,lp(dash) lc(red)) msize(*0.6) ///
title("$nn ($id) 的 Beta 系数, 2015-2017") ///
xtitle("市场指数收益率(深成指)")
#graph export "估计贝塔.png" //做出各年贝塔值
bysort year: reg rit retmkt,noheader
statsby _b[retmkt], by(year) saving("beta_data.dta", replace): ///
reg rit retmkt if year<$yr_2 & year>$yr_1 //对2015-2017年进行逐年回归
preserve
use "beta_data.dta", clear
keep if _stat!=.
qui sum year
local byr = r(min)
local eyr = r(max)
list
#d ;
twoway connect _stat year,
yline(1, lpattern(dash) lcolor(red*0.3))
xlabel(`byr'(2)`eyr')
ylabel(,angle(0) format(%2.1f))
subtitle("$nn ($id) 的Beta系数")
ytitle("beta") xtitle("");
#d cr
graph export "$out\beta $nn $id.png", replace
restore