我写的stata句子是这样的:
- clear
- use tradeweek
- /*对原始数据的一点处理*/
- gen week=substr(trdwnt,6,7)
- replace week="1" if strpos(trdwnt,"Jan")
- replace week="2" if strpos(trdwnt,"Feb")
- replace week="3" if strpos(trdwnt,"Mar")
- replace week="4" if strpos(trdwnt,"Apr")
- replace week="5" if strpos(trdwnt,"May")
- replace week="6" if strpos(trdwnt,"Jun")
- replace week="7" if strpos(trdwnt,"Jul")
- replace week="8" if strpos(trdwnt,"Aug")
- replace week="9" if strpos(trdwnt,"Sep")
- replace week="10" if strpos(trdwnt,"Oct")
- replace week="11" if strpos(trdwnt,"Nov")
- replace week="12" if strpos(trdwnt,"Dec")
- gen m_year=string(year)
- gen Yweek=m_year+week
- destring Yweek,replace force
- drop trdwnt id markettype m_year week
- /*计算周市场加权平均收益率*/
- bysort Yweek:egen p=pc(wsmvttl),prop
- bysort Yweek:egen rm=sum(wretnd*p)
- /*方程1的估计*/
- xtset stkcd Yweek
- reg wretnd l2.rm l.rm rm f.rm f2.rm
- predict e /*残差项与指标计算*/
- gen w=log(1+e)
- bysort stkcd year:egen n=count(year) /*全年交易周数*/
- /*指标2的计算*/
- bysort stkcd year:egen sum1=sum(w^3)
- bysort stkcd year:egen sum2=sum(w^2)
- gen n1=n*[(n-1)^(3/2)]
- gen n2=(n-1)*(n-2)
- gen n3=sum2^(3/2)
- gen nsckew=-(n1*sum1)/[n2*n3]
- duplicates drop
还请大家多多指教。
数据在此
感谢感谢