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 Keep New Orlean MSA as treated MSA.
library(readxl)
library(ggplot2)
library(readr)
library(dplyr)
library(stringr)
library(plm)
library(lmtest)
RENT.merge<-read_xlsx("MSA-RENT merge All.xlsx")
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"
# 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])
}
#KEEP NEW ORLEAN
RENT.merge1<-RENT.merge
RENT.merge1$NS<-paste0(RENT.merge1$FirstNAME,RENT.merge1$state)
RENT.NEWLA<-RENT.merge1%>%
filter(NS=="newLA")
RENTUS<-RENT.merge1%>%
filter(state!="LA")
RENT.merge1<-RENT.merge1%>%
filter(NS!="newLA")
## WITH NEW ORLEAN ONLY
RENT.merge2<-rbind(RENT.NEWLA,RENTUS)
mpl.00<-plm(log(RENT_0)~treat+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),
data = RENT.merge2, model = "within",cluster="MSA", index=c("MSA", "YEAR"))
summary(mpl.00)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(RENT_0) ~ treat + 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), data = RENT.merge2,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 211, T = 13-15, N = 3133
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.3973123 -0.0470342 0.0042402 0.0500234 0.2914407
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 1.3834e-03 7.2700e-05 19.0288 < 2.2e-16 ***
## Unemployee.Rate 3.2779e-02 8.8183e-04 37.1717 < 2.2e-16 ***
## Personal.Income 1.9273e-05 3.9110e-07 49.2782 < 2.2e-16 ***
## Resident.Population -9.6395e-05 1.9481e-05 -4.9481 7.92e-07 ***
## treat:d.2001 -1.6210e-01 1.1698e-01 -1.3857 0.1659
## treat:d.2002 -7.7571e-03 1.1698e-01 -0.0663 0.9471
## treat:d.2003 3.8767e-03 1.1698e-01 0.0331 0.9736
## treat:d.2005 -2.8043e-02 1.1701e-01 -0.2397 0.8106
## treat:d.2006 1.8909e-01 1.1727e-01 1.6123 0.1070
## treat:d.2007 1.8012e-01 1.1721e-01 1.5367 0.1245
## treat:d.2008 1.7926e-01 1.1715e-01 1.5301 0.1261
## treat:d.2009 1.4126e-01 1.1709e-01 1.2064 0.2278
## treat:d.2010 1.3827e-01 1.1711e-01 1.1807 0.2378
## treat:d.2011 1.5960e-01 1.1709e-01 1.3630 0.1730
## treat:d.2012 6.8303e-02 1.1712e-01 0.5832 0.5598
## treat:d.2013 -4.7349e-02 1.1711e-01 -0.4043 0.6860
## treat:d.2014 -7.7655e-02 1.1714e-01 -0.6629 0.5074
## treat:d.2015 -9.2802e-02 1.1715e-01 -0.7922 0.4283
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 76.132
## Residual Sum of Squares: 19.867
## R-Squared: 0.73904
## Adj. R-Squared: 0.71855
## F-statistic: 456.902 on 18 and 2904 DF, p-value: < 2.22e-16
#coef_df1 <- data.frame(summary(mpl.00)$coefficients)[5:18,]
coef_df <- coeftest(mpl.00,vcov. = vcovHC(mpl.00,type = "HC1"))
coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
se = coef_df$`Std. Error`)
event_df<-rbind(event_df,c("time"=3.5,"coef"=0,"se"=0))
event_df<-arrange(event_df,time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
# 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, ]
library(ggplot2)
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
png("FE RENT0 V6-2004.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png
## 2
mpl.01<-plm(log(RENT_1)~treat+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),
data = RENT.merge2, model = "within",cluster="MSA", index=c("MSA", "YEAR"))
summary(mpl.01)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(RENT_1) ~ treat + 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), data = RENT.merge2,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 211, T = 13-15, N = 3133
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.4081731 -0.0342472 0.0010796 0.0348875 0.2440099
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 7.9583e-04 5.3321e-05 14.9252 < 2e-16 ***
## Unemployee.Rate 2.6561e-02 6.4677e-04 41.0666 < 2e-16 ***
## Personal.Income 1.8589e-05 2.8685e-07 64.8030 < 2e-16 ***
## Resident.Population -3.0593e-05 1.4288e-05 -2.1411 0.03235 *
## treat:d.2001 -1.7876e-01 8.5802e-02 -2.0834 0.03731 *
## treat:d.2002 -1.5711e-02 8.5798e-02 -0.1831 0.85472
## treat:d.2003 -1.3608e-03 8.5795e-02 -0.0159 0.98735
## treat:d.2005 -3.8695e-02 8.5820e-02 -0.4509 0.65210
## treat:d.2006 2.0448e-01 8.6014e-02 2.3773 0.01750 *
## treat:d.2007 1.8881e-01 8.5970e-02 2.1963 0.02815 *
## treat:d.2008 1.8583e-01 8.5925e-02 2.1627 0.03065 *
## treat:d.2009 1.5477e-01 8.5880e-02 1.8022 0.07162 .
## treat:d.2010 1.5215e-01 8.5892e-02 1.7714 0.07661 .
## treat:d.2011 1.7043e-01 8.5881e-02 1.9845 0.04729 *
## treat:d.2012 7.4596e-02 8.5901e-02 0.8684 0.38525
## treat:d.2013 2.4918e-02 8.5892e-02 0.2901 0.77175
## treat:d.2014 -2.7437e-03 8.5918e-02 -0.0319 0.97453
## treat:d.2015 -1.3870e-02 8.5921e-02 -0.1614 0.87177
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 55.708
## Residual Sum of Squares: 10.687
## R-Squared: 0.80815
## Adj. R-Squared: 0.79309
## F-statistic: 679.614 on 18 and 2904 DF, p-value: < 2.22e-16
#coef_df <- data.frame(summary(mpl.01)$coefficients)[5:18,]
coef_df <- coeftest(mpl.01,vcov. = vcovHC(mpl.01,type = "HC1"))
coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
se = coef_df$`Std. Error`)
event_df<-rbind(event_df,c("time"=3.5,"coef"=0,"se"=0))
event_df<-arrange(event_df,time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
# 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, ]
library(ggplot2)
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_1") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl
png("FE RENT1 V6-2004.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png
## 2
mpl.02<-plm(log(RENT_2)~treat+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),
data = RENT.merge2, model = "within",cluster="MSA", index=c("MSA", "YEAR"))
summary(mpl.02)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(RENT_2) ~ treat + 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), data = RENT.merge2,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 211, T = 13-15, N = 3133
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.3741538 -0.0341744 -0.0012902 0.0326357 0.2722585
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 2.6509e-04 5.4390e-05 4.8739 1.153e-06 ***
## Unemployee.Rate 2.1328e-02 6.5973e-04 32.3288 < 2.2e-16 ***
## Personal.Income 2.0539e-05 2.9260e-07 70.1950 < 2.2e-16 ***
## Resident.Population -3.8769e-05 1.4575e-05 -2.6601 0.007856 **
## treat:d.2001 -1.8897e-01 8.7521e-02 -2.1591 0.030921 *
## treat:d.2002 -2.3523e-02 8.7517e-02 -0.2688 0.788113
## treat:d.2003 -3.4964e-03 8.7514e-02 -0.0400 0.968133
## treat:d.2005 -7.1691e-02 8.7539e-02 -0.8190 0.412875
## treat:d.2006 1.4380e-01 8.7738e-02 1.6390 0.101317
## treat:d.2007 1.2192e-01 8.7692e-02 1.3903 0.164534
## treat:d.2008 1.2028e-01 8.7647e-02 1.3723 0.170080
## treat:d.2009 1.0366e-01 8.7600e-02 1.1834 0.236754
## treat:d.2010 9.8451e-02 8.7613e-02 1.1237 0.261233
## treat:d.2011 1.1586e-01 8.7602e-02 1.3226 0.186076
## treat:d.2012 3.3477e-03 8.7622e-02 0.0382 0.969526
## treat:d.2013 1.1569e-02 8.7613e-02 0.1320 0.894960
## treat:d.2014 -1.8170e-02 8.7639e-02 -0.2073 0.835772
## treat:d.2015 -2.6562e-02 8.7642e-02 -0.3031 0.761854
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 54.608
## Residual Sum of Squares: 11.12
## R-Squared: 0.79637
## Adj. R-Squared: 0.78038
## F-statistic: 630.947 on 18 and 2904 DF, p-value: < 2.22e-16
coef_df <- coeftest(mpl.02,vcov. = vcovHC(mpl.02,type = "HC1"))
coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
se = coef_df$`Std. Error`)
event_df<-rbind(event_df,c("time"=3.5,"coef"=0,"se"=0))
event_df<-arrange(event_df,time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
# 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, ]
library(ggplot2)
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_2") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl
png("FE RENT2 V6-2004.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png
## 2
mpl.03<-plm(log(RENT_3)~treat+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),
data = RENT.merge2, model = "within",cluster="MSA", index=c("MSA", "YEAR"))
summary(mpl.03)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(RENT_3) ~ treat + 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), data = RENT.merge2,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 211, T = 13-15, N = 3133
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -4.0167e-01 -3.8377e-02 -7.1718e-05 3.6628e-02 2.7543e-01
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 2.8818e-04 5.8537e-05 4.9231 8.994e-07 ***
## Unemployee.Rate 2.0825e-02 7.1004e-04 29.3294 < 2.2e-16 ***
## Personal.Income 2.1631e-05 3.1491e-07 68.6896 < 2.2e-16 ***
## Resident.Population -5.1828e-05 1.5686e-05 -3.3041 0.0009643 ***
## treat:d.2001 -1.8633e-01 9.4194e-02 -1.9781 0.0480100 *
## treat:d.2002 -2.1388e-02 9.4190e-02 -0.2271 0.8203851
## treat:d.2003 -2.9315e-03 9.4187e-02 -0.0311 0.9751730
## treat:d.2005 -1.1546e-01 9.4214e-02 -1.2255 0.2204716
## treat:d.2006 8.4032e-02 9.4428e-02 0.8899 0.3735915
## treat:d.2007 5.8691e-02 9.4379e-02 0.6219 0.5340787
## treat:d.2008 5.8444e-02 9.4330e-02 0.6196 0.5355901
## treat:d.2009 4.6520e-02 9.4280e-02 0.4934 0.6217541
## treat:d.2010 4.0364e-02 9.4294e-02 0.4281 0.6686344
## treat:d.2011 5.8328e-02 9.4282e-02 0.6187 0.5361943
## treat:d.2012 -7.1377e-02 9.4303e-02 -0.7569 0.4491796
## treat:d.2013 -8.6599e-02 9.4294e-02 -0.9184 0.3584869
## treat:d.2014 -1.1830e-01 9.4322e-02 -1.2542 0.2098619
## treat:d.2015 -1.2820e-01 9.4325e-02 -1.3591 0.1742233
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 59.509
## Residual Sum of Squares: 12.88
## R-Squared: 0.78356
## Adj. R-Squared: 0.76656
## F-statistic: 584.051 on 18 and 2904 DF, p-value: < 2.22e-16
coef_df <- coeftest(mpl.03,vcov. = vcovHC(mpl.03,type = "HC1"))
coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
se = coef_df$`Std. Error`)
event_df<-rbind(event_df,c("time"=3.5,"coef"=0,"se"=0))
event_df<-arrange(event_df,time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
# 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, ]
library(ggplot2)
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_3") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl
png("FE RENT3 V6-2004.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png
## 2
mpl.04<-plm(log(RENT_4)~treat+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),
data = RENT.merge2, model = "within",cluster="MSA", index=c("MSA", "YEAR"))
summary(mpl.04)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = log(RENT_4) ~ treat + 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), data = RENT.merge2,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 211, T = 13-15, N = 3133
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.35946066 -0.04439405 -0.00041669 0.04489418 0.31650855
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 1.3303e-04 6.8215e-05 1.9501 0.05126 .
## Unemployee.Rate 1.8216e-02 8.2743e-04 22.0155 < 2e-16 ***
## Personal.Income 2.2017e-05 3.6697e-07 59.9972 < 2e-16 ***
## Resident.Population -2.7784e-05 1.8279e-05 -1.5200 0.12863
## treat:d.2001 -1.8988e-01 1.0977e-01 -1.7298 0.08377 .
## treat:d.2002 -2.1526e-02 1.0976e-01 -0.1961 0.84454
## treat:d.2003 -3.5369e-03 1.0976e-01 -0.0322 0.97430
## treat:d.2005 -2.1411e-01 1.0979e-01 -1.9501 0.05126 .
## treat:d.2006 -1.7754e-02 1.1004e-01 -0.1613 0.87183
## treat:d.2007 -4.8064e-02 1.0998e-01 -0.4370 0.66213
## treat:d.2008 -4.8534e-02 1.0993e-01 -0.4415 0.65888
## treat:d.2009 -5.4867e-02 1.0987e-01 -0.4994 0.61754
## treat:d.2010 -6.1174e-02 1.0988e-01 -0.5567 0.57777
## treat:d.2011 -4.4295e-02 1.0987e-01 -0.4032 0.68686
## treat:d.2012 -2.2538e-01 1.0990e-01 -2.0509 0.04037 *
## treat:d.2013 -8.2016e-02 1.0988e-01 -0.7464 0.45549
## treat:d.2014 -1.1561e-01 1.0992e-01 -1.0518 0.29297
## treat:d.2015 -1.2401e-01 1.0992e-01 -1.1282 0.25932
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 62.981
## Residual Sum of Squares: 17.492
## R-Squared: 0.72227
## Adj. R-Squared: 0.70047
## F-statistic: 419.569 on 18 and 2904 DF, p-value: < 2.22e-16
coef_df <- coeftest(mpl.04,vcov. = vcovHC(mpl.04,type = "HC1"))
coef_df <- coef_df[,]%>%as_tibble()%>%mutate(variables=rownames(coef_df))
coef_df <- coef_df[5:18,]
event_df <- data.frame(time = 1:nrow(coef_df),
coef = coef_df$Estimate,
se = coef_df$`Std. Error`)
event_df<-rbind(event_df,c("time"=3.5,"coef"=0,"se"=0))
event_df<-arrange(event_df,time)
# Calculate confidence intervals
event_df$ci_upper <- event_df$coef + 1.96 * event_df$se
event_df$ci_lower <- event_df$coef - 1.96 * event_df$se
# 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, ]
library(ggplot2)
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_4") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+theme_bw()
pl
png("FE RENT4 V6-2004.png",width = 7.70,height = 6.0,units = "in",res = 500)
pl
dev.off()
## png
## 2