The data set contain information for Rental price base on additional number of room in MSA levels, observation start in 2001 to 2005 with annual frequency observation, its also contain information like Unemployee Rate,Personal Income and Resident Population.
We also create dummy date that indicate, an observation happens in a specifict year, for example A has observation in 2002, so d.2002 will assign to 1.
We log response variables, and regress with other variables but in event study we will focus on time effect in this case is dummy time, treatment is for every msa that in LA is equal to 1, and non-LA is 0.
-NOTE : In this analysis, we exclude New Orlean MSA.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(readr)
library(dplyr)
library(stringr)
library(plm)
##
## Attaching package: 'plm'
##
## The following objects are masked from 'package:dplyr':
##
## between, lag, lead
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(lfe)
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
##
##
## Attaching package: 'lfe'
##
## The following object is masked from 'package:lmtest':
##
## waldtest
##
## The following object is masked from 'package:plm':
##
## sargan
library(conleyreg)
RENT.merge <- read.csv("MSA-RENT merge All.csv")
RENT.merge$treat <- ifelse(RENT.merge$state == "LA", 1, 0)
colnames(RENT.merge)
## [1] "FirstNAME" "AREANAME" "RENT_0"
## [4] "RENT_1" "RENT_2" "RENT_3"
## [7] "RENT_4" "YEAR" "NAME.x"
## [10] "state" "Unemployee.Rate" "Personal.Income"
## [13] "Resident.Population" "nyear" "MSA"
## [16] "MSA.Code" "Price" "Change"
## [19] "NAME.y" "treat"
lat_long <- read.csv("rent data new.csv") %>%
distinct(X, Y, AREANAME)
RENT.merge <- RENT.merge %>%
merge(lat_long, by = "AREANAME")
# Remove NA
RENT.merge <- RENT.merge %>%
group_by(MSA) %>%
filter(!any(is.na(Unemployee.Rate)))
dloop <- data.frame(YEAR = unique(RENT.merge$YEAR))
## YEAR DUMMY
for (i in 1:nrow(dloop)) {
RENT.merge[paste0("d.", dloop$YEAR[i])] <- as.numeric(RENT.merge$YEAR == unique(RENT.merge$YEAR)[i])
}
#REMOVE NEW ORLEAN
RENT.merge1 <- RENT.merge
RENT.merge1$NS <- paste0(RENT.merge1$FirstNAME, RENT.merge1$state)
RENT.merge1 <- RENT.merge1 %>%
filter(NS != "newLA")
cse <- conleyreg(log(RENT_0) ~ Price + Unemployee.Rate +
Personal.Income + Resident.Population +
treat:(d.2001 + d.2002 + d.2003 +
d.2005 + d.2006 + d.2007 + d.2008 +
d.2009 + d.2010 + d.2011 + d.2012 +
d.2013 + d.2014 + d.2015) | MSA + YEAR,
data = RENT.merge1,
dist_cutoff = 300,
st_distance = TRUE,
lat = "Y",
lon = "X",
)
## Checking spatial attributes
## Estimating model
## Warning: In fixest_env(fml = fml, data = data, weights = weig...:
## OpenMP not detected: cannot use 4 threads, single-threaded mode instead.
## Estimating distance matrix and addressing spatial correlation
summary(cse)
## Estimate Std. Error t value Pr(>|t|)
## Min. :-0.008954 Min. :1.540e-06 Min. :-2.962 Min. :0.0000000
## 1st Qu.: 0.004661 1st Qu.:3.542e-03 1st Qu.: 2.654 1st Qu.:0.0000012
## Median : 0.139020 Median :2.375e-02 Median : 3.088 Median :0.0020354
## Mean : 0.100705 Mean :2.602e-02 Mean : 3.355 Mean :0.0546839
## 3rd Qu.: 0.153325 3rd Qu.:4.799e-02 3rd Qu.: 4.869 3rd Qu.:0.0043354
## Max. : 0.223425 Max. :5.519e-02 Max. : 8.706 Max. :0.5022836
colnames(cse)[2] <- "Conley SE"
coef_df <- cse[,] %>%
as_tibble() %>%
mutate(variables = rownames(cse))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
cse = coef_df$`Conley SE`)
event_df <- rbind(event_df, c("time" = 3.5, "coef" = 0, "cse" = 0))
event_df <- arrange(event_df, time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$cse
event_df$ci_lower <- event_df$coef - 1.96 * event_df$cse
# Extract dates from row names of coef_df
##dates <- as.Date(paste0(row.names(coef_df),"0101"), format = "treat:YEAR%Y%m%d")
dates<-seq.Date(from = as.Date("2001-01-01"),as.Date("2015-01-01"),by="year")
# Define start and end dates for plot
start_date <- as.Date("2001-01-01")
end_date <- as.Date("2015-01-01")
# Create sequence of dates for x-axis
dates_seq <- seq(from = start_date, to = end_date, by = "year")
# Subset event_df to only include dates after or equal to start_date
event_df_sub <- event_df[dates >= start_date, ]
pl <- ggplot(event_df, aes(x = dates, y = coef)) +
geom_point() +geom_line()+
#geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
geom_vline(xintercept = as.Date("2005-01-01"), linetype = "dashed", color = "blue") +
scale_x_date(date_labels = "%Y", limits = c(start_date, end_date), breaks = "1 year") +
labs(x = "Year", y = "Coefficient")+ #title = "Fixed effect of RENT_0") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl
cse.01 <- conleyreg(log(RENT_1) ~ Price + Unemployee.Rate +
Personal.Income + Resident.Population +
treat:(d.2001 + d.2002 + d.2003 +
d.2005 + d.2006 + d.2007 + d.2008 +
d.2009 + d.2010 + d.2011 + d.2012 +
d.2013 + d.2014 + d.2015) | MSA + YEAR,
data = RENT.merge1,
dist_cutoff = 300,
st_distance = TRUE,
lat = "Y",
lon = "X",
)
## Checking spatial attributes
## Estimating model
## Warning: In fixest_env(fml = fml, data = data, weights = weig...:
## OpenMP not detected: cannot use 4 threads, single-threaded mode instead.
## Estimating distance matrix and addressing spatial correlation
summary(cse.01)
## Estimate Std. Error t value Pr(>|t|)
## Min. :-0.002152 Min. :1.590e-06 Min. :-1.114 Min. :0.0000000
## 1st Qu.: 0.004093 1st Qu.:3.534e-03 1st Qu.: 2.403 1st Qu.:0.0000016
## Median : 0.112949 Median :2.845e-02 Median : 3.141 Median :0.0017382
## Mean : 0.085683 Mean :2.236e-02 Mean : 3.292 Mean :0.0935103
## 3rd Qu.: 0.147151 3rd Qu.:3.836e-02 3rd Qu.: 4.813 3rd Qu.:0.0166443
## Max. : 0.189712 Max. :4.447e-02 Max. : 6.566 Max. :0.7080520
colnames(cse.01)[2] <- "Conley SE"
coef_df1 <- cse.01[,] %>%
as_tibble() %>%
mutate(variables = rownames(cse.01))
coef_df1 <- coef_df1[5:18,]
event_df1 <- data.frame(time = 1:nrow(coef_df1),
coef = coef_df1$Estimate,
cse = coef_df1$`Conley SE`)
event_df1 <- rbind(event_df1, c("time" = 3.5, "coef" = 0, "cse" = 0))
event_df1 <- arrange(event_df1, time)
# Calculate confidence intervals
event_df1$ci_upper <- event_df1$coef + 1.96 * event_df1$cse
event_df1$ci_lower <- event_df1$coef - 1.96 * event_df1$cse
# Subset event_df to only include dates after or equal to start_date
event_df_sub1 <- event_df1[dates >= start_date, ]
pl1 <- ggplot(event_df1, aes(x = dates, y = coef)) +
geom_point() +geom_line()+
#geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
geom_vline(xintercept = as.Date("2005-01-01"), linetype = "dashed", color = "blue") +
scale_x_date(date_labels = "%Y", limits = c(start_date, end_date), breaks = "1 year") +
labs(x = "Year", y = "Coefficient")+ #title = "Fixed effect of RENT_1") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl1
cse.02 <- conleyreg(log(RENT_2) ~ Price + Unemployee.Rate +
Personal.Income + Resident.Population +
treat:(d.2001 + d.2002 + d.2003 +
d.2005 + d.2006 + d.2007 + d.2008 +
d.2009 + d.2010 + d.2011 + d.2012 +
d.2013 + d.2014 + d.2015) | MSA + YEAR,
data = RENT.merge1,
dist_cutoff = 300,
st_distance = TRUE,
lat = "Y",
lon = "X",
)
## Checking spatial attributes
## Estimating model
## Warning: In fixest_env(fml = fml, data = data, weights = weig...:
## OpenMP not detected: cannot use 4 threads, single-threaded mode instead.
## Estimating distance matrix and addressing spatial correlation
summary(cse.02)
## Estimate Std. Error t value Pr(>|t|)
## Min. :-0.0000587 Min. :1.460e-06 Min. :-1.512 Min. :0.0000000
## 1st Qu.: 0.0048068 1st Qu.:3.029e-03 1st Qu.: 1.823 1st Qu.:0.0001548
## Median : 0.0978249 Median :3.106e-02 Median : 2.832 Median :0.0053218
## Mean : 0.0753652 Mean :2.328e-02 Mean : 2.800 Mean :0.0956764
## 3rd Qu.: 0.1252505 3rd Qu.:3.899e-02 3rd Qu.: 3.789 3rd Qu.:0.0729289
## Max. : 0.1740518 Max. :4.702e-02 Max. : 5.879 Max. :0.8783613
colnames(cse.02)[2] <- "Conley SE"
coef_df2 <- cse.02[,] %>%
as_tibble() %>%
mutate(variables = rownames(cse.02))
coef_df2 <- coef_df2[5:18,]
event_df2 <- data.frame(time = 1:nrow(coef_df2),
coef = coef_df2$Estimate,
cse = coef_df2$`Conley SE`)
event_df2 <- rbind(event_df2, c("time" = 3.5, "coef" = 0, "cse" = 0))
event_df2 <- arrange(event_df2, time)
# Calculate confidence intervals
event_df2$ci_upper <- event_df2$coef + 1.96 * event_df2$cse
event_df2$ci_lower <- event_df2$coef - 1.96 * event_df2$cse
# Subset event_df to only include dates after or equal to start_date
event_df_sub2 <- event_df2[dates >= start_date, ]
pl2 <- ggplot(event_df2, aes(x = dates, y = coef)) +
geom_point() +
geom_line() +
#geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
geom_vline(xintercept = as.Date("2005-01-01"), linetype = "dashed", color = "blue") +
scale_x_date(date_labels = "%Y", limits = c(start_date, end_date), breaks = "1 year") +
labs(x = "Year", y = "Coefficient")+ #title = "Fixed effect of RENT_1") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl2
cse.03 <- conleyreg(log(RENT_3) ~ Price + Unemployee.Rate +
Personal.Income + Resident.Population +
treat:(d.2001 + d.2002 + d.2003 +
d.2005 + d.2006 + d.2007 + d.2008 +
d.2009 + d.2010 + d.2011 + d.2012 +
d.2013 + d.2014 + d.2015) | MSA + YEAR,
data = RENT.merge1,
dist_cutoff = 300,
st_distance = TRUE,
lat = "Y",
lon = "X",
)
## Checking spatial attributes
## Estimating model
## Warning: In fixest_env(fml = fml, data = data, weights = weig...:
## OpenMP not detected: cannot use 4 threads, single-threaded mode instead.
## Estimating distance matrix and addressing spatial correlation
summary(cse.03)
## Estimate Std. Error t value Pr(>|t|)
## Min. :-0.03717 Min. :1.630e-06 Min. :-2.757 Min. :0.0000012
## 1st Qu.: 0.00216 1st Qu.:3.168e-03 1st Qu.: 1.002 1st Qu.:0.0025270
## Median : 0.03308 Median :2.931e-02 Median : 1.159 Median :0.0641967
## Mean : 0.03729 Mean :2.260e-02 Mean : 1.618 Mean :0.1677719
## 3rd Qu.: 0.06570 3rd Qu.:3.855e-02 3rd Qu.: 2.998 3rd Qu.:0.2891091
## Max. : 0.11612 Max. :4.686e-02 Max. : 4.863 Max. :0.7698475
colnames(cse.03)[2] <- "Conley SE"
coef_df3 <- cse.03[,] %>%
as_tibble() %>%
mutate(variables = rownames(cse.03))
coef_df3 <- coef_df3[5:18,]
event_df3 <- data.frame(time = 1:nrow(coef_df3),
coef = coef_df3$Estimate,
cse = coef_df3$`Conley SE`)
event_df3 <- rbind(event_df3, c("time" = 3.5, "coef" = 0, "cse" = 0))
event_df3 <- arrange(event_df3, time)
# Calculate confidence intervals
event_df3$ci_upper <- event_df3$coef + 1.96 * event_df3$cse
event_df3$ci_lower <- event_df3$coef - 1.96 * event_df3$cse
# Subset event_df to only include dates after or equal to start_date
event_df_sub3 <- event_df3[dates >= start_date, ]
pl3 <- ggplot(event_df3, aes(x = dates, y = coef)) +
geom_point() +
geom_line() +
#geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
geom_vline(xintercept = as.Date("2005-01-01"), linetype = "dashed", color = "blue") +
scale_x_date(date_labels = "%Y", limits = c(start_date, end_date), breaks = "1 year") +
labs(x = "Year", y = "Coefficient")+ #title = "Fixed effect of RENT_1") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl3
cse.04 <- conleyreg(log(RENT_4) ~ Price + Unemployee.Rate +
Personal.Income + Resident.Population +
treat:(d.2001 + d.2002 + d.2003 +
d.2005 + d.2006 + d.2007 + d.2008 +
d.2009 + d.2010 + d.2011 + d.2012 +
d.2013 + d.2014 + d.2015) | MSA + YEAR,
data = RENT.merge1,
dist_cutoff = 300,
st_distance = TRUE,
lat = "Y",
lon = "X",
)
## Checking spatial attributes
## Estimating model
## Warning: In fixest_env(fml = fml, data = data, weights = weig...:
## OpenMP not detected: cannot use 4 threads, single-threaded mode instead.
## Estimating distance matrix and addressing spatial correlation
summary(cse.04)
## Estimate Std. Error t value Pr(>|t|)
## Min. :-0.020702 Min. :1.530e-06 Min. :-1.1345 Min. :0.000044
## 1st Qu.: 0.001065 1st Qu.:3.808e-03 1st Qu.: 0.8011 1st Qu.:0.046391
## Median : 0.043585 Median :4.620e-02 Median : 1.2665 Median :0.202326
## Mean : 0.041458 Mean :3.474e-02 Mean : 1.3784 Mean :0.225434
## 3rd Qu.: 0.077712 3rd Qu.:5.730e-02 3rd Qu.: 2.0070 3rd Qu.:0.341358
## Max. : 0.116887 Max. :6.320e-02 Max. : 4.0916 Max. :0.712055
colnames(cse.04)[2] <- "Conley SE"
coef_df4 <- cse.04[,] %>%
as_tibble() %>%
mutate(variables = rownames(cse.04))
coef_df4 <- coef_df4[5:18,]
event_df4 <- data.frame(time = 1:nrow(coef_df4),
coef = coef_df4$Estimate,
cse = coef_df4$`Conley SE`)
event_df4 <- rbind(event_df4, c("time" = 3.5, "coef" = 0, "cse" = 0))
event_df4 <- arrange(event_df4, time)
# Calculate confidence intervals
event_df4$ci_upper <- event_df4$coef + 1.96 * event_df4$cse
event_df4$ci_lower <- event_df4$coef - 1.96 * event_df4$cse
# Subset event_df to only include dates after or equal to start_date
event_df_sub4 <- event_df4[dates >= start_date, ]
pl4 <- ggplot(event_df4, aes(x = dates, y = coef)) +
geom_point() +
geom_line() +
#geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.2) +
geom_ribbon(aes(ymin = ci_lower, ymax = ci_upper), alpha = 0.2) +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
geom_vline(xintercept = as.Date("2005-01-01"), linetype = "dashed", color = "blue") +
scale_x_date(date_labels = "%Y", limits = c(start_date, end_date), breaks = "1 year") +
labs(x = "Year", y = "Coefficient")+ #title = "Fixed effect of RENT_1") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl4