-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1_DataCreate_EFFR_IIP.R
More file actions
40 lines (28 loc) · 1.62 KB
/
1_DataCreate_EFFR_IIP.R
File metadata and controls
40 lines (28 loc) · 1.62 KB
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
# This file explores EFFR data downloaded from FRED and creates weekly data.
# creates two files EFFR (dailydata) and EFFR_w (weekly data)
EFFR = read.csv('EFFR.csv')
EFFR$DATE = as.Date(EFFR$DATE)
EFFR$EFFR = as.numeric(EFFR$EFFR)
IIP = read.csv('INDPRO.csv')
IIP$DATE = as.Date(IIP$DATE)
# Creating Weekly data ----------------------------------------------------
Sun = seq(as.Date("2006-01-01"), as.Date("2023-12-31"), by = "7 days") #creating vector of Sundays. 2006-01-01 was Sunday.
EFFR_w = data.frame(Date = Sun,
Values = matrix(NaN, length(Sun),1 ) ) #Initiating a dataframe
colnames(EFFR_w)[-1] = 'EFFR'
for(i in 1:length(Sun)){
Week_Data = EFFR[EFFR$DATE <= Sun[i] & EFFR$DATE > (Sun[i]-7), ]
a = na.omit(Week_Data[,2])
EFFR_w[i,2] = if(length(a) != 0) tail(a,1) else NA
}
# Creating Monthly data ----------------------------------------------------
Month = seq(as.Date("2006-02-01"), as.Date("2024-01-01"), by = "month")-1 #creating vector of last day of months.
EFFR_m = data.frame(Date = Month, Values = matrix(NaN, length(Month),1) )
colnames(EFFR_m)[-1] = 'EFFR'
for(i in 1:length(Month)){
Month_Data = EFFR[EFFR$DATE <= Month[i] & EFFR$DATE > (Month[i]-10), ] #here 10 is arbitrary. It has to be a number large enough so that there are non NAs
a = na.omit(Month_Data[,2])
EFFR_m[i,2] = if(length(a) != 0) tail(a,1) else NA
}
# Removing unnecessary variables ------------------------------------------
rm(Sun,Month, Week_Data,Month_Data, a,i)