library(ggplot2)
library(lfe)
## Warning: package 'lfe' was built under R version 4.3.2
## Loading required package: Matrix
library(sf)
## Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
library(tmap)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
library(data.table)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
##
## between, first, last
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(lfe)
filesave <-paste0("E:/POI_gridmet_daily_weather_data/7cities_heat_spend_visit_climate",".RData")
load(filesave)
Q1 <- quantile(df$visit, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df$visit, 0.75, na.rm = TRUE) # 3rd Quartile
IQR <- Q3 - Q1 # Interquartile Range
# Define outlier thresholds
lower_bound <- Q1 - 1.5 * IQR
upper_bound <- Q3 + 1.5 * IQR
df <- df[df$visit >= lower_bound & df$visit <= upper_bound, ]
################Heterogeneous Effects##################
#######################################################
###Effects of chain
category <- c("Chain", "NonChain")
for (cat in category){
print(cat)
df_category <-df[df$chain==cat,]
print(paste0("N of Obeservation: ",nrow(df_category)))
FE_visit_chain <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_visit_chain))
}
## [1] "Chain"
## [1] "N of Obeservation: 1207296"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.819 -3.474 -0.352 2.869 41.400
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.7257385 0.0228117 -75.651 <2e-16 ***
## pr 0.0026508 0.0008447 3.138 0.0017 **
## rmax 0.0475911 0.0007412 64.208 <2e-16 ***
## wind -0.2270418 0.0073244 -30.998 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.41 on 1159128 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6588 Adjusted R-squared: 0.6538
## Multiple R-squared(proj model): 0.01287 Adjusted R-squared: -0.001624
## F-statistic(full model):131.5 on 17015 and 1159128 DF, p-value: < 2.2e-16
## F-statistic(proj model): 3777 on 4 and 1159128 DF, p-value: < 2.2e-16
##
##
## [1] "NonChain"
## [1] "N of Obeservation: 936742"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.233 -2.304 -0.314 1.726 40.279
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.4967135 0.0193470 -77.36 <2e-16 ***
## pr 0.0091410 0.0007266 12.58 <2e-16 ***
## rmax 0.0414489 0.0006432 64.44 <2e-16 ***
## wind -0.1632007 0.0062371 -26.17 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.755 on 890405 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6481 Adjusted R-squared: 0.6421
## Multiple R-squared(proj model): 0.0169 Adjusted R-squared: 0.0001334
## F-statistic(full model): 108 on 15184 and 890405 DF, p-value: < 2.2e-16
## F-statistic(proj model): 3826 on 4 and 890405 DF, p-value: < 2.2e-16
###Effects of cuisine types
category <- c("American & European Cuisine",
"Casual & Quick Service",
"Asian Cuisine",
"Cafes, Bakeries & Ice Cream",
"Bars & Pubs",
"Fast Food & Snacks",
"Latin & South American Cuisine",
"Healthy Options",
"Indian & Middle Eastern Cuisine")
for (cat in category){
print(cat)
df_category <-df[df$new_schemes==cat,]
print(paste0("N of Obeservation",nrow(df_category)))
FE_visit_cusine <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_visit_cusine))
}
## [1] "American & European Cuisine"
## [1] "N of Obeservation299010"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.788 -3.617 -0.313 2.995 40.031
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.890426 0.046721 -40.46 <2e-16 ***
## pr 0.003864 0.001756 2.20 0.0278 *
## rmax 0.053761 0.001524 35.28 <2e-16 ***
## wind -0.237723 0.014989 -15.86 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.287 on 263252 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6746 Adjusted R-squared: 0.6689
## Multiple R-squared(proj model): 0.0164 Adjusted R-squared: -0.0008032
## F-statistic(full model):118.5 on 4605 and 263252 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1098 on 4 and 263252 DF, p-value: < 2.2e-16
##
##
## [1] "Casual & Quick Service"
## [1] "N of Obeservation122259"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.432 -5.182 -0.306 4.846 36.698
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.590671 0.104831 -15.17 <2e-16 ***
## pr -0.004949 0.004159 -1.19 0.234
## rmax 0.045354 0.003424 13.25 <2e-16 ***
## wind -0.276502 0.033235 -8.32 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.29 on 89326 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6115 Adjusted R-squared: 0.6038
## Multiple R-squared(proj model): 0.007245 Adjusted R-squared: -0.01254
## F-statistic(full model):78.99 on 1780 and 89326 DF, p-value: < 2.2e-16
## F-statistic(proj model): 163 on 4 and 89326 DF, p-value: < 2.2e-16
##
##
## [1] "Asian Cuisine"
## [1] "N of Obeservation198716"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.550 -1.992 -0.291 1.440 38.889
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.200566 0.040552 -29.605 < 2e-16 ***
## pr 0.008272 0.001605 5.155 2.54e-07 ***
## rmax 0.038864 0.001322 29.399 < 2e-16 ***
## wind -0.159452 0.012580 -12.675 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.327 on 164675 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6559 Adjusted R-squared: 0.6499
## Multiple R-squared(proj model): 0.01642 Adjusted R-squared: -0.0008268
## F-statistic(full model):108.7 on 2888 and 164675 DF, p-value: < 2.2e-16
## F-statistic(proj model): 687.4 on 4 and 164675 DF, p-value: < 2.2e-16
##
##
## [1] "Cafes, Bakeries & Ice Cream"
## [1] "N of Obeservation275228"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.557 -2.961 -0.353 2.479 41.701
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.554258 0.045964 -33.815 <2e-16 ***
## pr 0.004017 0.001764 2.278 0.0227 *
## rmax 0.039137 0.001519 25.761 <2e-16 ***
## wind -0.187376 0.014954 -12.531 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.911 on 239886 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6475 Adjusted R-squared: 0.6414
## Multiple R-squared(proj model): 0.01118 Adjusted R-squared: -0.006084
## F-statistic(full model):105.2 on 4189 and 239886 DF, p-value: < 2.2e-16
## F-statistic(proj model): 678.3 on 4 and 239886 DF, p-value: < 2.2e-16
##
##
## [1] "Bars & Pubs"
## [1] "N of Obeservation103596"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.702 -3.421 -0.370 2.697 39.840
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.780147 0.082079 -21.688 < 2e-16 ***
## pr 0.011146 0.003376 3.302 0.000962 ***
## rmax 0.038118 0.002714 14.043 < 2e-16 ***
## wind -0.196926 0.026917 -7.316 2.58e-13 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.919 on 70864 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.648 Adjusted R-squared: 0.6402
## Multiple R-squared(proj model): 0.01391 Adjusted R-squared: -0.008066
## F-statistic(full model):82.63 on 1579 and 70864 DF, p-value: < 2.2e-16
## F-statistic(proj model): 249.8 on 4 and 70864 DF, p-value: < 2.2e-16
##
##
## [1] "Fast Food & Snacks"
## [1] "N of Obeservation211182"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.595 -2.685 -0.321 2.143 36.379
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.605482 0.049757 -32.267 < 2e-16 ***
## pr 0.006391 0.001742 3.668 0.000245 ***
## rmax 0.050786 0.001651 30.767 < 2e-16 ***
## wind -0.171330 0.016291 -10.517 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.31 on 176824 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6835 Adjusted R-squared: 0.6778
## Multiple R-squared(proj model): 0.01632 Adjusted R-squared: -0.001512
## F-statistic(full model):119.1 on 3205 and 176824 DF, p-value: < 2.2e-16
## F-statistic(proj model): 733.3 on 4 and 176824 DF, p-value: < 2.2e-16
##
##
## [1] "Latin & South American Cuisine"
## [1] "N of Obeservation183031"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.214 -2.306 -0.303 1.738 37.280
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.536147 0.045745 -33.581 < 2e-16 ***
## pr 0.011189 0.001713 6.533 6.46e-11 ***
## rmax 0.041974 0.001580 26.561 < 2e-16 ***
## wind -0.154466 0.015319 -10.083 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.619 on 148957 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.6298 Adjusted R-squared: 0.6226
## Multiple R-squared(proj model): 0.01793 Adjusted R-squared: -0.001328
## F-statistic(full model):86.77 on 2921 and 148957 DF, p-value: < 2.2e-16
## F-statistic(proj model): 679.9 on 4 and 148957 DF, p-value: < 2.2e-16
##
##
## [1] "Healthy Options"
## [1] "N of Obeservation53030"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.0471 -1.9799 -0.2481 1.5193 31.0356
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.164631 0.115425 -10.090 < 2e-16 ***
## pr 0.009083 0.003896 2.332 0.0197 *
## rmax 0.042016 0.003764 11.164 < 2e-16 ***
## wind -0.170814 0.036337 -4.701 2.61e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.072 on 21127 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.7131 Adjusted R-squared: 0.7029
## Multiple R-squared(proj model): 0.0161 Adjusted R-squared: -0.01883
## F-statistic(full model):70.02 on 750 and 21127 DF, p-value: < 2.2e-16
## F-statistic(proj model): 86.42 on 4 and 21127 DF, p-value: < 2.2e-16
##
##
## [1] "Indian & Middle Eastern Cuisine"
## [1] "N of Obeservation44620"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -19.224 -2.143 -0.313 1.536 30.035
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.283772 0.184775 -6.948 3.89e-12 ***
## pr 0.010008 0.005780 1.731 0.0834 .
## rmax 0.029940 0.005944 5.037 4.80e-07 ***
## wind -0.079196 0.062175 -1.274 0.2028
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.612 on 12899 degrees of freedom
## (31152 observations deleted due to missingness)
## Multiple R-squared(full model): 0.5717 Adjusted R-squared: 0.5529
## Multiple R-squared(proj model): 0.008218 Adjusted R-squared: -0.03546
## F-statistic(full model):30.31 on 568 and 12899 DF, p-value: < 2.2e-16
## F-statistic(proj model): 26.72 on 4 and 12899 DF, p-value: < 2.2e-16
###Effects of minority-owned
load("E:/POI_features/black_new.RData")
df<- merge(df, POIs_minority, by="PLACEKEY")
category <- unique(df$minority)
for (cat in category){
print(cat)
df_category <-df[df$minority==cat,]
print(paste0("N of Obeservation: ",nrow(df_category)))
FE_airtemp_spend_minority <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_minority))
}
## [1] "non_minority"
## [1] "N of Obeservation: 1744658"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.792 -2.917 -0.324 2.328 40.942
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.6398302 0.0169638 -96.667 < 2e-16 ***
## pr 0.0051243 0.0006278 8.163 3.28e-16 ***
## rmax 0.0447188 0.0005554 80.509 < 2e-16 ***
## wind -0.1928056 0.0054465 -35.400 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.781 on 1717909 degrees of freedom
## Multiple R-squared(full model): 0.6705 Adjusted R-squared: 0.6654
## Multiple R-squared(proj model): 0.01375 Adjusted R-squared: -0.001608
## F-statistic(full model):130.7 on 26748 and 1717909 DF, p-value: < 2.2e-16
## F-statistic(proj model): 5987 on 4 and 1717909 DF, p-value: < 2.2e-16
##
##
## [1] "hispanic"
## [1] "N of Obeservation: 129435"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.279 -2.840 -0.319 2.212 39.874
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.504340 0.060051 -25.051 < 2e-16 ***
## pr 0.007039 0.002343 3.005 0.00266 **
## rmax 0.052082 0.001971 26.430 < 2e-16 ***
## wind -0.207123 0.019445 -10.652 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.703 on 127110 degrees of freedom
## Multiple R-squared(full model): 0.681 Adjusted R-squared: 0.6752
## Multiple R-squared(proj model): 0.01591 Adjusted R-squared: -0.002087
## F-statistic(full model):116.8 on 2324 and 127110 DF, p-value: < 2.2e-16
## F-statistic(proj model): 513.6 on 4 and 127110 DF, p-value: < 2.2e-16
##
##
## [1] "black"
## [1] "N of Obeservation: 207641"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.533 -2.902 -0.333 2.305 40.261
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.590379 0.047078 -33.782 < 2e-16 ***
## pr 0.006247 0.001803 3.464 0.000532 ***
## rmax 0.044951 0.001571 28.618 < 2e-16 ***
## wind -0.249652 0.015305 -16.311 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.625 on 204145 degrees of freedom
## Multiple R-squared(full model): 0.6869 Adjusted R-squared: 0.6815
## Multiple R-squared(proj model): 0.01484 Adjusted R-squared: -0.002027
## F-statistic(full model):128.1 on 3495 and 204145 DF, p-value: < 2.2e-16
## F-statistic(proj model): 768.7 on 4 and 204145 DF, p-value: < 2.2e-16
###Effects of full service and limited service
category <- unique(df$SUB_CATEGORY)
for (cat in category){
print(cat)
df_category <-df[df$SUB_CATEGORY==cat,]
print(paste0("N of Obeservation",nrow(df_category)))
FE_airtemp_spend_chain <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_chain))
}
## [1] "Limited-Service Restaurants"
## [1] "N of Obeservation867000"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.857 -3.039 -0.348 2.442 41.301
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.5573967 0.0245385 -63.467 < 2e-16 ***
## pr 0.0046556 0.0009053 5.143 2.71e-07 ***
## rmax 0.0457123 0.0007985 57.245 < 2e-16 ***
## wind -0.2078395 0.0078587 -26.447 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.917 on 854550 degrees of freedom
## Multiple R-squared(full model): 0.6721 Adjusted R-squared: 0.6673
## Multiple R-squared(proj model): 0.01304 Adjusted R-squared: -0.001333
## F-statistic(full model):140.7 on 12449 and 854550 DF, p-value: < 2.2e-16
## F-statistic(proj model): 2824 on 4 and 854550 DF, p-value: < 2.2e-16
##
##
## [1] "Full-Service Restaurants"
## [1] "N of Obeservation913436"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.643 -2.821 -0.288 2.245 40.875
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.6912528 0.0222615 -75.972 < 2e-16 ***
## pr 0.0064041 0.0008342 7.677 1.63e-14 ***
## rmax 0.0485183 0.0007362 65.900 < 2e-16 ***
## wind -0.1930165 0.0071887 -26.850 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.506 on 898406 degrees of freedom
## Multiple R-squared(full model): 0.686 Adjusted R-squared: 0.6808
## Multiple R-squared(proj model): 0.01664 Adjusted R-squared: 0.0001887
## F-statistic(full model):130.6 on 15029 and 898406 DF, p-value: < 2.2e-16
## F-statistic(proj model): 3800 on 4 and 898406 DF, p-value: < 2.2e-16
##
##
## [1] "Snack and Nonalcoholic Beverage Bars"
## [1] "N of Obeservation297769"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.945 -2.970 -0.354 2.464 41.979
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.638255 0.041729 -39.26 < 2e-16 ***
## pr 0.004108 0.001580 2.60 0.00931 **
## rmax 0.034409 0.001369 25.14 < 2e-16 ***
## wind -0.196362 0.013445 -14.61 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.894 on 292743 degrees of freedom
## Multiple R-squared(full model): 0.6512 Adjusted R-squared: 0.6452
## Multiple R-squared(proj model): 0.01095 Adjusted R-squared: -0.006024
## F-statistic(full model):108.8 on 5025 and 292743 DF, p-value: < 2.2e-16
## F-statistic(proj model): 810.5 on 4 and 292743 DF, p-value: < 2.2e-16
##
##
## [1] ""
## [1] "N of Obeservation1485"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.664 -3.053 0.000 2.547 24.235
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.71545 0.75284 -0.950 0.34216
## pr 0.02987 0.03560 0.839 0.40174
## rmax 0.07252 0.02774 2.614 0.00908 **
## wind -0.04419 0.21065 -0.210 0.83387
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.12 on 1078 degrees of freedom
## Multiple R-squared(full model): 0.7062 Adjusted R-squared: 0.5955
## Multiple R-squared(proj model): 0.01119 Adjusted R-squared: -0.3612
## F-statistic(full model):6.381 on 406 and 1078 DF, p-value: < 2.2e-16
## F-statistic(proj model): 3.049 on 4 and 1078 DF, p-value: 0.01636
##
##
## [1] "Cafeterias, Grill Buffets, and Buffets"
## [1] "N of Obeservation2044"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.8285 -2.0289 -0.0941 1.7161 15.6391
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.98796 0.78139 -2.544 0.0110 *
## pr 0.01116 0.01386 0.805 0.4208
## rmax -0.01271 0.03747 -0.339 0.7345
## wind 0.88347 0.38990 2.266 0.0236 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.633 on 1649 degrees of freedom
## Multiple R-squared(full model): 0.6154 Adjusted R-squared: 0.5235
## Multiple R-squared(proj model): 0.007007 Adjusted R-squared: -0.2303
## F-statistic(full model):6.696 on 394 and 1649 DF, p-value: < 2.2e-16
## F-statistic(proj model): 2.909 on 4 and 1649 DF, p-value: 0.02057
###Effects of outdoor seating
file=load("E:/POI_features/combined_data_outdoor.RData")
filesave <-paste0("E:/POI_gridmet_daily_weather_data/7cities_heat_spend_visit_climate",".RData")
load(filesave)
Q1 <- quantile(df$visit, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df$visit, 0.75, na.rm = TRUE) # 3rd Quartile
IQR <- Q3 - Q1 # Interquartile Range
# Define outlier thresholds
lower_bound <- Q1 - 1.5 * IQR
upper_bound <- Q3 + 1.5 * IQR
df <- df[df$visit >= lower_bound & df$visit <= upper_bound, ]
##merge df with outdoor seating
df <- merge(df,combined_data, by="PLACEKEY")
df <- df %>% distinct(PLACEKEY, date, .keep_all = TRUE)
category <- c("with_seating", "without_seating")
for (cat in category){
print(cat)
df_category <-df[df$outdoor==cat,]
print(paste0("N of Obeservation: ",nrow(df_category)))
FE_airtemp_visit_outdoor <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_visit_outdoor))
}
## [1] "with_seating"
## [1] "N of Obeservation: 446939"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.369 -2.942 -0.324 2.347 40.997
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.694636 0.032881 -51.539 < 2e-16 ***
## pr 0.003570 0.001254 2.847 0.00442 **
## rmax 0.044116 0.001081 40.816 < 2e-16 ***
## wind -0.208475 0.010608 -19.653 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.717 on 439813 degrees of freedom
## Multiple R-squared(full model): 0.6802 Adjusted R-squared: 0.675
## Multiple R-squared(proj model): 0.01455 Adjusted R-squared: -0.001417
## F-statistic(full model):131.3 on 7125 and 439813 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1623 on 4 and 439813 DF, p-value: < 2.2e-16
##
##
## [1] "without_seating"
## [1] "N of Obeservation: 1634795"
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.800 -2.902 -0.326 2.310 40.766
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.6067369 0.0174657 -91.994 <2e-16 ***
## pr 0.0058224 0.0006467 9.004 <2e-16 ***
## rmax 0.0455154 0.0005727 79.471 <2e-16 ***
## wind -0.1966162 0.0056129 -35.030 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.773 on 1609720 degrees of freedom
## Multiple R-squared(full model): 0.6707 Adjusted R-squared: 0.6656
## Multiple R-squared(proj model): 0.01381 Adjusted R-squared: -0.001548
## F-statistic(full model):130.8 on 25074 and 1609720 DF, p-value: < 2.2e-16
## F-statistic(proj model): 5637 on 4 and 1609720 DF, p-value: < 2.2e-16
###holdays or not
# Create a sample dataframe with a date column
holidays <-fread("E:/POI_gridmet_daily_weather_data/us_holidays_2019_2022_2023.csv")
holidays<- holidays[,c(1,4)]
df<- merge(df, holidays, by="date", all.x=TRUE)
df$Holiday_new[is.na(df$Holiday_new)] <- 0
##run the regression for day_of_week
category <- unique(df$day_of_week)
for (cat in category){
print(cat)
df_category <-df[df$day_of_week==cat,]
print(nrow(df_category))
FE_airtemp_spend_dow <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_dow))
}
## [1] "Wednesday"
## [1] 305655
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.661 -2.606 -0.174 2.140 39.290
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.695574 0.040784 -41.575 < 2e-16 ***
## pr -0.007388 0.001550 -4.767 1.87e-06 ***
## rmax 0.033806 0.001257 26.887 < 2e-16 ***
## wind -0.347544 0.012437 -27.945 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.517 on 274572 degrees of freedom
## Multiple R-squared(full model): 0.7216 Adjusted R-squared: 0.6901
## Multiple R-squared(proj model): 0.01651 Adjusted R-squared: -0.09483
## F-statistic(full model): 22.9 on 31082 and 274572 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1152 on 4 and 274572 DF, p-value: < 2.2e-16
##
##
## [1] "Thursday"
## [1] 300075
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.771 -2.687 -0.213 2.199 39.284
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.472013 0.042111 -34.956 <2e-16 ***
## pr -0.014115 0.001602 -8.809 <2e-16 ***
## rmax 0.036672 0.001339 27.384 <2e-16 ***
## wind -0.168984 0.013502 -12.516 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.652 on 269030 degrees of freedom
## Multiple R-squared(full model): 0.7145 Adjusted R-squared: 0.6816
## Multiple R-squared(proj model): 0.01077 Adjusted R-squared: -0.1034
## F-statistic(full model):21.69 on 31044 and 269030 DF, p-value: < 2.2e-16
## F-statistic(proj model): 732.5 on 4 and 269030 DF, p-value: < 2.2e-16
##
##
## [1] "Friday"
## [1] 285713
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.538 -2.850 -0.310 2.422 40.061
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.790209 0.043273 -41.370 < 2e-16 ***
## pr 0.013565 0.001846 7.348 2.01e-13 ***
## rmax 0.028643 0.001456 19.678 < 2e-16 ***
## wind -0.158150 0.014649 -10.796 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.889 on 255063 degrees of freedom
## Multiple R-squared(full model): 0.7101 Adjusted R-squared: 0.6753
## Multiple R-squared(proj model): 0.01072 Adjusted R-squared: -0.1082
## F-statistic(full model):20.39 on 30649 and 255063 DF, p-value: < 2.2e-16
## F-statistic(proj model): 690.9 on 4 and 255063 DF, p-value: < 2.2e-16
##
##
## [1] "Saturday"
## [1] 286845
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.187 -2.728 -0.280 2.369 40.945
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.800719 0.042958 -41.918 < 2e-16 ***
## pr 0.001147 0.001635 0.701 0.483
## rmax 0.037574 0.001486 25.287 < 2e-16 ***
## wind 0.119561 0.014625 8.175 2.97e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.814 on 256243 degrees of freedom
## Multiple R-squared(full model): 0.7134 Adjusted R-squared: 0.6792
## Multiple R-squared(proj model): 0.01296 Adjusted R-squared: -0.1049
## F-statistic(full model):20.85 on 30601 and 256243 DF, p-value: < 2.2e-16
## F-statistic(proj model): 841.3 on 4 and 256243 DF, p-value: < 2.2e-16
##
##
## [1] "Sunday"
## [1] 295406
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.367 -2.512 -0.249 2.069 39.027
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.786281 0.039258 -45.501 <2e-16 ***
## pr 0.007642 0.001299 5.884 4e-09 ***
## rmax 0.057295 0.001298 44.131 <2e-16 ***
## wind -0.015045 0.013133 -1.146 0.252
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.508 on 264419 degrees of freedom
## Multiple R-squared(full model): 0.7209 Adjusted R-squared: 0.6882
## Multiple R-squared(proj model): 0.02377 Adjusted R-squared: -0.09063
## F-statistic(full model):22.04 on 30986 and 264419 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1610 on 4 and 264419 DF, p-value: < 2.2e-16
##
##
## [1] "Monday"
## [1] 303785
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.645 -2.477 -0.208 2.006 37.742
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.606605 0.041079 -39.11 <2e-16 ***
## pr 0.036573 0.001607 22.76 <2e-16 ***
## rmax 0.047921 0.001264 37.92 <2e-16 ***
## wind -0.411892 0.012639 -32.59 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.494 on 272568 degrees of freedom
## Multiple R-squared(full model): 0.7119 Adjusted R-squared: 0.679
## Multiple R-squared(proj model): 0.02471 Adjusted R-squared: -0.08698
## F-statistic(full model):21.58 on 31216 and 272568 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1727 on 4 and 272568 DF, p-value: < 2.2e-16
##
##
## [1] "Tuesday"
## [1] 304255
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.656 -2.638 -0.190 2.147 40.375
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.2470379 0.0403874 -30.877 <2e-16 ***
## pr 0.0005712 0.0014882 0.384 0.701
## rmax 0.0564168 0.0013562 41.599 <2e-16 ***
## wind -0.3992110 0.0134720 -29.633 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.525 on 273105 degrees of freedom
## Multiple R-squared(full model): 0.7171 Adjusted R-squared: 0.6848
## Multiple R-squared(proj model): 0.02094 Adjusted R-squared: -0.09072
## F-statistic(full model):22.23 on 31149 and 273105 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1460 on 4 and 273105 DF, p-value: < 2.2e-16
##run the regression for holidays
category <- unique(df$Holiday_new)
for (cat in category){
print(cat)
df_category <-df[df$Holiday_new==cat,]
print(nrow(df_category))
FE_airtemp_spend_holiday <- felm(visit ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_holiday))
}
## [1] 0
## [1] 2047299
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -33.182 -2.911 -0.327 2.322 40.836
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.6220949 0.0154718 -104.842 <2e-16 ***
## pr 0.0051058 0.0005757 8.869 <2e-16 ***
## rmax 0.0452110 0.0005081 88.973 <2e-16 ***
## wind -0.1886260 0.0050104 -37.647 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.758 on 2015483 degrees of freedom
## Multiple R-squared(full model): 0.6735 Adjusted R-squared: 0.6684
## Multiple R-squared(proj model): 0.01395 Adjusted R-squared: -0.001612
## F-statistic(full model):130.7 on 31815 and 2015483 DF, p-value: < 2.2e-16
## F-statistic(proj model): 7130 on 4 and 2015483 DF, p-value: < 2.2e-16
##
##
## [1] 1
## [1] 34435
##
## Call:
## felm(formula = visit ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26.516 -1.873 0.000 1.635 26.102
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -2.726436 0.322942 -8.442 <2e-16 ***
## pr 0.025240 0.012826 1.968 0.0491 *
## rmax 0.063524 0.006716 9.459 <2e-16 ***
## wind -0.693496 0.042251 -16.414 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.06 on 19225 degrees of freedom
## Multiple R-squared(full model): 0.7801 Adjusted R-squared: 0.6061
## Multiple R-squared(proj model): 0.03026 Adjusted R-squared: -0.7369
## F-statistic(full model):4.483 on 15209 and 19225 DF, p-value: < 2.2e-16
## F-statistic(proj model): 150 on 4 and 19225 DF, p-value: < 2.2e-16