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(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])
}
#REMOVE NEW ORLEAN
RENT.merge1<-RENT.merge
RENT.merge1$NS<-paste0(RENT.merge1$FirstNAME,RENT.merge1$state)
RENT.merge1<-RENT.merge1%>%
filter(NS!="newLA")
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.merge1, 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.merge1,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 217, T = 13-15, N = 3222
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.3965054 -0.0471874 0.0043075 0.0499550 0.2912199
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 1.3881e-03 7.2307e-05 19.1970 < 2.2e-16 ***
## Unemployee.Rate 3.2805e-02 8.7656e-04 37.4248 < 2.2e-16 ***
## Personal.Income 1.9228e-05 3.8867e-07 49.4710 < 2.2e-16 ***
## Resident.Population -9.6292e-05 1.9317e-05 -4.9849 6.552e-07 ***
## treat:d.2001 -2.3669e-03 4.5934e-02 -0.0515 0.9589087
## treat:d.2002 1.4756e-02 4.4005e-02 0.3353 0.7374080
## treat:d.2003 7.4871e-03 4.4003e-02 0.1701 0.8649049
## treat:d.2005 1.3581e-01 4.4012e-02 3.0857 0.0020490 **
## treat:d.2006 2.2810e-01 4.4063e-02 5.1767 2.408e-07 ***
## treat:d.2007 2.0255e-01 4.4093e-02 4.5938 4.533e-06 ***
## treat:d.2008 2.0138e-01 4.4143e-02 4.5620 5.270e-06 ***
## treat:d.2009 2.2302e-01 4.4103e-02 5.0569 4.519e-07 ***
## treat:d.2010 2.3531e-01 4.4120e-02 5.3333 1.036e-07 ***
## treat:d.2011 2.4490e-01 4.4132e-02 5.5493 3.119e-08 ***
## treat:d.2012 1.4332e-01 4.4169e-02 3.2447 0.0011886 **
## treat:d.2013 1.5904e-01 4.4186e-02 3.5993 0.0003243 ***
## treat:d.2014 1.1515e-01 4.4240e-02 2.6028 0.0092925 **
## treat:d.2015 1.0842e-01 4.4242e-02 2.4506 0.0143186 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 80.453
## Residual Sum of Squares: 20.238
## R-Squared: 0.74845
## Adj. R-Squared: 0.72874
## F-statistic: 493.746 on 18 and 2987 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.merge1, 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.merge1,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 217, T = 13-15, N = 3222
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.4077950 -0.0341142 0.0014903 0.0347124 0.2436659
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 7.9673e-04 5.3057e-05 15.0165 < 2.2e-16 ***
## Unemployee.Rate 2.6546e-02 6.4319e-04 41.2727 < 2.2e-16 ***
## Personal.Income 1.8564e-05 2.8519e-07 65.0927 < 2.2e-16 ***
## Resident.Population -2.7452e-05 1.4174e-05 -1.9368 0.0528657 .
## treat:d.2001 -6.7636e-03 3.3705e-02 -0.2007 0.8409702
## treat:d.2002 8.2296e-03 3.2290e-02 0.2549 0.7988441
## treat:d.2003 7.4780e-03 3.2288e-02 0.2316 0.8168647
## treat:d.2005 4.9955e-02 3.2295e-02 1.5469 0.1220028
## treat:d.2006 1.3091e-01 3.2332e-02 4.0489 5.276e-05 ***
## treat:d.2007 1.1467e-01 3.2354e-02 3.5444 0.0003996 ***
## treat:d.2008 1.1985e-01 3.2391e-02 3.7001 0.0002194 ***
## treat:d.2009 1.5368e-01 3.2362e-02 4.7489 2.142e-06 ***
## treat:d.2010 1.6812e-01 3.2374e-02 5.1932 2.206e-07 ***
## treat:d.2011 1.7754e-01 3.2383e-02 5.4824 4.546e-08 ***
## treat:d.2012 1.1472e-01 3.2410e-02 3.5397 0.0004067 ***
## treat:d.2013 1.4833e-01 3.2422e-02 4.5749 4.958e-06 ***
## treat:d.2014 1.0679e-01 3.2462e-02 3.2898 0.0010141 **
## treat:d.2015 1.0417e-01 3.2463e-02 3.2090 0.0013461 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 58.792
## Residual Sum of Squares: 10.896
## R-Squared: 0.81466
## Adj. R-Squared: 0.80014
## F-statistic: 729.413 on 18 and 2987 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.merge1, 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.merge1,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 217, T = 13-15, N = 3222
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.3738198 -0.0340896 -0.0016306 0.0325883 0.2723176
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 2.6762e-04 5.4075e-05 4.9490 7.874e-07 ***
## Unemployee.Rate 2.1327e-02 6.5554e-04 32.5338 < 2.2e-16 ***
## Personal.Income 2.0516e-05 2.9067e-07 70.5817 < 2.2e-16 ***
## Resident.Population -3.6208e-05 1.4446e-05 -2.5064 0.0122481 *
## treat:d.2001 -1.2776e-02 3.4352e-02 -0.3719 0.7099832
## treat:d.2002 4.9397e-03 3.2910e-02 0.1501 0.8806966
## treat:d.2003 8.7632e-03 3.2908e-02 0.2663 0.7900313
## treat:d.2005 1.2118e-03 3.2915e-02 0.0368 0.9706331
## treat:d.2006 7.3464e-02 3.2953e-02 2.2294 0.0258637 *
## treat:d.2007 5.9356e-02 3.2975e-02 1.8000 0.0719555 .
## treat:d.2008 6.3407e-02 3.3013e-02 1.9207 0.0548675 .
## treat:d.2009 1.1174e-01 3.2983e-02 3.3878 0.0007136 ***
## treat:d.2010 1.2834e-01 3.2995e-02 3.8896 0.0001026 ***
## treat:d.2011 1.3374e-01 3.3005e-02 4.0522 5.204e-05 ***
## treat:d.2012 5.6872e-02 3.3032e-02 1.7217 0.0852234 .
## treat:d.2013 1.4213e-01 3.3045e-02 4.3012 1.753e-05 ***
## treat:d.2014 9.9101e-02 3.3085e-02 2.9953 0.0027640 **
## treat:d.2015 1.0051e-01 3.3087e-02 3.0377 0.0024047 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 57.462
## Residual Sum of Squares: 11.319
## R-Squared: 0.80302
## Adj. R-Squared: 0.78759
## F-statistic: 676.5 on 18 and 2987 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.merge1, 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.merge1,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 217, T = 13-15, N = 3222
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.40133260 -0.03842115 -0.00034462 0.03632763 0.27529729
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 2.9095e-04 5.8172e-05 5.0016 6.015e-07 ***
## Unemployee.Rate 2.0835e-02 7.0520e-04 29.5447 < 2.2e-16 ***
## Personal.Income 2.1609e-05 3.1269e-07 69.1059 < 2.2e-16 ***
## Resident.Population -4.9687e-05 1.5540e-05 -3.1973 0.001402 **
## treat:d.2001 -9.9669e-03 3.6955e-02 -0.2697 0.787405
## treat:d.2002 7.7266e-03 3.5403e-02 0.2182 0.827249
## treat:d.2003 1.0936e-02 3.5401e-02 0.3089 0.757408
## treat:d.2005 -5.5652e-02 3.5408e-02 -1.5718 0.116114
## treat:d.2006 1.9893e-02 3.5449e-02 0.5612 0.574733
## treat:d.2007 3.2886e-03 3.5473e-02 0.0927 0.926142
## treat:d.2008 4.2068e-03 3.5514e-02 0.1185 0.905714
## treat:d.2009 5.5334e-02 3.5481e-02 1.5595 0.118977
## treat:d.2010 7.1763e-02 3.5495e-02 2.0218 0.043289 *
## treat:d.2011 7.5790e-02 3.5505e-02 2.1346 0.032873 *
## treat:d.2012 -1.3143e-02 3.5534e-02 -0.3699 0.711509
## treat:d.2013 7.4253e-02 3.5548e-02 2.0888 0.036809 *
## treat:d.2014 2.8868e-02 3.5592e-02 0.8111 0.417383
## treat:d.2015 3.0364e-02 3.5593e-02 0.8531 0.393672
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 61.885
## Residual Sum of Squares: 13.099
## R-Squared: 0.78834
## Adj. R-Squared: 0.77176
## F-statistic: 618.068 on 18 and 2987 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.merge1, 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.merge1,
## model = "within", index = c("MSA", "YEAR"), cluster = "MSA")
##
## Unbalanced Panel: n = 217, T = 13-15, N = 3222
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -0.35889562 -0.04484087 -0.00061547 0.04478693 0.31682201
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## Price 1.3894e-04 6.8178e-05 2.0379 0.04165 *
## Unemployee.Rate 1.8284e-02 8.2650e-04 22.1227 < 2e-16 ***
## Personal.Income 2.1985e-05 3.6647e-07 59.9919 < 2e-16 ***
## Resident.Population -2.6693e-05 1.8213e-05 -1.4656 0.14287
## treat:d.2001 -3.2548e-02 4.3311e-02 -0.7515 0.45241
## treat:d.2002 6.9065e-03 4.1492e-02 0.1665 0.86781
## treat:d.2003 1.2045e-02 4.1490e-02 0.2903 0.77160
## treat:d.2005 -4.5049e-02 4.1498e-02 -1.0856 0.27776
## treat:d.2006 3.2490e-03 4.1547e-02 0.0782 0.93767
## treat:d.2007 -1.1991e-02 4.1575e-02 -0.2884 0.77305
## treat:d.2008 -1.0489e-02 4.1622e-02 -0.2520 0.80106
## treat:d.2009 4.6391e-02 4.1585e-02 1.1156 0.26469
## treat:d.2010 6.3269e-02 4.1600e-02 1.5209 0.12840
## treat:d.2011 6.6697e-02 4.1612e-02 1.6028 0.10908
## treat:d.2012 -2.4592e-02 4.1646e-02 -0.5905 0.55490
## treat:d.2013 1.0143e-01 4.1662e-02 2.4345 0.01497 *
## treat:d.2014 5.5793e-02 4.1714e-02 1.3375 0.18116
## treat:d.2015 5.8633e-02 4.1715e-02 1.4056 0.15996
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 65.987
## Residual Sum of Squares: 17.992
## R-Squared: 0.72733
## Adj. R-Squared: 0.70597
## F-statistic: 442.649 on 18 and 2987 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