-
Notifications
You must be signed in to change notification settings - Fork 22
/
CC_LINK.sas
112 lines (101 loc) · 3.65 KB
/
CC_LINK.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Author: Edwin Hu
Date: 2013-05-24
# CC_LINK #
## Summary ##
Links COMPUSTAT GVKEYs to CRSP PERMNOs.
Takes a file which contains GVKEYs and dates and merges in the
appropriate PERMNOs. This handles a lot of silly merge issues.
Suitable for most cases where you need COMPUSTAT data, but may not be
enough for specific paper replications (e.g., FF93)
## Variables ##
- dsetin: Input Dataset
- dsetout: Output Dataset Name, default compx
- datevar: date variable to use (datadate, rdq)
- keep_vars: variables to keep
## Usage ##
```
%IMPORT "~/git/sas/CC_LINK.sas";
%CC_LINK(dsetin=&syslast.,
dsetout=compx,
datevar=datadate,
keep_vars=);
```
*/
%MACRO CC_LINK(dsetin=comp.funda,
outlib=USER,
dsetout=compx,
datevar=datadate,
keep_vars=);
/* If PERMNO is the primary key, then the CRSP Manual recommends */
/* forming GVKEY-PERMNO links where the USEDFLAG=1, which is unique */
/* See: http://www.crsp.chicagobooth.edu/documentation/product/ccm/crsp_link/ */
PROC SQL;
CREATE TABLE compx AS
SELECT b.lpermno AS permno,
b.lpermco as permco,
a.*,
/* Fama French assume a six month minimum filing delay for 10-Ks */
intnx('month',datadate,6,'E') as date
FROM &dsetin.(keep=GVKEY &datevar.
&keep_vars.
CUSIP CIK
INDFMT DATAFMT CONSOL POPSRC
%if &dsetin.=comp.funda %then %do;
PSTKRV PSTKL PSTK TXDITC TXDB SEQ CEQ CEQL AT LT CSHPRI PRCC_F GP FYEAR
%end;
%if &dsetin.=comp.fundq %then %do;
ATQ LTQ IBQ RDQ FYEARQ
%end;
) AS a,
crsp.ccmxpf_linktable AS b
WHERE a.indfmt = 'INDL'
AND a.datafmt = 'STD'
AND a.popsrc = 'D'
AND a.consol = 'C'
AND a.gvkey=b.gvkey
AND SUBSTR(b.linktype,1,1)='L' AND linkprim IN ('P','C')
AND (b.LINKDT <= CALCULATED date or b.LINKDT = .B)
AND (CALCULATED date <= b.LINKENDDT or b.LINKENDDT = .E)
/* If you don't use usedflag you will have duplicates */
AND b.usedflag=1
ORDER BY permno, CALCULATED date;
QUIT;
proc printto log='/dev/null';run;
/* Compute Book Equity */
data &outlib..&dsetout.;
set compx;
%if &dsetin.=comp.funda %then %do;
/* See Davis, Fama , French (2002) for a complete description */
/* Preferred Stock Equity is measured as redemption, liquidation, or par value */
PS = coalesce(PSTKRV,PSTKL,PSTK,0);
/* Deferred tax is measured as balance sheet deferred taxes and investment tax credit (if available) */
DEFTX = coalesce(TXDITC,TXDB,0);
/* Shareholder's equity is measured as COMPUSTAT shareholder equity (total),
or common plus preferred stock, or total assets minus total liabilities */
SHE = coalesce(SEQ,coalesce(CEQ,CEQL,0) + coalesce(PSTK,0),coalesce(AT,0) - coalesce(LT,0),0);
/* Book equity is shareholder's equity plus deferred taxes minus preferred stock */
BE = coalesce(SHE + DEFTX - PS);
if BE<0 then BE=.;
ME_COMP = abs(coalesce(CSHPRI,0)*coalesce(PRCC_F,0))*1000;
LEV = LT/AT;
YEAR=year(datadate);
label BE='Book Value of Equity Fiscal Year t-1'
YEAR='Calendar Year'
date='Data available to market';
format date yymmddn8.;
if first.gvkey then count=1;
else count+1;
%end;
drop INDFMT DATAFMT CONSOL POPSRC
%if &dsetin.=comp.funda %then %do;
PSTKRV PSTKL PSTK TXDITC TXDB SEQ CEQ CEQL CSHPRI PRCC_F
PS DEFTX SHE
%end;;
run;
proc printto;run;
proc datasets nolist;
contents data=&outlib..&dsetout.;
run;quit;
%PUT ### DONE CC_LINK ###;
%MEND CC_LINK;