关于本站
人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!
获取电子版《CDA一级教材》
完整电子版已上线CDA网校,累计已有10万+在读~ 教材严格按考试大纲编写,适合CDA考生备考,也适合业务及数据分析岗位的从业者提升自我。
TOP热门关键词
北大出版的那本书,那里面的sas其实没有忠于元论文,尤其账面市值比的分组问题,那个程序是平分的,不是按照30%,40%,30%分组的。下面这段程序,洋人写的,供大家参考。没有调试,不知对错。自己好好看看是否需修改 ...
免费学术公开课,扫码加入![]() |
/* *//* This code creates a SAS dataset with the Fama-French monthly factor returns purged of firms that have not been listed for at least 60 months *//* Part 1 of this code assings stocks to NYSE Size/BM-based groups and was written by Denys Glushkov at WRDS. I made some minor modifications. Part 2 extends the first part by computing the resulting Fama-French monthly factor returns. */********************************************************** Part 1 - this part of the code runs on the WRDS server**********************************************************;libname comp 'H:\www\compustat'; *or whatever directory on your personal computer you want to save the SAS dataset;%let wrds=wrds.wharton.upenn.edu 4016;options comamid=TCP remote=WRDS;signon username=_prompt_;rsubmit;options nodate nocenter nonumber ps=max ls=72 fullstimer;title ' ';* The size breakpoint for year t is the median NYSE market equity at the end of June of year t. ;* BE/ME for June of year t is the book equity for the last fiscal year end in t-1 divided by ME ;* for December of t-1. The BE/ME breakpoints are the 30th and 70th NYSE percentiles. ;libname link '/wrds/crsp/sasdata/a_ccm';data linktable; set link.CCMXPF_LINKTABLE;run;%MACRO SIZE_BM (bdate=, edate=, link=); %local msfars; %local msevars; %local sharecode; %local exchangecode; %local begdate; %local enddate; %let msfvars = prc ret shrout; * Selected variables from the CRSP monthly data file (crsp.msf file); %let msevars = exchcd shrcd dlret; * Selected variables from the CRSP monthly event file (crsp.mse); %let sharecode = and shrcd in (10,11); * Restriction on the type of shares (e.g. common stocks); %let exchangecode = ; * In this case, no restrictions on the exchange codes; %let begdate=intck('year',&bdate,-1); %let enddate=&edate;*Call and Run the msf2a.sas program; %include '/wrds/crsp/samples/msf2a.sas';data msex2; set mylib.msf2a; by permno date; size=abs(prc)*shrout; size_lag=lag(size); ldate = lag(date); if first.permno then size_lag = size / (1+ret); ret = sum(ret,dlret); if size>0; drop prc shrout ldate;run;*Assign Stocks to NYSE Size-Based groups;proc sort data=msex2 (keep=date size exchcd) out=msex3; where month(date)=6 and exchcd=1; by date;run;proc means data=msex3 noprint; var size; by date; output out=nyse (drop=_freq_ _type_) median=/autoname;run;proc sql; create table size_assign as select a.permno, a.date, a.size, case when size<=size_median then 'Small' else 'Big' end as size_port from msex2 (keep=permno date size where = (month(date)=6)) as a left join nyse as b on a.date= b.date;quit;*Create Book Equity(BE) measure from Compustat (definition from Daniel and Titman (JF, 2006;data comp_extract; set comp.funda (where=(fyr>0 and at>0 and consol='C' and indfmt='INDL' and datafmt='STD' and popsrc='D')); if missing(SEQ)=0 then she=SEQ;else if missing(CEQ)=0 and missing(PSTK)=0 then she=CEQ+PSTK;else if missing(AT)=0 and missing(LT)=0 and missing(MIB)=0 then she=AT-(LT+MIB);else she=.; if missing(PSTKRV)=0 then BE0=she-PSTKRV;else if missing(PSTKL)=0 then BE0=she-PSTKL; else if missing(PSTK)=0 then BE0=she-PSTK; else BE0=.; * Converts fiscal year into calendar year data; if (1<=fyr<=5) then date_fyend=intnx('month',mdy(fyr,1,fyear+1),0,'end'); else if (6<=fyr<=12) then date_fyend=intnx('month',mdy(fyr,1,fyear),0,'end'); calyear=year(date_fyend); format date_fyend date9.; * Accounting data since calendar year 't-1'; if (year(date_fyend) >= year(&bdate) - 1) and (year(date_fyend) <=year(&edate) + 1); keep gvkey calyear fyr BE0 date_fyend indfmt consol datafmt popsrc datadate TXDITC;run;proc sql; create table comp_extractas select a.gvkey, a.calyear, a.fyr, a.date_fyend, case when missing(TXDITC)=0 and missing(PRBA)=0 then BE0+TXDITC-PRBA else BE0 end as BE from comp_extract as a left join comp.aco_pnfnda (keep=gvkey indfmt consol datafmt popsrc datadate prba) as bon a.gvkey=b.gvkey and a.indfmt=b.indfmt and a.consol=b.consol and a.datafmt=b.datafmt and a.popsrc=b.popsrc and a.datadate=b.datadate;quit;*Create Book to Market (BM) ratios at December;proc sql; create table BM0 (where=(BM>0)) as select a.gvkey, a.calyear, c.permno, c.exchcd, c.date, a.be/(abs(c.prc)*c.shrout/1000) as BM from comp_extract as a, &link as b, mylib.msf2a (where=( month(date)=12)) as c where a.gvkey=b.gvkey and ((b.linkdt<=c.date<=b.linkenddt) or (b.linkdt<=c.date and b.linkenddt=.E) or (c.date<=b.linkenddt and b.linkdt=.B)) and b.lpermno=c.permno and a.calyear = year(c.date) and (abs(c.prc)*c.shrout)>0;quit;*Keep only those cases with valid stock market in June;proc sql; create table BM as select a.gvkey, a.permno, a.bm, a.calyear, a.date as decdate, a.exchcd, b.date, b.size, b.size_port from BM0 as a, size_assign as b where a.permno=b.permno and intck('month',a.date,b.date)=6 and b.size>0;quit;*Assign stocks to NYSE BM-based groups;proc sort data=BM out=nyse1 (keep=permno bm calyear decdate); where exchcd=1; by decdate;run;proc univariate data=nyse1 noprint; var bm; by decdate; output out=nyse2 pctlpts = 30 70 pctlpre=per;run;*Merge back with master file that contains all securities from NYSE, Nasdaq and AMEX;proc sql; create table bm1 as select a.permno, a.gvkey, a.bm, a.size, a.size_port, a.date, a.decdate, case when bm<=per30 then 'Low' when per30<bm<=per70 then 'Medium' else 'High' end as bm_port from BM as a, nyse2 as b where a.decdate=b.decdate; *The 'date' variable refers to June, the 'decdate' variable refers to December of the previous year;quit;proc sort data=bm1; by permno descending date;run;data size_bm_port; set bm1; by permno; leaddate=lag(date); if first.permno then leaddate=intnx('month',date,-12,'end'); format date leaddate decdate date9.; rename date=size_date decdate=bm_date; label date='Valid date for firm size'; label decdate='Valid date for Book-to-Market';run;proc sort data=size_bm_port; by permno size_date;run;proc sql; drop table nyse1, nyse2, nyse, size_assign, msex2, msex3, msedata, bm, bm0, bm1, comp_extract;quit;%MEND;%SIZE_BM (bdate='01Jan1962'd, edate='31DEC2011'd, link=linktable);proc download data=size_bm_port out=size_bm_port;run;endrsubmit;proc sort data=size_bm_port out=comp.size_bm_port; by permno bm_date;run;********************************************************** Part 2**********************************************************;libname msf 'H:\www\crsp'; *directory where CRSP monthly stock return file is stored;libname comp 'H:\www\compustat'; *directory where output file 'size_bm_port' from Part 1 is stored;data crsp; set msf.msf; by permno date; *CRSP montly stock return file with permno, date, ret; n+1; if first.permno then n=0; yyyymm = year(date)*100+month(date); keep permno date yyyymm ret n;proc sort data=comp.size_bm_port out=compu; by permno bm_date;data compu; set compu; cyear= year(bm_date); drop leaddate;run;*I match the accounting data for all fiscal year ends in calender year t-1 with the returns for July of year t to June of year t+1;%let begyear=1962;%let endyear=2011;%let begmon=6;%let endmon=12;%macro merg(st); data crsp; set crsp;%do myear=%eval(&begyear) %to %eval(&endyear); %do mmonth=%eval(&begmon) %to %eval(&endmon); if(yyyymm ge %eval((&myear)*100+(&mmonth+1))) and (yyyymm le %eval((&myear+1)*100+(&mmonth))) then cyear=%eval(&myear-1); %end;%end;proc sort data=crsp; by permno cyear; run;%mend;%merg(1);proc sort data=crsp; by permno cyear;proc sort data=compu; by permno cyear;*Unpurged factors;data ff; merge crsp (in=m1) compu (in=m2); by permno cyear; if m1 and m2; if ret= .B then ret = .; if ret= .C then ret = .;run;proc sort data=ff; by date size_port bm_port;proc means data=ff noprint; var ret / weight=size; by date size_port bm_port; output out=ff_factors mean=vwret;run;proc transpose data=ff_factors out=ff_factors_wide; var vwret; by date; id size_port bm_port;run;data msf.ff_factors_unpurged; set ff_factors_wide; uSMB = 1/3*(SmallHigh + SmallMedium + SmallLow) - 1/3*(BigHigh + BigMedium + BigLow); uHML = 1/2*(SmallHigh + BigHigh) - 1/2*(SmallLow + BigLow); label uSMB = 'SMB [unpurged]'; label uHML = 'HML [unpurged]'; keep date uSMB uHML;run;*Purged factors;data ff; merge crsp (in=m1) compu (in=m2); by permno cyear; if m1 and m2; if ret= .B then ret = .; if ret= .C then ret = .; if n > 60;run;proc sort data=ff; by date size_port bm_port;proc means data=ff noprint; var ret / weight=size; by date size_port bm_port; output out=ff_factors mean=vwret;run;proc transpose data=ff_factors out=ff_factors_wide; var vwret; by date; id size_port bm_port;run;data msf.ff_factors_purged; set ff_factors_wide; pSMB = 1/3*(SmallHigh + SmallMedium + SmallLow) - 1/3*(BigHigh + BigMedium + BigLow); pHML = 1/2*(SmallHigh + BigHigh) - 1/2*(SmallLow + BigLow); label pSMB = 'SMB [purged]'; label pHML = 'HML [purged]'; keep date pSMB pHML;run;data msf.ff_factors; merge msf.ff_factors_unpurged msf.ff_factors_purged; by date; if year(date) >= 1963; keep date pSMB pHML uSMB uHML;run;
「经管之家」APP:经管人学习、答疑、交友,就上经管之家!
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
您可能感兴趣的文章
- SAS软件培训 ... | 急问一道求sample variance的SAS ...
- SAS软件培训 ... | [免费下载]Learning SAS by Exa ...
- SAS软件培训 ... | SAS ADVANCE 63 题的一道看晕头 ...
- SAS软件培训 ... | 《人力资源管理》全国最顶级教材 ...
- SAS软件培训 ... | Statistical Graphics in SAS Fe ...
- SAS软件培训 ... | 基于SAS期货程序化交易策略回溯系 ...
- SAS软件培训 ... | SID for SAS 9.2 validation un ...
- SAS软件培训 ... | [下载]SAS 9.1.3 破解 (verisio ...
人气文章
本文标题:fama-french三因素模型的sas程序
本文链接网址:https://bbs.pinggu.org/jg/ruanjianpeixun_sasruanjianpeixun_2174583_1.html
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。



