-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy path12_CreateCRSPPredictors.R
52 lines (38 loc) · 1.3 KB
/
12_CreateCRSPPredictors.R
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
# creates predictors that are simple transformation of CRSP data
### READ DATA
crspret = read_fst(paste0(pathDataIntermediate,'crspmret.fst'))
crspinfo = read_fst(paste0(pathDataIntermediate,'crspminfo.fst'))
### MAKE STreversal
if (!file.exists(paste0(pathPredictors, 'STreversal.csv'))) {
temp = crspret %>%
select(permno, date, ret) %>%
mutate(
STreversal = if_else(is.na(ret), 0, ret)
, yyyymm = year(date)*100 + month(date)
) %>%
filter(!is.na(STreversal)) %>%
select(permno, yyyymm, STreversal)
write_csv(temp, paste0(pathPredictors, 'STreversal.csv'))
}
### MAKE Price
if (!file.exists(paste0(pathPredictors, 'Price.csv'))) {
temp = crspinfo %>%
select(permno, yyyymm, prc) %>%
mutate(
Price = log(abs(prc))
) %>%
filter(!is.na(Price)) %>%
select(permno, yyyymm, Price)
write_csv(temp, paste0(pathPredictors, 'Price.csv'))
}
### MAKE Size
if (!file.exists(paste0(pathPredictors, 'Size.csv'))) {
temp = crspinfo %>%
select(permno, yyyymm, me) %>%
mutate(
Size = log(me)
) %>%
filter(!is.na(Size)) %>%
select(permno, yyyymm, Size)
write_csv(temp, paste0(pathPredictors, 'Size.csv'))
}