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$spend_pertransaction, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df$spend_pertransaction, 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$spend_pertransaction >= lower_bound & df$spend_pertransaction <= upper_bound, ]
################Spend Heterogeneous Effects##################
#############################################################
###Effects of chain
category <- unique(df$chain)
for (cat in category){
print(cat)
df_category <-df[df$chain==cat,]
print(paste0("N of Obeservation",nrow(df_category)))
FE_airtemp_spend_chain <- felm(spend_pertransaction ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_chain))
}
## [1] "Chain"
## [1] "N of Obeservation1278924"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.659 -4.460 -0.942 3.516 46.461
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.2062049 0.0284427 -42.408 < 2e-16 ***
## pr 0.0040679 0.0010443 3.895 9.81e-05 ***
## rmax 0.0555769 0.0009235 60.183 < 2e-16 ***
## wind 0.0279591 0.0091024 3.072 0.00213 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.305 on 1261212 degrees of freedom
## Multiple R-squared(full model): 0.3536 Adjusted R-squared: 0.3445
## Multiple R-squared(proj model): 0.006048 Adjusted R-squared: -0.00791
## F-statistic(full model):38.95 on 17711 and 1261212 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1919 on 4 and 1261212 DF, p-value: < 2.2e-16
##
##
## [1] "NonChain"
## [1] "N of Obeservation897640"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.762 -6.040 -2.070 3.142 48.236
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.752524 0.041681 -18.054 <2e-16 ***
## pr 0.004030 0.001556 2.590 0.0096 **
## rmax 0.051740 0.001393 37.135 <2e-16 ***
## wind 0.029448 0.013382 2.201 0.0278 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.19 on 881641 degrees of freedom
## Multiple R-squared(full model): 0.2865 Adjusted R-squared: 0.2736
## Multiple R-squared(proj model): 0.002624 Adjusted R-squared: -0.01547
## F-statistic(full model):22.13 on 15998 and 881641 DF, p-value: < 2.2e-16
## F-statistic(proj model): 580 on 4 and 881641 DF, p-value: < 2.2e-16
###Effects of cuisine types
category <- unique(df$new_schemes)
for (cat in category){
print(cat)
df_category <-df[df$new_schemes==cat,]
print(paste0("N of Obeservation",nrow(df_category)))
FE_airtemp_spend_cusine <- felm(spend_pertransaction ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_cusine))
}
## [1] "Others"
## [1] "N of Obeservation942867"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.080 -4.598 -1.062 3.338 46.444
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.147727 0.032135 -35.716 < 2e-16 ***
## pr 0.005417 0.001174 4.615 3.93e-06 ***
## rmax 0.053261 0.001049 50.797 < 2e-16 ***
## wind 0.008244 0.010310 0.800 0.424
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.043 on 929554 degrees of freedom
## Multiple R-squared(full model): 0.3138 Adjusted R-squared: 0.3039
## Multiple R-squared(proj model): 0.005874 Adjusted R-squared: -0.008363
## F-statistic(full model):31.93 on 13312 and 929554 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1373 on 4 and 929554 DF, p-value: < 2.2e-16
##
##
## [1] "American & European Cuisine"
## [1] "N of Obeservation256460"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -38.928 -7.588 -1.720 6.383 48.585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.825982 0.090059 -9.172 < 2e-16 ***
## pr -0.001447 0.003311 -0.437 0.66221
## rmax 0.073200 0.002943 24.869 < 2e-16 ***
## wind 0.078847 0.028598 2.757 0.00583 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.78 on 251619 degrees of freedom
## Multiple R-squared(full model): 0.3961 Adjusted R-squared: 0.3845
## Multiple R-squared(proj model): 0.003634 Adjusted R-squared: -0.01553
## F-statistic(full model): 34.1 on 4840 and 251619 DF, p-value: < 2.2e-16
## F-statistic(proj model): 229.4 on 4 and 251619 DF, p-value: < 2.2e-16
##
##
## [1] "Casual & Quick Service"
## [1] "N of Obeservation108125"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.853 -3.061 -0.756 1.936 44.384
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.306398 0.092999 -14.048 <2e-16 ***
## pr 0.005548 0.003437 1.614 0.107
## rmax 0.051278 0.002976 17.229 <2e-16 ***
## wind 0.032580 0.028976 1.124 0.261
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.829 on 106313 degrees of freedom
## Multiple R-squared(full model): 0.3374 Adjusted R-squared: 0.3261
## Multiple R-squared(proj model): 0.006662 Adjusted R-squared: -0.01026
## F-statistic(full model):29.89 on 1811 and 106313 DF, p-value: < 2.2e-16
## F-statistic(proj model): 178.2 on 4 and 106313 DF, p-value: < 2.2e-16
##
##
## [1] "Asian Cuisine"
## [1] "N of Obeservation154925"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.400 -7.818 -2.699 5.501 49.363
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.682082 0.115391 -5.911 3.41e-09 ***
## pr 0.004600 0.004485 1.026 0.305
## rmax 0.062476 0.003774 16.556 < 2e-16 ***
## wind 0.153190 0.035784 4.281 1.86e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.79 on 151956 degrees of freedom
## Multiple R-squared(full model): 0.2667 Adjusted R-squared: 0.2524
## Multiple R-squared(proj model): 0.002765 Adjusted R-squared: -0.01671
## F-statistic(full model):18.62 on 2968 and 151956 DF, p-value: < 2.2e-16
## F-statistic(proj model): 105.3 on 4 and 151956 DF, p-value: < 2.2e-16
##
##
## [1] "Cafes, Bakeries & Ice Cream"
## [1] "N of Obeservation269651"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.005 -3.725 -1.169 2.221 45.194
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.013050 0.048054 -21.081 <2e-16 ***
## pr 0.003754 0.001838 2.042 0.0411 *
## rmax 0.044361 0.001587 27.960 <2e-16 ***
## wind -0.036980 0.015488 -2.388 0.0170 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.486 on 265247 degrees of freedom
## Multiple R-squared(full model): 0.2442 Adjusted R-squared: 0.2316
## Multiple R-squared(proj model): 0.00655 Adjusted R-squared: -0.009941
## F-statistic(full model):19.46 on 4403 and 265247 DF, p-value: < 2.2e-16
## F-statistic(proj model): 437.2 on 4 and 265247 DF, p-value: < 2.2e-16
##
##
## [1] "Bars & Pubs"
## [1] "N of Obeservation69166"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.835 -7.082 -2.016 4.327 48.131
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.754180 0.158510 -4.758 1.96e-06 ***
## pr -0.004618 0.006298 -0.733 0.463
## rmax 0.048458 0.005260 9.213 < 2e-16 ***
## wind 0.048316 0.051786 0.933 0.351
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.12 on 67523 degrees of freedom
## Multiple R-squared(full model): 0.3334 Adjusted R-squared: 0.3172
## Multiple R-squared(proj model): 0.002122 Adjusted R-squared: -0.02214
## F-statistic(full model):20.57 on 1642 and 67523 DF, p-value: < 2.2e-16
## F-statistic(proj model): 35.9 on 4 and 67523 DF, p-value: < 2.2e-16
##
##
## [1] "Fast Food & Snacks"
## [1] "N of Obeservation192093"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.523 -5.978 -1.842 3.993 45.943
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.058526 0.087615 -12.082 <2e-16 ***
## pr 0.003671 0.003119 1.177 0.239
## rmax 0.050457 0.002912 17.326 <2e-16 ***
## wind 0.044171 0.028358 1.558 0.119
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.747 on 188721 degrees of freedom
## Multiple R-squared(full model): 0.293 Adjusted R-squared: 0.2804
## Multiple R-squared(proj model): 0.003264 Adjusted R-squared: -0.01454
## F-statistic(full model):23.21 on 3371 and 188721 DF, p-value: < 2.2e-16
## F-statistic(proj model): 154.5 on 4 and 188721 DF, p-value: < 2.2e-16
##
##
## [1] "Latin & South American Cuisine"
## [1] "N of Obeservation148681"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -34.233 -5.572 -2.102 2.341 45.439
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.831295 0.096761 -8.591 <2e-16 ***
## pr 0.007664 0.003596 2.131 0.0331 *
## rmax 0.043044 0.003358 12.818 <2e-16 ***
## wind 0.064034 0.032330 1.981 0.0476 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.64 on 145722 degrees of freedom
## Multiple R-squared(full model): 0.2788 Adjusted R-squared: 0.2642
## Multiple R-squared(proj model): 0.002314 Adjusted R-squared: -0.01794
## F-statistic(full model):19.05 on 2958 and 145722 DF, p-value: < 2.2e-16
## F-statistic(proj model): 84.51 on 4 and 145722 DF, p-value: < 2.2e-16
##
##
## [1] "Healthy Options"
## [1] "N of Obeservation22359"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -27.823 -5.913 -2.196 1.966 45.896
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -8.114e-01 2.782e-01 -2.917 0.00354 **
## pr -1.605e-05 9.711e-03 -0.002 0.99868
## rmax 3.832e-02 9.145e-03 4.190 2.8e-05 ***
## wind -1.088e-01 8.521e-02 -1.276 0.20182
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.18 on 21580 degrees of freedom
## Multiple R-squared(full model): 0.2489 Adjusted R-squared: 0.2219
## Multiple R-squared(proj model): 0.001724 Adjusted R-squared: -0.03427
## F-statistic(full model):9.194 on 778 and 21580 DF, p-value: < 2.2e-16
## F-statistic(proj model): 9.316 on 4 and 21580 DF, p-value: 1.612e-07
##
##
## [1] "Indian & Middle Eastern Cuisine"
## [1] "N of Obeservation12237"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.721 -7.142 -2.250 3.947 44.025
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.150784 0.467555 -2.461 0.0139 *
## pr -0.001243 0.014676 -0.085 0.9325
## rmax -0.013752 0.015192 -0.905 0.3654
## wind 0.172843 0.157552 1.097 0.2726
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.06 on 11666 degrees of freedom
## Multiple R-squared(full model): 0.2521 Adjusted R-squared: 0.2156
## Multiple R-squared(proj model): 0.0006634 Adjusted R-squared: -0.04816
## F-statistic(full model):6.899 on 570 and 11666 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1.936 on 4 and 11666 DF, p-value: 0.1015
FE_airtemp_spend_size <- felm(spend_pertransaction ~ extreme_heat_100F+extreme_heat_100F*size + pr+rmax + wind|
place_month + date|0,
data = df)
## Warning in chol.default(mat, pivot = TRUE, tol = tol): the matrix is either
## rank-deficient or not positive definite
summary(FE_airtemp_spend_size)
## Warning in chol.default(mat, pivot = TRUE, tol = tol): the matrix is either
## rank-deficient or not positive definite
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + extreme_heat_100F * size + pr + rmax + wind | place_month + date | 0, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.667 -5.184 -1.452 3.469 48.707
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.9844225 0.1009439 -9.752 < 2e-16 ***
## size NaN NA NaN NaN
## pr 0.0039649 0.0008876 4.467 7.93e-06 ***
## rmax 0.0539948 0.0007887 68.459 < 2e-16 ***
## wind 0.0276747 0.0076940 3.597 0.000322 ***
## extreme_heat_100F:size -0.0047352 0.0164003 -0.289 0.772792
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.149 on 2143221 degrees of freedom
## Multiple R-squared(full model): 0.3319 Adjusted R-squared: 0.3215
## Multiple R-squared(proj model): 0.004195 Adjusted R-squared: -0.0113
## F-statistic(full model):31.93 on 33342 and 2143221 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1505 on 6 and 2143221 DF, p-value: < 2.2e-16
###Effects of minority-owned
load("E:/POI_features/black_new.RData")
df1<- merge(df, POIs_minority, by="PLACEKEY")
category <- unique(df1$minority)
for (cat in category){
print(cat)
df_category <-df1[df1$minority==cat,]
print(paste0("N of Obeservation: ",nrow(df_category)))
FE_airtemp_spend_minority <- felm(spend_pertransaction ~ 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: 1823273"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.678 -5.195 -1.458 3.470 47.502
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.9834901 0.0263068 -37.385 < 2e-16 ***
## pr 0.0034086 0.0009666 3.526 0.000421 ***
## rmax 0.0542108 0.0008625 62.855 < 2e-16 ***
## wind 0.0170433 0.0084129 2.026 0.042781 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.146 on 1795285 degrees of freedom
## Multiple R-squared(full model): 0.3309 Adjusted R-squared: 0.3205
## Multiple R-squared(proj model): 0.004128 Adjusted R-squared: -0.0114
## F-statistic(full model):31.72 on 27987 and 1795285 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1860 on 4 and 1795285 DF, p-value: < 2.2e-16
##
##
## [1] "hispanic"
## [1] "N of Obeservation: 134285"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.155 -5.083 -1.336 3.501 46.309
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.163710 0.094803 -12.275 <2e-16 ***
## pr 0.003437 0.003642 0.944 0.3454
## rmax 0.055680 0.003118 17.856 <2e-16 ***
## wind 0.066128 0.030595 2.161 0.0307 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.138 on 131852 degrees of freedom
## Multiple R-squared(full model): 0.3493 Adjusted R-squared: 0.3373
## Multiple R-squared(proj model): 0.005013 Adjusted R-squared: -0.01334
## F-statistic(full model): 29.1 on 2432 and 131852 DF, p-value: < 2.2e-16
## F-statistic(proj model): 166.1 on 4 and 131852 DF, p-value: < 2.2e-16
##
##
## [1] "black"
## [1] "N of Obeservation: 219006"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.458 -5.161 -1.470 3.458 48.532
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.156392 0.075068 -15.405 < 2e-16 ***
## pr 0.009155 0.002849 3.213 0.001313 **
## rmax 0.051371 0.002502 20.532 < 2e-16 ***
## wind 0.088668 0.024337 3.643 0.000269 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.186 on 215347 degrees of freedom
## Multiple R-squared(full model): 0.3317 Adjusted R-squared: 0.3204
## Multiple R-squared(proj model): 0.00439 Adjusted R-squared: -0.01252
## F-statistic(full model):29.22 on 3658 and 215347 DF, p-value: < 2.2e-16
## F-statistic(proj model): 237.4 on 4 and 215347 DF, p-value: < 2.2e-16
###Effects of full service and limited service
file=load("E:/POI_features/6cities_POIs_HOLC_Chain.RData")
df2<- merge(df, POIs, by="PLACEKEY")
category <- c("Limited-Service Restaurants", "Full-Service Restaurants")
for (cat in category){
print(cat)
df_category <-df2[df2$SUB_CATEGORY==cat,]
print(paste0("N of Obeservation: ",nrow(df_category)))
FE_airtemp_spend_chain <- felm(spend_pertransaction ~ 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 Obeservation: 950272"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.219 -4.437 -0.999 3.296 46.346
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.185056 0.031665 -37.425 < 2e-16 ***
## pr 0.004420 0.001161 3.806 0.000142 ***
## rmax 0.054829 0.001029 53.270 < 2e-16 ***
## wind 0.016639 0.010108 1.646 0.099727 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.979 on 937404 degrees of freedom
## Multiple R-squared(full model): 0.3024 Adjusted R-squared: 0.2928
## Multiple R-squared(proj model): 0.006376 Adjusted R-squared: -0.007263
## F-statistic(full model):31.58 on 12867 and 937404 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1504 on 4 and 937404 DF, p-value: < 2.2e-16
##
##
## [1] "Full-Service Restaurants"
## [1] "N of Obeservation: 888719"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -38.183 -6.761 -2.076 4.610 49.067
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.817416 0.045143 -18.107 < 2e-16 ***
## pr 0.003045 0.001670 1.824 0.0682 .
## rmax 0.056667 0.001499 37.801 < 2e-16 ***
## wind 0.058024 0.014499 4.002 6.29e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.97 on 873038 degrees of freedom
## Multiple R-squared(full model): 0.3461 Adjusted R-squared: 0.3344
## Multiple R-squared(proj model): 0.00271 Adjusted R-squared: -0.0152
## F-statistic(full model):29.47 on 15680 and 873038 DF, p-value: < 2.2e-16
## F-statistic(proj model): 593.2 on 4 and 873038 DF, p-value: < 2.2e-16
###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$spend_pertransaction, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df$spend_pertransaction, 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$spend_pertransaction >= lower_bound & df$spend_pertransaction <= 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_spend_outdoor <- felm(spend_pertransaction ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_outdoor))
}
## [1] "with_seating"
## [1] "N of Obeservation: 491945"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.428 -5.073 -1.399 3.411 48.537
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.082988 0.049958 -21.678 < 2e-16 ***
## pr 0.004325 0.001835 2.357 0.01845 *
## rmax 0.053326 0.001640 32.510 < 2e-16 ***
## wind 0.045367 0.016006 2.834 0.00459 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.021 on 484123 degrees of freedom
## Multiple R-squared(full model): 0.3403 Adjusted R-squared: 0.3296
## Multiple R-squared(proj model): 0.004407 Adjusted R-squared: -0.01168
## F-statistic(full model):31.93 on 7821 and 484123 DF, p-value: < 2.2e-16
## F-statistic(proj model): 535.7 on 4 and 484123 DF, p-value: < 2.2e-16
##
##
## [1] "without_seating"
## [1] "N of Obeservation: 1684619"
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.877 -5.218 -1.466 3.486 47.554
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.9920793 0.0273789 -36.235 < 2e-16 ***
## pr 0.0038754 0.0010139 3.822 0.000132 ***
## rmax 0.0541816 0.0008994 60.241 < 2e-16 ***
## wind 0.0223907 0.0087733 2.552 0.010706 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.186 on 1658730 degrees of freedom
## Multiple R-squared(full model): 0.3297 Adjusted R-squared: 0.3192
## Multiple R-squared(proj model): 0.004138 Adjusted R-squared: -0.0114
## F-statistic(full model):31.51 on 25888 and 1658730 DF, p-value: < 2.2e-16
## F-statistic(proj model): 1723 on 4 and 1658730 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_chain <- felm(spend_pertransaction ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_chain))
}
## [1] "Wednesday"
## [1] 320651
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -36.693 -4.219 -0.702 2.851 44.062
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.199985 0.062955 -19.061 <2e-16 ***
## pr -0.001514 0.002370 -0.639 0.523
## rmax 0.044064 0.001941 22.705 <2e-16 ***
## wind -0.034495 0.019108 -1.805 0.071 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.687 on 287645 degrees of freedom
## Multiple R-squared(full model): 0.409 Adjusted R-squared: 0.3412
## Multiple R-squared(proj model): 0.004351 Adjusted R-squared: -0.1099
## F-statistic(full model):6.032 on 33005 and 287645 DF, p-value: < 2.2e-16
## F-statistic(proj model): 314.3 on 4 and 287645 DF, p-value: < 2.2e-16
##
##
## [1] "Thursday"
## [1] 315448
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.878 -4.297 -0.721 2.999 42.761
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.364530 0.064103 -21.286 <2e-16 ***
## pr -0.006020 0.002413 -2.495 0.0126 *
## rmax 0.040703 0.002045 19.904 <2e-16 ***
## wind -0.027939 0.020504 -1.363 0.1730
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.802 on 282455 degrees of freedom
## Multiple R-squared(full model): 0.4038 Adjusted R-squared: 0.3341
## Multiple R-squared(proj model): 0.003957 Adjusted R-squared: -0.1124
## F-statistic(full model):5.798 on 32992 and 282455 DF, p-value: < 2.2e-16
## F-statistic(proj model): 280.6 on 4 and 282455 DF, p-value: < 2.2e-16
##
##
## [1] "Friday"
## [1] 304993
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.688 -4.279 -0.653 3.087 41.977
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.137380 0.063263 -17.979 < 2e-16 ***
## pr 0.007827 0.002651 2.952 0.00316 **
## rmax 0.037271 0.002119 17.591 < 2e-16 ***
## wind -0.062977 0.021249 -2.964 0.00304 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.838 on 272023 degrees of freedom
## Multiple R-squared(full model): 0.4242 Adjusted R-squared: 0.3544
## Multiple R-squared(proj model): 0.003081 Adjusted R-squared: -0.1177
## F-statistic(full model):6.079 on 32969 and 272023 DF, p-value: < 2.2e-16
## F-statistic(proj model): 210.2 on 4 and 272023 DF, p-value: < 2.2e-16
##
##
## [1] "Saturday"
## [1] 307035
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.164 -4.615 -0.908 2.020 43.286
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.923695 0.065400 -14.124 < 2e-16 ***
## pr 0.015040 0.002448 6.144 8.06e-10 ***
## rmax 0.075785 0.002259 33.544 < 2e-16 ***
## wind 0.029929 0.022146 1.351 0.177
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.119 on 274060 degrees of freedom
## Multiple R-squared(full model): 0.3493 Adjusted R-squared: 0.271
## Multiple R-squared(proj model): 0.006631 Adjusted R-squared: -0.1129
## F-statistic(full model):4.461 on 32974 and 274060 DF, p-value: < 2.2e-16
## F-statistic(proj model): 457.3 on 4 and 274060 DF, p-value: < 2.2e-16
##
##
## [1] "Sunday"
## [1] 307580
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -38.418 -4.560 -0.876 1.885 44.365
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.203893 0.064072 -18.790 < 2e-16 ***
## pr 0.005248 0.002102 2.496 0.01256 *
## rmax 0.081216 0.002121 38.289 < 2e-16 ***
## wind 0.058746 0.021368 2.749 0.00597 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.135 on 274623 degrees of freedom
## Multiple R-squared(full model): 0.3571 Adjusted R-squared: 0.28
## Multiple R-squared(proj model): 0.01009 Adjusted R-squared: -0.1087
## F-statistic(full model):4.629 on 32956 and 274623 DF, p-value: < 2.2e-16
## F-statistic(proj model): 700.1 on 4 and 274623 DF, p-value: < 2.2e-16
##
##
## [1] "Monday"
## [1] 307144
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.230 -4.112 -0.697 3.413 44.994
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.641555 0.064690 -9.917 < 2e-16 ***
## pr 0.010244 0.002548 4.020 5.83e-05 ***
## rmax 0.058740 0.001995 29.438 < 2e-16 ***
## wind -0.172431 0.019849 -8.687 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.666 on 274287 degrees of freedom
## Multiple R-squared(full model): 0.5002 Adjusted R-squared: 0.4403
## Multiple R-squared(proj model): 0.005743 Adjusted R-squared: -0.1134
## F-statistic(full model):8.355 on 32856 and 274287 DF, p-value: < 2.2e-16
## F-statistic(proj model): 396.1 on 4 and 274287 DF, p-value: < 2.2e-16
##
##
## [1] "Tuesday"
## [1] 313713
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.165 -4.461 -0.774 3.167 42.149
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -0.988623 0.064117 -15.419 <2e-16 ***
## pr 0.003151 0.002357 1.337 0.181
## rmax 0.039052 0.002158 18.095 <2e-16 ***
## wind -0.014267 0.021376 -0.667 0.505
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.892 on 280745 degrees of freedom
## Multiple R-squared(full model): 0.4285 Adjusted R-squared: 0.3614
## Multiple R-squared(proj model): 0.003168 Adjusted R-squared: -0.1139
## F-statistic(full model):6.386 on 32967 and 280745 DF, p-value: < 2.2e-16
## F-statistic(proj model): 223.1 on 4 and 280745 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_chain <- felm(spend_pertransaction ~ extreme_heat_100F+ pr+rmax + wind|
place_month + date|0,
data = df_category)
print(summary(FE_airtemp_spend_chain))
}
## [1] 0
## [1] 2140413
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -37.797 -5.167 -1.432 3.472 48.730
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.0290882 0.0240856 -42.726 < 2e-16 ***
## pr 0.0036783 0.0008892 4.137 3.52e-05 ***
## rmax 0.0538800 0.0007920 68.030 < 2e-16 ***
## wind 0.0373546 0.0077684 4.809 1.52e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.143 on 2107077 degrees of freedom
## Multiple R-squared(full model): 0.3337 Adjusted R-squared: 0.3231
## Multiple R-squared(proj model): 0.004261 Adjusted R-squared: -0.01149
## F-statistic(full model):31.66 on 33335 and 2107077 DF, p-value: < 2.2e-16
## F-statistic(proj model): 2254 on 4 and 2107077 DF, p-value: < 2.2e-16
##
##
## [1] 1
## [1] 36151
##
## Call:
## felm(formula = spend_pertransaction ~ extreme_heat_100F + pr + rmax + wind | place_month + date | 0, data = df_category)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.075 -1.726 0.000 1.212 32.008
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## extreme_heat_100F -1.581012 0.467137 -3.384 0.000715 ***
## pr -0.042652 0.018407 -2.317 0.020507 *
## rmax 0.098894 0.009844 10.046 < 2e-16 ***
## wind -0.028856 0.062856 -0.459 0.646177
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.042 on 19906 degrees of freedom
## Multiple R-squared(full model): 0.5734 Adjusted R-squared: 0.2252
## Multiple R-squared(proj model): 0.00664 Adjusted R-squared: -0.804
## F-statistic(full model):1.647 on 16244 and 19906 DF, p-value: < 2.2e-16
## F-statistic(proj model): 33.26 on 4 and 19906 DF, p-value: < 2.2e-16