# finc872 feb25 carpgm

Document Sample

```					* FEBRUARY 25, 2010 - FINC872 EMPIRICAL WORKSHOP;
***************************************************************************************************************
***********;
***************************************************************************************************************
***********;

*PURPOSE:

1. Introduce students to cumulative return measurement
2. Show similarity between the retain/sum statements, and the plain sum statement
3. Form portfolios based on cars and test something...

***************************************************************************************************************
***********;
***************************************************************************************************************
***********;

proc datasets kill; run;

/* This code through the proc contents is the same as is was for the first assignment */

libname go 'c:\documents and settings\coughenj\desktop\empirical course';

data a; set go.FINC872_feb25_cardata;
if exchcd=1 or exchcd=2 or exchcd=3; *this keeps all stocks with exchange code 1, 2,
or 3;
month=month(date);
year=year(date);
ym=year*100+month; *this makes July 1988 = 198807;
one=1;
if prc le 0 then prc=abs(prc);
mcap=shrout*prc/1000000; *shrout is in 1000's, so this changes the unit to
\$Billions;
run;

proc sort data=a; by permno date;
data a; set a;
if permno=lag(permno) and date=lag(date) and ret=lag(ret) then delete; run;

** I will use only those stocks with full 108 months of returns;

proc sort data=a; by permno;
proc means data=a noprint; by permno; var one;
output out=x sum(one)=months;
data x; set x; if months=108; keep permno;

data b; merge a x(in=tag); by permno; if tag=1; run;     *data set b is the same as set a except
it only includes stocks with a full sample;

proc datasets; delete a x;
*proc contents data=b; run;

/* Alphabetic List of Variables and Attributes

# Variable Type Len Format       Informat Label

5 COMNAM     Char   32 \$32.      35.      Company Name
2 DATE       Num     4 YYMMDDN8. YYMMDD8. NASDAQ traits date from NASDAQ INFORMATION
event, same as TRTSDT
16   EWRETD   Num     8 10.6      E13.6    Equal-Weighted Return-incl. dividends
17   EWRETX   Num     8 10.6      E13.6    Equal-Weighted Return-excl. dividends
4   EXCHCD   Num     8 2.        2.       Exchange Code
9   HSICIG   Num     8                    Header SIC Industry Group
8   HSICMG   Num     8                    Header SIC Major Gorup
1   PERMNO   Num     8 8.        8.       PERMNO
10   PRC      Num     8 12.5      12.5     Price or Bid/Ask Average
11   RET      Num     8 11.6      11.6     Returns
12   RETX     Num     8 11.6      11.6     Returns without Dividends
3   SHRCD    Num     8 2.        2.       Share Code
13   SHROUT   Num     8 10.       10.      Shares Outstanding
7   SICCD    Num     8 8.        8.       Standard Industrial Classification Code
18   SPRTRN   Num     8 10.6      E13.6    Return on the S&P 500 Index
6   TICKER   Char    5 8.        8.       Exchange Ticker Symbol
14   VWRETD   Num     8 10.6      E13.6    Value-Weighted Return-incl. dividends
15   VWRETX   Num     8 10.6      E13.6    Value-Weighted Return-excl. dividends
23   mcap     Num     8
19   month   Num    8
22   one     Num    8
20   year    Num    8
21   ym      Num    8 */

**********************************************************************;
** OK, lets calculate abnormal returns and cumulative abnormal returns;
**********************************************************************;

proc sort data=b; by permno year date;

data b; set b;
ar=retx-ewretx; *this is an abnormal return;
log_ar=log(1+ar);
log_ret=log(1+ret);

data try1; set b;
retain sum_ar;
if permno=lag(permno) and year=lag(year) then do;
sum_ar=sum(sum_ar,log_ar);
end;
else do;
sum_ar=log_ar;
end;
car=exp(sum_ar)-1;

data try1; set try1;
if permno=11850;
proc print; var ticker date ar log_ar sum_ar car; run;

*DO IT AGAIN, WITHOUT RETAIN STATEMENT OR SUM FUNCTION*;
data try2; set b;
if permno=lag(permno) and year=lag(year) then do;
sum_ar+log_ar;
end;
else do;
sum_ar=log_ar;
end;
car=exp(sum_ar)-1;

data try2; set try2;
if permno=11850;
proc print; var ticker date ar log_ar sum_ar car; run;

*THE ABOVE TWO PRINTOUTS FROM TRY1 AND TRY2 ARE IDENTICAL*;

**** TO DO: ********************************************************
OF THOSE STOCKS OVER \$50B IN MCAP ON JANUARY 2007,
LIST TOP/BOTTOM 10 BY CAR OVER 2-YEARS ENDING DEC 2008
***********************************************************************;

data getstocks; set b;
if ym=200701;
if mcap gt 50;
keep permno;
proc sort data=getstocks; by permno;

data c; merge b getstocks(in=tag); by permno;
if tag=1;
if ym ge 200701;
proc sort data=c; by permno date;

data cars; set c;
if permno=lag(permno) then do;
sum_ar+log_ar;
end;
else do;
sum_ar=log_ar;
end;
car=exp(sum_ar)-1;

data cars; set cars; by permno; if last.permno;
*this keeps just the last observation by stock,which should be dec 2008;

proc sort data=cars; by descending car;
title 'TOP10 CARS OVER 2-YEARS ENDING DEC2008';
proc print data=cars(firstobs=1 obs=10); var date ticker comnam
permno car;
proc sort data=cars; by car;
title 'BOTTOM10 CARS OVER 2-YEARS ENDING DEC2008';
proc print data=cars(firstobs=1 obs=10); var date ticker comnam
permno car;
run;

** QUESTION: *******************************************************************************************;
* Are December returns lower for the stocks with lowest portfolio returns from January - November?;

*to test, let's calculate cumulative returns for all stocks from Jan - Nov each year.
* then form portfolios based on this performance.
* then test to determine if the returns on worst portfolio are lower than the others.
*********************************************************************************************************;
*Step 1;
* cumulate returns and put in portfolios;
proc sort data=b; by year permno date;
data fp1; set b;
if permno=lag(permno) and year=lag(year) then do;
sum_ar+log_ar;
end;
else do;
sum_ar=log_ar;
end;
car=exp(sum_ar)-1;

data fp2; set fp1;
if month=11;
proc rank data=fp2 out=ports groups=20;
by year;
ranks port;
var car;

data ports; set ports;
port=port+1;
proc sort data=ports; by port;
proc means data=ports noprint; by port; var car;
output out=peek mean=;
proc print data=peek; var port _FREQ_ car; run;

*Step 2;
*match portfolio numbers in data=ports with december return data;

data   x; set ports;
keep   year permno port; run;
proc   sort data=x; by permno year;
proc   sort data=fp1; by permno year;

data test; merge fp1 x; by permno year ;
if month=12;

* Step 3 - test if port 1 is different from rest.     Lot's of ways to do this...;

data test; set test;

proc reg data=test; model ar=bad; run;

proc sort data=test; by year;
proc reg data=test ;
by year;
run;

*the above proc reg produces 9 pages of output - the following produces 1
page;

proc reg data=test noprint outest=regout tableout adjrsq;
by year;

data regout; set regout; *this is pretty sparse;
if _TYPE_='PARMS';
proc print; run;

proc print data=regout; *this is still alot of information on about
1 page;

*DONE**********************************************************************************************************
************;

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 9/11/2012 language: Korean pages: 3
How are you planning on using Docstoc?