Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports
- library(tidyverse)
- library(ggplot2)
- # Read in the CSV file
- gdp <- read.csv('PATH_TO_CSV',header=T)
- # Format the date column
- gdp$Date <- strptime(gdp$Date, format = "%b %d %Y")
- # Format Date
- gdp$Date <- as.POSIXct(gdp$Date)
- # Which dates to consider?
- threshold <- "1970-01-01"
- gdpReduced <-
- gdp %>%
- filter(Date > threshold) %>%
- mutate(isNegative = ifelse(Value < 0, TRUE, FALSE)) %>%
- mutate(prior1QuarterNegative = ifelse(lead(Value < 0), TRUE, FALSE)) %>%
- mutate(twoNegativeInARow = ifelse(isNegative & prior1QuarterNegative, TRUE, FALSE)) %>%
- transmute(Date = Date,
- Value = Value,
- twoNegativeInARow = twoNegativeInARow)
- # Percentage occurence
- occurences <-
- gdpReduced %>% filter(twoNegativeInARow)
- occurenceRate <- nrow(occurences) / nrow(gdpReduced) # 7.2% as a prior probability
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement