All homes where buyernonindividual <> ’’
rm(list=ls())
library(data.table)
library(RSQLite)
library(DBI)
library(dplyr)
library(stargazer)
library(lfe)
library(ggplot2)
library(tidyverse)
library(zoo)
library(stringr)
library(fst)
dbdir = "/data/ztrax.db"
con <- dbConnect(RSQLite::SQLite(),dbdir)
# identify_sfr_buyers_all_inst.R
sfr <- read_fst(path="sfr_all_inst.fst",as.data.table = T)
temp <- read_fst(path="sfr_all_inst_pre2008.fst",as.data.table = T)
sfr <- rbind(sfr,temp)
rm(temp)
gc()
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 51780629 2765.4 103632985 5534.6 51794263 2766.2
## Vcells 873286479 6662.7 1515703508 11564.0 1429757222 10908.2
sfr_yearly <- sfr[,.N,by=buy_year]
ggplot(sfr_yearly[buy_year<2020],aes(x=buy_year,y=N))+geom_line()
# counties <- unique(sfr$fips)
# sfr_county_cumalative <- merge(counties,2000:2018)
# names(sfr_county_cumalative) <- c("fips","year")
#
# sfr_county_cumalative <- data.table(sfr_county_cumalative)
#
# sfr_county_cumalative[,no_of_sfr_homes:=0]
#
#
#
# pb <- txtProgressBar(min=0,max=length(unique(sfr_county_cumalative$fips)),style = 3)
# i=0
# for(c in unique(sfr_county_cumalative$fips)) {
# i=i+1
# setTxtProgressBar(pb,i)
# for(y in unique(sfr_county_cumalative$year)) {
# sfr_county_cumalative[fips ==c & year==y]$no_of_sfr_homes =nrow(sfr[fips ==c & buy_year<=y & selling_year>=y])
# }
# }
#
# write_fst(sfr_county_cumalative,"sfr_county_cumalative.fst",compress = 100)
sfr_county_cumalative <- read_fst("sfr_county_cumalative.fst",as.data.table = T)
ggplot(sfr_county_cumalative[,.(no_of_sfr_homes=sum(no_of_sfr_homes,na.rm=T)),by=year],aes(x=year,y=no_of_sfr_homes))+geom_line()
Difference in types of homes purchased by institutions?
Change in homepurchaser type? Income? Race? Denials? HMDA data.
acs <- read_fst('/data/zillow research data/acs_2012_2018.fst',as.data.table = T)
acs[,pop_change:=total_population_2018/total_population-1]
acs[,educ_change:=college_frac_2018/college_frac-1]
acs[,no_of_homes_change:=no_of_homes_2018/no_of_homes-1]
acs[,income_change:=med_income_2018/med_income-1]
acs[,pct_rent:=renter_occ_units/(renter_occ_units+owner_occ_units)]
acs[,pct_rent_2018:=renter_occ_units_2018/(renter_occ_units_2018+owner_occ_units_2018)]
acs[,pct_rent_change:=pct_rent_2018/pct_rent-1]
acs[,rent_units_change:=log(pct_rent_2018/pct_rent)]
acs[,rent_units_change_own_change:=log(renter_occ_units_2018/renter_occ_units)/log(owner_occ_units_2018/owner_occ_units)]
acs[,white_frac_change:=white_frac_2018/white_frac-1]
zri <- readRDS('/data/zillow research data/County_Zri_SingleFamilyResidenceRental.rds')
zri <- data.table(zri)
zri <- zri[year(month) %in% c(2012,2018)]
zri <- zri[,.(rent=median(zri,na.rm=T)),by=.(fips,year(month))]
zri_12 <- zri[year==2012]
setnames(zri_12,"rent","rent_12")
zri <- merge(zri[year==2018,c("fips","rent")],zri_12,by="fips")
zri[,rent_change:=rent/rent_12-1]
zri[,fips:=as.numeric(fips)]
zhvi <- readRDS('/data/zillow research data/County_zhvi_uc_sfr_tier_0.33_0.67_sm_sa_month.rds')
zhvi <- data.table(zhvi)
zhvi <- zhvi[year(month) %in% c(2012,2018)]
zhvi <- zhvi[,.(house_price=median(zhvi,na.rm=T)),by=.(fips,year(month))]
zhvi_12 <- zhvi[year==2012]
setnames(zhvi_12,"house_price","house_price_12")
zhvi <- merge(zhvi[year==2018,c("fips","house_price")],zhvi_12,by="fips")
zhvi[,house_price_change:=house_price/house_price_12-1]
zhvi[,fips:=as.numeric(fips)]
permits <- read_fst("/data/zillow research data/permits.fst",as.data.table = T)
permits <- permits[,.(oneunit_Units=sum(oneunit_Units,na.rm=T),oneunit_Value=sum(oneunit_Value,na.rm=T)),by=.(fips,year)]
permits <- permits[year %in% c(2012,2018)]
permits_12 <- permits[year==2012]
setnames(permits_12,c("oneunit_Units","oneunit_Value"),c("oneunit_Units_12","oneunit_Value_12"))
permits <- merge(permits[year==2018,c("fips","oneunit_Units","oneunit_Value")],permits_12,by="fips")
permits[,oneunit_Units_change:=oneunit_Units/oneunit_Units_12-1]
permits[,oneunit_Value_change:=oneunit_Value/oneunit_Value_12-1]
permits[,year:=NULL]
zhvi <- fread("/data/zillow research data/zhvi_1996_2021.csv.gz")
zhvi[,year:=year(month)]
zhvi[,month:=NULL]
zhvi <- zhvi[year %in% c(2012,2018)]
zhvi <- zhvi[,.(zhvi_top=median(zhvi_top,na.rm=T),zhvi_middle=median(zhvi_middle,na.rm=T),zhvi_bottom=median(zhvi_bottom,na.rm=T)),by=.(fips,year)]
zhvi_12 <- zhvi[year==2012]
setnames(zhvi_12,c("zhvi_top","zhvi_middle","zhvi_bottom"),c("zhvi_top_12","zhvi_middle_12","zhvi_bottom_12"))
zhvi_12[,year:=NULL]
zhvi <- merge(zhvi[year==2018,c("fips","zhvi_top","zhvi_middle","zhvi_bottom")],zhvi_12,by="fips")
zhvi[,zhvi_top_change:=zhvi_top/zhvi_top_12-1]
zhvi[,zhvi_middle_change:=zhvi_middle/zhvi_middle_12-1]
zhvi[,zhvi_bottom_change:=zhvi_bottom/zhvi_bottom_12-1]
r_2018 <- sfr_county_cumalative[year==2018]
r_2012 <- sfr_county_cumalative[year==2012,c("fips","no_of_sfr_homes")]
setnames(r_2012,"no_of_sfr_homes","no_of_sfr_homes_2012")
regsample <- merge(r_2018,r_2012,by="fips")
regsample <- merge(regsample,acs,by="fips",all.x=T)
regsample[,sfr_frac:=no_of_sfr_homes/no_of_homes_2018]
regsample[,sfr_frac_change:= (sfr_frac - (no_of_sfr_homes_2012/no_of_homes))]
regsample[,sfr_frac_change_cat := ifelse(sfr_frac_change<0.01,1,ifelse(sfr_frac_change<0.04,4,5))]
regsample[,sfr_frac_cat := ifelse(sfr_frac_change<0.04,1,ifelse(sfr_frac_change<0.10,10,ifelse(sfr_frac_change<0.16,16,17)))]
regsample[,state:=floor(fips/1000)]
regsample <- merge(regsample,zri,by="fips",all.x=T)
regsample <- merge(regsample,zhvi,by="fips",all.x=T)
regsample <- merge(regsample,permits,by="fips",all.x=T)
sfr_frac: Fraction of homes owned by institutions in 2018 as a fraction of total homessfr_frac_change: Change in sfr_frac from 2012 to 2018zhvi_top_change: house price top 3rdzhvi_middle_change: house price middle 3rdzhvi_bottom_change: house price bottom 3rdoneunit_Units_change: Change in number of permits for one units from 2012 to 2018summary(regsample[,c("sfr_frac","sfr_frac_change","pct_rent_change","zhvi_middle_change","oneunit_Units_change","oneunit_Value_change")])
## sfr_frac sfr_frac_change pct_rent_change zhvi_middle_change oneunit_Units_change oneunit_Value_change
## Min. :0.00000 Min. :-0.11882 Min. :-0.50650 Min. :-0.4313 Min. :-1.0000 Min. :-1.0000
## 1st Qu.:0.04252 1st Qu.: 0.01830 1st Qu.:-0.01613 1st Qu.: 0.1777 1st Qu.: 0.1651 1st Qu.: 0.3839
## Median :0.09047 Median : 0.03890 Median : 0.04466 Median : 0.2708 Median : 0.5971 Median : 0.9114
## Mean :0.12039 Mean : 0.04710 Mean : 0.04924 Mean : 0.3095 Mean : Inf Mean : Inf
## 3rd Qu.:0.16153 3rd Qu.: 0.06624 3rd Qu.: 0.10593 3rd Qu.: 0.4043 3rd Qu.: 1.2791 3rd Qu.: 1.7623
## Max. :1.47786 Max. : 0.43146 Max. : 1.37281 Max. : 1.5474 Max. : Inf Max. : Inf
## NA's :1 NA's :1 NA's :1 NA's :250 NA's :2136 NA's :2136
r <- list()
r[[1]] <- felm(pct_rent_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state,data=regsample)
r[[2]] <- felm(rent_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[3]] <- felm(zhvi_top_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[4]] <- felm(zhvi_middle_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[5]] <- felm(zhvi_bottom_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[6]] <- felm(oneunit_Units_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Units_change)])
r[[7]] <- felm(oneunit_Value_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
r[[8]] <- felm(pop_change~factor(sfr_frac_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
stargazer(r,type="text",no.space = T)
##
## =================================================================================================================================================================================
## Dependent variable:
## ------------------------------------------------------------------------------------------------------------------------------------------------------
## pct_rent_change rent_change zhvi_top_change zhvi_middle_change zhvi_bottom_change oneunit_Units_change oneunit_Value_change pop_change
## (1) (2) (3) (4) (5) (6) (7) (8)
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## factor(sfr_frac_cat)10 -0.008 0.026*** -0.013** -0.012* -0.012 0.583 1.344 0.011
## (0.007) (0.006) (0.006) (0.007) (0.008) (0.730) (1.456) (0.007)
## factor(sfr_frac_cat)16 0.011 0.047*** -0.018 -0.014 -0.016 0.693 1.721 0.023**
## (0.012) (0.015) (0.016) (0.016) (0.019) (0.925) (1.668) (0.011)
## factor(sfr_frac_cat)17 0.034 0.054** -0.028 -0.043 -0.063 -1.001 -0.503 0.015
## (0.022) (0.022) (0.030) (0.045) (0.051) (0.951) (1.303) (0.014)
## log(med_income_2018) -0.031** 0.095*** 0.054** 0.070*** 0.071** -2.259 -4.659 0.111***
## (0.014) (0.031) (0.024) (0.025) (0.030) (1.529) (3.249) (0.016)
## log(white_frac_2018) 0.004 0.039* -0.017 -0.004 -0.031 0.484 0.920 0.013
## (0.012) (0.022) (0.023) (0.026) (0.032) (0.361) (0.584) (0.011)
## log(college_frac_2018) 0.015 -0.103*** -0.060*** -0.081*** -0.112*** -2.407 -5.690 -0.004
## (0.019) (0.028) (0.019) (0.022) (0.029) (2.329) (5.506) (0.013)
## log(total_population_2018) 0.084*** 0.043 0.104*** 0.117*** 0.122*** 1.753 1.817 -0.002
## (0.020) (0.030) (0.025) (0.029) (0.031) (1.203) (1.879) (0.016)
## median_age_2018 0.0001 0.003** 0.001 0.002** 0.003** 0.094 0.208 -0.003**
## (0.001) (0.001) (0.001) (0.001) (0.001) (0.085) (0.212) (0.001)
## log(no_of_homes_2018) -0.081*** -0.019 -0.121*** -0.120*** -0.118*** -1.891 -2.020 0.010
## (0.020) (0.030) (0.024) (0.028) (0.029) (1.231) (1.925) (0.015)
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Observations 2,671 1,573 2,423 2,422 2,423 531 531 531
## R2 0.038 0.500 0.707 0.682 0.653 0.098 0.079 0.587
## Adjusted R2 0.016 0.480 0.700 0.674 0.644 -0.004 -0.025 0.540
## Residual Std. Error 0.126 (df = 2611) 0.091 (df = 1513) 0.097 (df = 2363) 0.111 (df = 2362) 0.127 (df = 2363) 4.010 (df = 476) 7.739 (df = 476) 0.041 (df = 476)
## =================================================================================================================================================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
r <- list()
r[[1]] <- felm(pct_rent_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state,data=regsample)
r[[2]] <- felm(rent_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[3]] <- felm(zhvi_top_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[4]] <- felm(zhvi_middle_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[5]] <- felm(zhvi_bottom_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[6]] <- felm(oneunit_Units_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Units_change)])
r[[7]] <- felm(oneunit_Value_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
r[[8]] <- felm(pop_change~sfr_frac+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
stargazer(r,type="text",no.space = T)
##
## =================================================================================================================================================================================
## Dependent variable:
## ------------------------------------------------------------------------------------------------------------------------------------------------------
## pct_rent_change rent_change zhvi_top_change zhvi_middle_change zhvi_bottom_change oneunit_Units_change oneunit_Value_change pop_change
## (1) (2) (3) (4) (5) (6) (7) (8)
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## sfr_frac 0.053* 0.130*** 0.004 0.025 0.044 2.653 4.844 0.040*
## (0.029) (0.045) (0.069) (0.086) (0.112) (2.424) (3.916) (0.022)
## log(med_income_2018) -0.033** 0.092*** 0.050** 0.064** 0.063** -2.483 -5.026 0.109***
## (0.014) (0.032) (0.025) (0.025) (0.030) (1.547) (3.307) (0.017)
## log(white_frac_2018) 0.005 0.040* -0.016 -0.004 -0.031 0.592* 1.105* 0.014
## (0.012) (0.022) (0.023) (0.026) (0.032) (0.347) (0.608) (0.012)
## log(college_frac_2018) 0.014 -0.102*** -0.060*** -0.081*** -0.111*** -2.467 -5.774 -0.005
## (0.019) (0.027) (0.019) (0.022) (0.030) (2.261) (5.376) (0.014)
## log(total_population_2018) 0.083*** 0.038 0.109*** 0.124*** 0.133*** 2.028 2.194 0.0001
## (0.020) (0.031) (0.026) (0.032) (0.034) (1.252) (1.971) (0.016)
## median_age_2018 0.00003 0.002* 0.001 0.002* 0.003** 0.093 0.208 -0.003*
## (0.001) (0.001) (0.001) (0.001) (0.001) (0.084) (0.213) (0.001)
## log(no_of_homes_2018) -0.082*** -0.014 -0.126*** -0.127*** -0.129*** -2.144* -2.354 0.008
## (0.020) (0.031) (0.025) (0.031) (0.031) (1.274) (2.008) (0.016)
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Observations 2,671 1,573 2,423 2,422 2,423 531 531 531
## R2 0.037 0.498 0.706 0.682 0.652 0.096 0.077 0.584
## Adjusted R2 0.016 0.479 0.699 0.674 0.643 -0.002 -0.024 0.538
## Residual Std. Error 0.126 (df = 2613) 0.091 (df = 1515) 0.097 (df = 2365) 0.111 (df = 2364) 0.127 (df = 2365) 4.006 (df = 478) 7.733 (df = 478) 0.041 (df = 478)
## =================================================================================================================================================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
r <- list()
r[[1]] <- felm(pct_rent_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state,data=regsample)
r[[2]] <- felm(rent_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[3]] <- felm(zhvi_top_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[4]] <- felm(zhvi_middle_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[5]] <- felm(zhvi_bottom_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample)
r[[6]] <- felm(oneunit_Units_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Units_change)])
r[[7]] <- felm(oneunit_Value_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
r[[8]] <- felm(pop_change~factor(sfr_frac_change_cat)+log(med_income_2018)+log(white_frac_2018)+log(college_frac_2018)+log(total_population_2018)+median_age_2018+log(no_of_homes_2018)|state|0|state,data=regsample[is.finite(oneunit_Value_change)])
stargazer(r,type="text",no.space = T)
##
## ===================================================================================================================================================================================
## Dependent variable:
## ------------------------------------------------------------------------------------------------------------------------------------------------------
## pct_rent_change rent_change zhvi_top_change zhvi_middle_change zhvi_bottom_change oneunit_Units_change oneunit_Value_change pop_change
## (1) (2) (3) (4) (5) (6) (7) (8)
## -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## factor(sfr_frac_change_cat)4 -0.025*** -0.010 -0.009 -0.017 -0.026** 0.192 -0.416 -0.002
## (0.008) (0.009) (0.010) (0.010) (0.012) (0.348) (0.654) (0.008)
## factor(sfr_frac_change_cat)5 -0.024*** 0.020* -0.021** -0.025*** -0.034*** 0.737 1.000 0.009
## (0.009) (0.010) (0.008) (0.008) (0.011) (0.736) (1.574) (0.011)
## log(med_income_2018) -0.029** 0.097*** 0.053** 0.069*** 0.070** -2.265 -4.707 0.111***
## (0.014) (0.032) (0.023) (0.025) (0.030) (1.515) (3.240) (0.016)
## log(white_frac_2018) 0.007 0.038* -0.016 -0.003 -0.030 0.472 1.000 0.012
## (0.012) (0.021) (0.022) (0.026) (0.032) (0.407) (0.692) (0.012)
## log(college_frac_2018) 0.017 -0.103*** -0.058*** -0.079*** -0.108*** -2.438 -5.682 -0.004
## (0.019) (0.028) (0.019) (0.021) (0.028) (2.323) (5.502) (0.013)
## log(total_population_2018) 0.084*** 0.039 0.107*** 0.122*** 0.130*** 1.910 2.108 -0.001
## (0.020) (0.033) (0.026) (0.032) (0.034) (1.236) (1.884) (0.015)
## median_age_2018 0.0001 0.003** 0.001 0.002** 0.003** 0.094 0.208 -0.003*
## (0.001) (0.001) (0.001) (0.001) (0.001) (0.083) (0.209) (0.001)
## log(no_of_homes_2018) -0.080*** -0.015 -0.123*** -0.124*** -0.125*** -2.040 -2.285 0.008
## (0.020) (0.032) (0.025) (0.030) (0.031) (1.271) (1.954) (0.015)
## -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Observations 2,671 1,573 2,423 2,422 2,423 531 531 531
## R2 0.039 0.498 0.707 0.683 0.653 0.096 0.078 0.585
## Adjusted R2 0.018 0.479 0.700 0.675 0.645 -0.004 -0.024 0.539
## Residual Std. Error 0.126 (df = 2612) 0.091 (df = 1514) 0.097 (df = 2364) 0.111 (df = 2363) 0.127 (df = 2364) 4.011 (df = 477) 7.735 (df = 477) 0.041 (df = 477)
## ===================================================================================================================================================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
evictions <- fread("/data/zillow research data/eviction_county.csv")
evictions[,fips:=GEOID]
temp_eviction <- evictions[year %in% 2005:2011]
temp_eviction <- temp_eviction[,.(hist_eviction_rate=mean(eviction.rate,na.rm=T)),by=fips]
temp_eviction[,hist_eviction_cat:=ntile(hist_eviction_rate,5)]
sfr_county_cumalative <- merge(sfr_county_cumalative,temp_eviction,by="fips",all.x=T)
temp <- sfr_county_cumalative[!is.na(hist_eviction_cat),.(no_of_sfr_homes=sum(no_of_sfr_homes,na.rm = T)),by=.(year,hist_eviction_cat)]
ggplot(temp,aes(x=year,y=no_of_sfr_homes,color=factor(hist_eviction_cat)))+geom_line()