hazards_quart.df$quarter <- as.yearqtr(as.character(date_decimal(hazards_quart.df$Date)), format = "%Y-%m-%d")
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="quarter")
hazards_f <- melt(hazards_quart.df[, c("quarter", "date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="quarter")
View(hazards_f)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("quarter", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="quarter")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("quarter", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="quarter")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("quarter", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="quarter")
g1 <- ggplot(hazards_f) + geom_line(aes(x=quarter, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus", "f_act_ws", "f_act_total")], id="Date")
g2 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date) )
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g2)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
View(hazards_f)
hazards_f <- melt(hazards_quart.df[, c("date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
no
ggplot(hazards_f) + geom_line(aes(x=date, y=value, color=variable))
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- aggregate(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), nfrequency=4, mean)
}
time <- time(datalist[[2]])
hazards <- read.csv("hazards_sexage_sa.csv",header=TRUE)
hazards$Date <- as.Date(as.character(hazards$Date),format="%Y%m%d")
# make quarterly data
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- aggregate(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), nfrequency=4, mean)
}
hazards_quart = t(do.call(rbind, datalist))
View(hazards)
Date = as.Date(rep(0,dim(hazards_quart.df,2)), origin = "1976-01-01"))
Date = as.Date(rep(0,dim(hazards_quart.df,2)), origin = "1976-01-01")
recessions.df = read.table(textConnection(
"Peak, Trough
1857-06-01, 1858-12-01
1860-10-01, 1861-06-01
1865-04-01, 1867-12-01
1869-06-01, 1870-12-01
1873-10-01, 1879-03-01
1882-03-01, 1885-05-01
1887-03-01, 1888-04-01
1890-07-01, 1891-05-01
1893-01-01, 1894-06-01
1895-12-01, 1897-06-01
1899-06-01, 1900-12-01
1902-09-01, 1904-08-01
1907-05-01, 1908-06-01
1910-01-01, 1912-01-01
1913-01-01, 1914-12-01
1918-08-01, 1919-03-01
1920-01-01, 1921-07-01
1923-05-01, 1924-07-01
1926-10-01, 1927-11-01
1929-08-01, 1933-03-01
1937-05-01, 1938-06-01
1945-02-01, 1945-10-01
1948-11-01, 1949-10-01
1953-07-01, 1954-05-01
1957-08-01, 1958-04-01
1960-04-01, 1961-02-01
1969-12-01, 1970-11-01
1973-11-01, 1975-03-01
1980-01-01, 1980-07-01
1981-07-01, 1982-11-01
1990-07-01, 1991-03-01
2001-03-01, 2001-11-01
2007-12-01, 2009-06-01"), sep=',',
colClasses=c('Date', 'Date'), header=TRUE)
# import data
hazards <- read.csv("hazards_sexage_sa.csv",header=TRUE)
hazards$Date <- as.Date(as.character(hazards$Date),format="%Y%m%d")
# make quarterly data
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- aggregate(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), nfrequency=4, mean)
}
time <- time(datalist[[2]])
hazards_quart_0 = do.call(rbind, datalist)
hazards_quart <- cbind(as.matrix(time), t(hazards_quart_0))
hazards_quart.df <- as.data.frame(hazards_quart)
colnames(hazards_quart.df) <- colnames(hazards)
hazards_quart.df$date <- as.character(date_decimal(hazards_quart.df$Date))
hazards_quart.df$quarter <- as.yearqtr(as.character(date_decimal(hazards_quart.df$Date)), format = "%Y-%m-%d")
recessions.df = read.table(textConnection(
"Peak, Trough
1857-06-01, 1858-12-01
1860-10-01, 1861-06-01
1865-04-01, 1867-12-01
1869-06-01, 1870-12-01
1873-10-01, 1879-03-01
1882-03-01, 1885-05-01
1887-03-01, 1888-04-01
1890-07-01, 1891-05-01
1893-01-01, 1894-06-01
1895-12-01, 1897-06-01
1899-06-01, 1900-12-01
1902-09-01, 1904-08-01
1907-05-01, 1908-06-01
1910-01-01, 1912-01-01
1913-01-01, 1914-12-01
1918-08-01, 1919-03-01
1920-01-01, 1921-07-01
1923-05-01, 1924-07-01
1926-10-01, 1927-11-01
1929-08-01, 1933-03-01
1937-05-01, 1938-06-01
1945-02-01, 1945-10-01
1948-11-01, 1949-10-01
1953-07-01, 1954-05-01
1957-08-01, 1958-04-01
1960-04-01, 1961-02-01
1969-12-01, 1970-11-01
1973-11-01, 1975-03-01
1980-01-01, 1980-07-01
1981-07-01, 1982-11-01
1990-07-01, 1991-03-01
2001-03-01, 2001-11-01
2007-12-01, 2009-06-01"), sep=',',
colClasses=c('Date', 'Date'), header=TRUE)
# import data
hazards <- read.csv("hazards_sexage_sa.csv",header=TRUE)
hazards$Date <- as.Date(as.character(hazards$Date),format="%Y%m%d")
# make quarterly data
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- aggregate(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), nfrequency=4, mean)
}
time <- time(datalist[[2]])
hazards_quart_0 = do.call(rbind, datalist)
hazards_quart <- cbind(as.matrix(time), t(hazards_quart_0))
hazards_quart.df <- as.data.frame(hazards_quart)
colnames(hazards_quart.df) <- colnames(hazards)
#hazards_quart.df$date <- as.character(date_decimal(hazards_quart.df$Date))
#hazards_quart.df$quarter <- as.yearqtr(as.character(date_decimal(hazards_quart.df$Date)), format = "%Y-%m-%d")
View(hazards_quart.df)
hazards_f <- melt(hazards_quart.df[, c("time", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="time")
g1 <- ggplot(hazards_f) + geom_line(aes(x=time, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
View(recessions.trim)
recessions.trim = date_decimal(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))
class(recessions.trim)
View(recessions.trim)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
recessions.trim = date_decimal(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
recessions.trim = decimal_date(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))
View(recessions.trim)
decimal <- decimal_date(d1988-01-01ate)
decimal <- decimal_date(d1988-01-01)
decimal <- decimal_date(1988-01-01)
decimal <- decimal_date("1988-01-01")
decimal <- decimal_date(ymd("1988-01-01"))
print(decimal)
recessions.trim = decimal_date(ymd(subset(recessions.df, Peak >= min(hazards_quart.df$Date))))
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim = decimal_date(ymd(as.character(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))))
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim = as.character(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim$Peak
recessions.trim1 = ymd(subset(recessions.df, Peak >= min(hazards_quart.df$Date)))
recessions.trim1 = ymd(recessions.trim)
recessions.trim1 = ymd("1980-01-01")
recessions.trim1 = decimal_date(ymd("1980-01-01"))
recessions.trim1 = decimal_date(ymd(recessions.trim))
recessions.trim1 = decimal_date(ymd(recessions.trim[1]))
recessions.trim1 = decimal_date(ymd(recessions.trim[1]))
recessions.trim1 = decimal_date(ymd(recessions.trim[1,1]))
datalist = list()
for(i in 1:ncol(recessions.trim_0)){
datalist[[i]] <- decimal_date(ymd(recessions.trim[i]))
}
datalist = list()
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
datalist[[i,j]] <- decimal_date(ymd(recessions.trim[i,j]))
}}
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
datalist = list()
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
datalist[[i,j]] <- decimal_date(ymd(recessions.trim[i,j]))
}}
decimal_date(ymd(recessions.trim[1,1]))
decimal_date(ymd(recessions.trim[1,2]))
nrow(recessions.trim_0)
ncol(recessions.trim_0))
ncol(recessions.trim_0)
View(recessions.trim)
datalist = list()
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
datalist[[i,j]] <- decimal_date(ymd(recessions.trim[i,j]))
}}
recessions.trim <- data.frame(matrix(NA, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim[i,j]))
}}
View(recessions.trim_0)
View(recessions.trim)
recessions.trim <- data.frame(matrix(NA, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim[i,j]))
}}
View(recessions.trim)
View(recessions.trim_0)
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim[i,j]))
}}
View(recessions.trim_0)
View(recessions.trim)
recessions.trim <- data.frame(matrix(NULL, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim[i,j]))
}}
View(recessions.trim)
View(recessions.trim_0)
View(recessions.trim)
View(recessions.trim_0)
recessions.trim[1,1] <- decimal_date(ymd(recessions.trim[1,1]))
View(recessions.trim)
View(recessions.trim_0)
View(recessions.trim)
recessions.trim <- data.frame(matrix(NULL, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
View(recessions.trim)
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
View(recessions.trim)
View(recessions.trim)
View(recessions.trim_0)
colnames(recessions.trim) <- colnames(recessions.trim_0)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
plot(g1)
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus", "f_act_ws", "f_act_total")], id="Date")
g2 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
## f hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus", "f_act_ws", "f_act_total")], id="Date")
g2 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g2)
## s hazard rates by group (SA)
hazards_s <- melt(hazards[, c("Date", "s_m16to24", "s_m25to54", "s_m55plus", "s_f16to24", "s_f25to54", "s_f55plus")], id="Date")
g1 <- ggplot(hazards_s) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="s by gender/age group (SA)") + theme_bw()
recessions.trim = subset(recessions.df, Peak >= min(hazards$Date) )
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_s <- melt(hazards[, c("Date", "s_m16to24", "s_m25to54", "s_m55plus", "s_f16to24", "s_f25to54", "s_f55plus", "s_act_ws", "s_act_total")], id="Date")
g2 <- ggplot(hazards_s) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="s by gender/age group (SA)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
recessions.trim = subset(recessions.df, Peak >= min(hazards$Date) )
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g2)
## s hazard rates by group (SA/quarterly)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus")], id="Date")
g1 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_f <- melt(hazards_quart.df[, c("Date", "f_m16to24", "f_m25to54", "f_m55plus", "f_f16to24", "f_f25to54", "f_f55plus", "f_act_ws", "f_act_total")], id="Date")
g2 <- ggplot(hazards_f) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="f by gender/age group (SA/quarterly)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g2)
## s hazard rates by group (SA/quarterly)
hazards_s <- melt(hazards_quart.df[, c("Date", "s_m16to24", "s_m25to54", "s_m55plus", "s_f16to24", "s_f25to54", "s_f55plus")], id="Date")
g1 <- ggplot(hazards_s) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="s by gender/age group (SA/quarterly)") + theme_bw()
recessions.trim_0 = subset(recessions.df, Peak >= min(hazards_quart.df$Date))
recessions.trim <- data.frame(matrix(0, nrow = nrow(recessions.trim_0), ncol = ncol(recessions.trim_0)))
for(i in 1:nrow(recessions.trim_0)){
for (j in 1:ncol(recessions.trim_0)){
recessions.trim[i,j] <- decimal_date(ymd(recessions.trim_0[i,j]))
}}
colnames(recessions.trim) <- colnames(recessions.trim_0)
g1 = g1 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g1)
hazards_s <- melt(hazards_quart.df[, c("Date", "s_m16to24", "s_m25to54", "s_m55plus", "s_f16to24", "s_f25to54", "s_f55plus", "s_act_ws", "s_act_total")], id="Date")
g2 <- ggplot(hazards_s) + geom_line(aes(x=Date, y=value, color=variable)) + labs(title="s by gender/age group (SA/quarterly)") + theme_bw() + scale_color_manual(values=c("gray", "gray", "gray", "gray", "gray", "gray", "blue", "orange"))
g2 = g2 + geom_rect(data=recessions.trim, aes(xmin=Peak, xmax=Trough, ymin=-Inf, ymax=+Inf), fill='gray', alpha=0.2) + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())
plot(g2)
library(rstudioapi) # load it
# the following line is for getting the path of your current open file
current_path <- getActiveDocumentContext()$path
# The next line set the working directory to the relevant one:
setwd(dirname(current_path))
# you can make sure you are in the right directory
print( getwd() )
knitr::opts_knit$set(root.dir = dirname(current_path), echo = FALSE) # set path
#knitr::opts_knit$set(root.dir = "/Volumes/Jin/CPS/unemp_count_Nov2018/findhaz/sexageregion", echo = FALSE) # set path
library(foreign)
library(seasonal)
# import data
hazards <- read.csv("csv/hazards_sexageregion.csv",header=TRUE)
weights <- read.csv("csv/weights_sexageregion.csv",header=TRUE)
# seasonal adjustment: X-13ARIMA-SEATS
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- final(seas(ts(hazards[ ,i], start = c(1976, 1), frequency = 12)))
}
library(rstudioapi) # load it
# the following line is for getting the path of your current open file
current_path <- getActiveDocumentContext()$path
# The next line set the working directory to the relevant one:
setwd(dirname(current_path))
# you can make sure you are in the right directory
print( getwd() )
knitr::opts_knit$set(root.dir = dirname(current_path), echo = FALSE) # set path
#knitr::opts_knit$set(root.dir = "/Volumes/Jin/CPS/unemp_count_Nov2018/findhaz/sexageregion", echo = FALSE) # set path
library(foreign)
library(seasonal)
# import data
hazards <- read.csv("csv/hazards_sexageregion.csv",header=TRUE)
weights <- read.csv("csv/weights_sexageregion.csv",header=TRUE)
# seasonal adjustment: X-13ARIMA-SEATS
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- final(seas(ts(hazards[ ,i], start = c(1976, 1), frequency = 12),na.action = na.x13))
}
library(rstudioapi) # load it
# the following line is for getting the path of your current open file
current_path <- getActiveDocumentContext()$path
# The next line set the working directory to the relevant one:
setwd(dirname(current_path))
# you can make sure you are in the right directory
print( getwd() )
knitr::opts_knit$set(root.dir = dirname(current_path), echo = FALSE) # set path
#knitr::opts_knit$set(root.dir = "/Volumes/Jin/CPS/unemp_count_Nov2018/findhaz/sexageregion", echo = FALSE) # set path
library(foreign)
library(seasonal)
# import data
hazards <- read.csv("csv/hazards_sexageregion.csv",header=TRUE)
weights <- read.csv("csv/weights_sexageregion.csv",header=TRUE)
# seasonal adjustment: X-13ARIMA-SEATS
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- final(seas(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), na.action = na.x13))
}
View(hazards)
# make quarterly data
datalist = list()
for(i in 2:ncol(weights)){
datalist[[i]] <- aggregate(ts(weights[ ,i], start = c(1976, 1), frequency = 12), nfrequency=4, mean)
}
time <- time(datalist[[2]])
weights_quart_0 = do.call(rbind, datalist)
weights_quart <- cbind(as.matrix(time), t(weights_quart_0))
weights_quart.df <- as.data.frame(weights_quart)
colnames(weights_quart.df) <- colnames(weights)
write.csv(weights_quart.df, "csv/weights_sexageregion_nsa_quart.csv", row.names=FALSE)
# seasonal adjustment: X-13ARIMA-SEATS
datalist = list()
for(i in 2:13){
datalist[[i]] <- final(seas(ts(weights[ ,i], start = c(1976, 1), frequency = 12), na.action = na.x13))
}
weights_sa_0 = do.call(rbind, datalist)
weights_sa <- cbind(as.matrix(weights$Date), t(weights_sa_0))
View(hazards_sa)
View(weights_sa_0)
library(rstudioapi) # load it
# the following line is for getting the path of your current open file
current_path <- getActiveDocumentContext()$path
# The next line set the working directory to the relevant one:
setwd(dirname(current_path))
# you can make sure you are in the right directory
print( getwd() )
knitr::opts_knit$set(root.dir = dirname(current_path), echo = FALSE) # set path
#knitr::opts_knit$set(root.dir = "/Volumes/Jin/CPS/unemp_count_Nov2018/findhaz/sexageregion", echo = FALSE) # set path
library(foreign)
library(seasonal)
# import data
hazards <- read.csv("csv/hazards_sexageregion.csv",header=TRUE)
weights <- read.csv("csv/weights_sexageregion.csv",header=TRUE)
# seasonal adjustment: X-13ARIMA-SEATS
datalist = list()
for(i in 2:ncol(hazards)){
datalist[[i]] <- final(seas(ts(hazards[ ,i], start = c(1976, 1), frequency = 12), na.action = na.x13))
}
