Created
May 5, 2021 18:51
-
-
Save erikgregorywebb/e282aef9a0c942f910dbd222b23104f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set working directory | |
setwd("~/Projects/zillow") | |
# import libraries | |
library(tidyverse) | |
### REALTOR ### | |
# import realtor.com | |
# source: https://www.realtor.com/research/data/ (Inventory, Monthly) | |
url = 'https://econdata.s3-us-west-2.amazonaws.com/Reports/Core/RDC_Inventory_Core_Metrics_Zip_History.csv' | |
download.file(url, 'realtor-inventory-zip.csv') | |
rltr = read_csv('realtor-inventory-zip.csv') | |
glimpse(rltr) | |
# import zipcodes | |
url = 'https://gist.githubusercontent.com/erikgregorywebb/af025a0f9290c7bfc00797dbcc7f9bef/raw/56860e735c57dee11b0ec03917d716cf38388e4e/utah-zipcodes.csv' | |
download.file(url, 'utah-zipcodes.csv') | |
zip = read_csv('utah-zipcodes.csv') | |
glimpse(zip) | |
# inner join, filtering for utah zipcodes | |
rltr_ut = inner_join(x = rltr, y = zip, by = c('postal_code' = 'zipcode')) | |
# export | |
write_csv(rltr_ut, 'realtor-utah-zip.csv') | |
### REALTOR ### | |
library(lubridate) | |
library(scales) | |
rltr_ut %>% filter(postal_code == 84045) %>% arrange(month_date_yyyymm) %>% | |
mutate(month_date_yyyymm = ymd(paste(month_date_yyyymm, '01', sep = ''))) %>% | |
mutate(month = month(month_date_yyyymm, abbr = T, label = T)) %>% | |
mutate(season = ifelse(month %in% c('Dec', 'Jan', 'Feb'), 'Winter', | |
ifelse(month %in% c('Mar', 'Apr', 'May'), 'Spring', | |
ifelse(month %in% c('Jun', 'Jul', 'Aug'), 'Summer', | |
ifelse(month %in% c('Sep', 'Oct', 'Nov'), 'Fall', ''))))) %>% | |
ggplot(., aes(x = month_date_yyyymm, y = median_listing_price)) + | |
geom_point(aes(col = season, size = 2)) + geom_line() + | |
scale_y_continuous(limits = c(100000, 500000), label = comma) | |
library(tidyverse) | |
library(zipcode) | |
library(lubridate) | |
# import "market hotness" data from realtor.com | |
setwd("~/Projects/zillow") | |
url = 'https://econdata.s3-us-west-2.amazonaws.com/Reports/Hotness/RDC_Inventory_Hotness_Metrics_Zip_History.csv' | |
download.file(url, 'realtor-hotness-zip.csv') | |
raw = read_csv('realtor-hotness-zip.csv') | |
glimpse(raw) | |
# clean the dataframe | |
rltr = raw %>% | |
mutate(month_date_yyyymm = lubridate::ymd(paste(month_date_yyyymm, '01', sep = ''))) %>% | |
separate(zip_name, into = c('city', 'state'), sep = ', ', remove = F) | |
# import zipcodes | |
url = 'https://gist.githubusercontent.com/erikgregorywebb/af025a0f9290c7bfc00797dbcc7f9bef/raw/56860e735c57dee11b0ec03917d716cf38388e4e/utah-zipcodes.csv' | |
download.file(url, 'utah-zipcodes.csv') | |
zip = read_csv('utah-zipcodes.csv') | |
glimpse(zip) | |
# inner join, filtering for utah zipcodes | |
rltr_ut = inner_join(x = select(rltr, -city), y = zip, by = c('postal_code' = 'zipcode')) | |
glimpse(rltr_ut) | |
# export | |
write_csv(rltr_ut, 'realtor-utah-hotness-by-zip.csv') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment