/* *************************************************************************** */ /* ********* W R D S R E S E A R C H A P P L I C A T I O N S ************* */ /* *************************************************************************** */ /* Program : fama_french_factors_replication.sas */ /* Authors : Luis Palacios (WRDS), Premal Vora (Penn State) */ /* Date : 04/2009 */ /* Last modified : 08/2011 */ /* Description : Replicates Fama-French (1993) SMB & HML Factors */ /* *************************************************************************** */ %let comp=compq; %let crsp=crspq; libname myh '~'; /************************ Part 1: Compustat ****************************/ /* Compustat XpressFeed Variables: */ /* AT = Total Asts */ /* PSTKL = Preferred Stock Liquidating Value */ /* TXDITC = Deferred Taxes and Investment Tax Credit */ /* PSTKRV = Preferred Stock Redemption Value */ /* CEQ = Common/Ordinary Equity - Total */ /* PSTK = Preferred/Preference Stock (Capital) - Total */ /* In calculating Book Equity, incorporate Preferred Stock (PS) values */ /* u the redemption value of PS, or the liquidation value */ /* or the par value (in that order) (FF,JFE, 1993, p. 8) */ /* USe Balance Sheet Deferred Taxes TXDITC if available */ /* Flag for number of years in Compustat (<2 likely backfilled data) */ %let vars = AT PSTKL TXDITC PSTKRV CEQ PSTK ; data comp; t &comp..funda (keep= gvkey datadate &vars indfmt datafmt popsrc consol); by gvkey datadate; where indfmt='INDL' and datafmt='STD' and popsrc='D' and consol='C' and datadate >='01Jan1959'd; /* Two years of accounting data before 1962 */ PS = coalesce(PSTKRV,PSTKL,PSTK,0); if missing(TXDITC) then TXDITC = 0 ; BE = CEQ + TXDITC - PS ; if BE<0 then BE=.; year = year(datadate); u盘不显示label BE='Book Value of Equity FYear t-1' ; drop indfmt datafmt popsrc consol ps &vars; retain count; if first.gvkey then count=1; el count = count+1; run; /************************ Part 2: CRSP **********************************/ /* Create a CRSP Subsample with Monthly Stock and Event Variables */ /* This procedure creates a SAS datat named "CRSP_M" */ /* Restrictions will be applied later */ /* Select variables from the CRSP monthly stock and event datats */ %let mvars=ticker ncusip shrcd exchcd; %let msfvars = prc ret retx shrout cfacpr cfacshr; %include '/wrds/crsp/samples/crspmerge.sas'; %crspmerge(s=m,start=01jan1959,end=30jun2011, sfvars=&msfvars,vars=&mvars,filters=exchcd in (1,2,3)); /* CRSP_M is sorted by date and permno and has historical returns */ /* as well as historical share codes and exchange codes */ /* Add CRSP delisting returns */ proc sql; create table crspm2 as lect a.*, b.dlret, sum(1,ret)*sum(1,dlret)-1 as retadj "Return adjusted for delisting", abs(a.prc)*a.shrout as MEq 'Market Value of Equity' from Crsp_m a left join &delist(where=(missing(dlret)=0)) b on a.permno=b.permno and intnx('month',a.date,0,'E')=intnx('month',b.DLSTDT,0,'E') order by a.date, a.permco, MEq; quit; /* There are cas when the same firm (permco) has two or more */ 年利/* curities (permno) at same date. For the purpo of ME for */ /* the firm, we aggregated all ME for a given permco, date. This */ /* aggregated ME will be assigned to the Permno with the largest ME */ data crspm2a (drop = Meq); t crspm2; by date permco Meq; retain ME; if first.permco and last.permco then do; ME=meq; output; /* most common ca where a firm has a unique permno*/ end; el do ; if first.permco then ME=meq; el ME=sum(meq,ME); if last.permco then output; end; run; /* There should be no duplicates*/ proc sort data=crspm2a nodupkey; by permno date;run; /* The next step does 2 things: */ /* - Create weights for later calculation of VW returns. */ /* Each firm's monthly return RET t willl be weighted by */ /* ME(t-1) = ME(t-2) * (1 + RETX (t-1)) */ /* where RETX is the without-dividend return. */ /* - Create a File with December t-1 Market Equity (ME) */ data crspm3 (keep=permno date retadj weight_port ME exchcd shrcd cumretx) decme (keep = permno date ME rename=(me=DEC_ME) ) ; t crspm2a; by permno date; retain weight_port cumretx me_ba; Lpermno=lag(permno); LME=lag(me); if first.permno then do; LME=me/(1+retx); cumretx=sum(1,retx); me_ba=LME;weight_port=.;end; el do; if 纸尿裤和拉拉裤的区别month(date)=7 then do; weight_port= LME; me_ba=LME; /* lag ME also at the end of June */ cumretx=sum(1,retx); end; 好听的女孩名字el do; if LME>0 then weight_port=cumretx*me_ba; el weight_port=.; cumretx=cumretx*sum(1,retx); end; end; output crspm3; if month(date)=12 and ME>0 then output decme; run; /* Create a file with data for each June with ME from previous December */ proc sql; create table crspjune as lect a.*, b.DEC_ME from crspm3 (where=(month(date)=6)) as a, decme as b where a.permno=b.permno and intck('month',b.date,a.date)=6; quit; /*************** Part 3: Merging CRSP and Compustat ***********/ /* Add Permno to Compustat sample */ proc sql; create table ccm1 as lect a.*, b.lpermno as permno, b.linkprim from comp as a, &pf_linktable as b where a.gvkey=b.gvkey and substr(b.linktype,1,1)='L' and linkprim in ('P','C') and (intnx('month',intnx('year',a.datadate,0,'E'),6,'E') >= b.linkdt) and (b.linkenddt >= intnx('month',intnx('year',a.datadate,0,'E'),6,'E') or missing(b.linkenddt)) order by a.datadate, permno, b.linkprim desc; quit; /* Cleaning Compustat Data for no relevant duplicates */ /* Eliminating overlapping matching : few cas where different gvkeys */ /* for same permno-date --- some of them are not 'primary' matches in CCM */ /* U linkprim='P' for lecting just one gvkey-permno-date combination */ data ccm1a; t ccm1; by datadate permno descending linkprim; if first.permno; run; /* Sanity Check -- No Duplicates */ proc sort data=ccm1a nodupkey; by permno year datadate; run; /* 2. However, there other type of duplicates within the year */ /* Some companiess change fiscal year end in the middle of the calendar year */ /* In the cas, there are more than one annual record for accounting data */ /* We will be lecting the last annual record in a given calendar year */ data ccm2a ; t ccm1a; by permno year datadate; if ar; run; /* Sanity Check -- No Duplicates */ proc sort data=ccm2a nodupkey; by permno datadate; run; /* Finalize Compustat Sample */ /* Merge CRSP with Compustat data, at June of every year */ /* Match fiscal year ending calendar year t-1 with June t */ proc sql; create table ccm2_june as lect a.*, b.BE, (1000*b.BE)/a.DEC_ME as BEME, b.count, b.datadate, intck('month',b.datadate, a.date) as dist from crspjune a, ccm2a b where a.permno=b.permno and intnx('month',a.date,0,'E')= intnx('month',intnx('year',b.datadate,0,'E'),6,'E') order by a.date; quit; /************************ Part 4: Size and Book to Market Portfolios ***/ /* Forming Portolio by ME and BEME as of each June t */ /* Calculate NYSE Breakpoints for Market Equity (ME) and */ /* Book-to-Market (BEME) */ proc univariate data=ccm2_june noprint; where exchcd=1 and beme>0 and shrcd in (10,11) and me>0 and count>=2; var ME BEME; by date; /*at june;*/ output out=ny_breaks median = SIZEMEDN pctlpre=ME BEME pctlpts=30 70; run; /* U Breakpoints to classify stock only at end of all June's */ proc sql; create table ccm3_june as lect a.*, b.sizemedn, b.beme30, b.beme70 from ccm2_june as a, ny_breaks as b where a.date=b.date; quit; /* Create portfolios as of June */ /* SIZE Portfolios : S[mall] or B[ig] */ /* Book-to-market Portfolios: L[ow], M[edium], H[igh] */ data june ; t ccm3_june; If beme>0 and me>0 and count>=2 then do; positivebeme=1; * beme>0 includes the restrictioncs that ME at Dec(t-1)>0 * and BE (t-1) >0 and more than two years in Compustat; if 0 <= ME <= sizemedn then sizeport = 'S'; elexcel有效性 if ME > sizemedn then sizeport = 'B'; el sizeport=''; if 0 < beme <= beme30 then btmport = 'L'; el if beme30 < beme <= beme70 then btmport = 'M' ; el if beme > beme70 then btmport = 'H'; el btmport=''; end; 课外阅读书籍el positivebeme=0; if cmiss(sizeport,btmport)=0 then nonmissport=1; el nonmissport=0; 家常炖菜菜谱大全 keep permno date sizeport btmport positivebeme exchcd shrcd nonmissport; run; /* Identifying each month the curities of */ /* Buy and hold June portfolios from July t to June t+1 */ proc sql; create table ccm4 as lect a.*, b.sizeport, b.btmport, b.date as portdate format date9., b.positivebeme , b.nonmissport from crspm3 as a, june as b where a.permno=b.permno and 1 <= intck('month',b.date,a.date) <= 12 order by date, sizeport, btmport; quit; /*************** Part 5: Calculating Fama-French Factors **************/ /* Calculate monthly time ries of weighted average portfolio returns */ proc means data=ccm4 noprint; where weight_port>0 and positivebeme=1 and exchcd in (1,2,3) and shrcd in (10,11) and nonmissport=1; by date sizeport btmport; var retadj; weight weight_port; output out=vwret (drop= _type_ _freq_ ) mean=vwret n=n_firms; run; /* Monthly Factor Returns: SMB and HML */ proc transpo data=vwret(keep=date sizeport btmport vwret) out=vwret2 (drop=_name_ _label_); by date ; ID sizeport btmport; Var vwret; run; /************************ Part 6: Saving Output ************************/ data myh.ff_factors; t vwret2; WH = (bh + sh)/2 ; WL = (sl + bl)/2 ; WHML = WH - WL; WB = (bl + bm + bh)/3 ; WS = (sl + sm + sh)/3 ; WSMB = WS - WB; label WH = 'WRDS High' WL = 'WRDS Low' WHML = 'WRDS HML' WS = 'WRDS Small' WB = 'WRDS Big' WSMB = 'WRDS SMB'; run; /* Number of Firms */ proc transpo data=vwret(keep=date sizeport btmport n_firms) out=vwret3 (drop=_name_ _label_) prefix=n_; by date ; ID sizeport btmport; Var n_firms; run; data myh.ff_nfirms; t vwret3; N_H = n_sh + n_bh; N_L = n_sl + n_bl; N_HML = N_H + N_L; N_B = n_bl + n_bm + n_bh; N_S = n_sl + n_sm + n_sh ; N_SMB = N_S + N_B; Total1= N_SMB; label N_H = 'N_firms High' N_L = 'N_firms Low' N_HML = 'N_firms HML' N_S = 'N_firms Small' N_B = 'N_firms Big' N_SMB = 'N_firms SMB'; run; /* Clean the hou*/ proc sql; 先进个人主要事迹drop table ccm1, ccm1a,ccm2a,ccm2_june, ccm3_june, ccm4, comp, crspm2, crspm2a, crspm3, crsp_m, decme, june, ny_breaks; quit; /* ********************************************************************************* */ /* ************* Material Copyright Wharton Rearch Data Services *************** */ /* ****************************** All Rights Rerved ****************************** */ /* ********************************************************************************* */ |
本文发布于:2023-05-15 07:48:08,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/fan/89/898781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |