library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
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)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:lubridate':
## 
##     hour, isoweek, mday, minute, month, quarter, second, wday, week,
##     yday, year
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(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0     ✔ stringr 1.5.0
## ✔ purrr   1.0.1     ✔ tibble  3.2.1
## ✔ readr   2.1.4     ✔ tidyr   1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between()      masks data.table::between()
## ✖ tidyr::expand()       masks Matrix::expand()
## ✖ dplyr::filter()       masks stats::filter()
## ✖ dplyr::first()        masks data.table::first()
## ✖ data.table::hour()    masks lubridate::hour()
## ✖ data.table::isoweek() masks lubridate::isoweek()
## ✖ dplyr::lag()          masks stats::lag()
## ✖ dplyr::last()         masks data.table::last()
## ✖ data.table::mday()    masks lubridate::mday()
## ✖ data.table::minute()  masks lubridate::minute()
## ✖ data.table::month()   masks lubridate::month()
## ✖ tidyr::pack()         masks Matrix::pack()
## ✖ data.table::quarter() masks lubridate::quarter()
## ✖ data.table::second()  masks lubridate::second()
## ✖ purrr::transpose()    masks data.table::transpose()
## ✖ tidyr::unpack()       masks Matrix::unpack()
## ✖ data.table::wday()    masks lubridate::wday()
## ✖ data.table::week()    masks lubridate::week()
## ✖ data.table::yday()    masks lubridate::yday()
## ✖ data.table::year()    masks lubridate::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(zoo)
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(lfe)
library(slider)
## Warning: package 'slider' was built under R version 4.3.2
#Read all POIs
load("E:/POI_gridmet_daily_weather_data/all_POI.RData")
load("E:/nine_city_POIs_address.RData")

combined_data <- st_drop_geometry(combined_data)
POIs <-merge(combined_data_cityarea, combined_data, by="PLACEKEY", all.x = FALSE)
POIs <-POIs[!duplicated(POIs$PLACEKEY), ]
POIs <-POIs[,c(1,6,8,9,10,12,14,16)]
POIs <-st_drop_geometry(POIs)

POIs$new_tags <- sub(",.*", "", POIs$CATEGORY_TAGS)

newscheme <-fread("E:/final_categorized_restaurant_types.csv")

POIs <- merge(POIs,newscheme, by="new_tags", all.x = TRUE)
POIs$new_schemes[is.na(POIs$new_schemes)] <- "Others"
POIs$new_tags <- NULL
POIs$CATEGORY_TAGS <- NULL

POIs <-POIs[,c(1,5)]


###########################################
################Filter out outliers #######
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, ]


#####Baseline regressions with different extreme heat definitions#####
######################################################################

FE_heat_spend_100F_3day <- felm(spend_pertransaction ~ extreme_heat_100F + pr+rmax + wind| 
                              place_month + date|0, 
                              data = df)
summary(FE_heat_spend_100F_3day)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.668  -5.184  -1.452   3.469  48.708 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F -1.0127311  0.0240111 -42.178  < 2e-16 ***
## pr                 0.0039657  0.0008876   4.468  7.9e-06 ***
## rmax               0.0539934  0.0007887  68.459  < 2e-16 ***
## wind               0.0276691  0.0076939   3.596 0.000323 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.149 on 2143222 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.94 on 33341 and 2143222 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  2257 on 4 and 2143222 DF, p-value: < 2.2e-16
FE_heat_spend_100F_2day <- felm(spend_pertransaction ~ extreme_heat_100F_2day + pr+rmax + wind| 
                             place_month + date|0, 
                           data = df)
summary(FE_heat_spend_100F_2day)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F_2day +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.633  -5.184  -1.453   3.468  48.623 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F_2day -0.9791470  0.0236691 -41.368  < 2e-16 ***
## pr                      0.0039498  0.0008876   4.450 8.59e-06 ***
## rmax                    0.0523222  0.0008024  65.207  < 2e-16 ***
## wind                    0.0305852  0.0076904   3.977 6.98e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.15 on 2143222 degrees of freedom
## Multiple R-squared(full model): 0.3319   Adjusted R-squared: 0.3215 
## Multiple R-squared(proj model): 0.004164   Adjusted R-squared: -0.01133 
## F-statistic(full model):31.93 on 33341 and 2143222 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  2240 on 4 and 2143222 DF, p-value: < 2.2e-16
FE_heat_spend_tran_90F_3day <- felm(spend_pertransaction ~ extreme_heat_90F + pr+rmax + wind| 
                             place_month + date|0, 
                           data = df)
summary(FE_heat_spend_tran_90F_3day)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_90F + pr +      rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.116  -5.172  -1.461   3.447  47.873 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_90F -1.6261855  0.0225983 -71.961  < 2e-16 ***
## pr               -0.0034273  0.0008901  -3.851 0.000118 ***
## rmax              0.0514318  0.0007743  66.423  < 2e-16 ***
## wind              0.0551245  0.0076730   7.184 6.76e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.142 on 2143222 degrees of freedom
## Multiple R-squared(full model): 0.333   Adjusted R-squared: 0.3226 
## Multiple R-squared(proj model): 0.005771   Adjusted R-squared: -0.009696 
## F-statistic(full model):32.09 on 33341 and 2143222 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  3110 on 4 and 2143222 DF, p-value: < 2.2e-16
FE_heat_spend_tran_90F_2day <- felm(spend_pertransaction ~ extreme_heat_90F_2day + pr+rmax + wind| 
                             place_month + date|0, 
                           data = df)
summary(FE_heat_spend_tran_90F_2day)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_90F_2day +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.233  -5.179  -1.459   3.457  47.939 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_90F_2day -1.3481057  0.0238691 -56.479  < 2e-16 ***
## pr                    -0.0040393  0.0008942  -4.517 6.27e-06 ***
## rmax                   0.0528624  0.0007791  67.846  < 2e-16 ***
## wind                   0.0739320  0.0076895   9.615  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.146 on 2143222 degrees of freedom
## Multiple R-squared(full model): 0.3324   Adjusted R-squared: 0.322 
## Multiple R-squared(proj model): 0.00485   Adjusted R-squared: -0.01063 
## F-statistic(full model):   32 on 33341 and 2143222 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  2611 on 4 and 2143222 DF, p-value: < 2.2e-16
######################Six MSA, restaurant heat exposure#########
################################################################
MSAs <- unique(df$NAME)

for (msa in MSAs){
  print(msa)
  df_msa <- df[df$NAME==msa,]
  
  print("Number of Observations")
  print(nrow(df_msa))
  FE_heat_city <- felm(spend_pertransaction ~ extreme_heat_100F + pr+rmax + wind| 
                         place_month + date|0, 
                            data = df_msa)
  print(summary(FE_heat_city))
}
## [1] "Dallas-Fort Worth-Arlington, TX"
## [1] "Number of Observations"
## [1] 696374
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -36.006  -5.190  -1.507   3.502  46.418 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F -0.543555   0.074092  -7.336  2.2e-13 ***
## pr                 0.003493   0.001939   1.801   0.0717 .  
## rmax               0.046856   0.004109  11.404  < 2e-16 ***
## wind               0.307414   0.056499   5.441  5.3e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.01 on 685679 degrees of freedom
## Multiple R-squared(full model): 0.3206   Adjusted R-squared:  0.31 
## Multiple R-squared(proj model): 0.0003232   Adjusted R-squared: -0.01527 
## F-statistic(full model):30.26 on 10694 and 685679 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 55.42 on 4 and 685679 DF, p-value: < 2.2e-16 
## 
## 
## [1] "Las Vegas-Henderson-Paradise, NV"
## [1] "Number of Observations"
## [1] 198646
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -34.324  -5.266  -1.873   2.714  45.605 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)  
## extreme_heat_100F -0.2714199  0.1180561  -2.299   0.0215 *
## pr                 0.0006835  0.0311636   0.022   0.9825  
## rmax               0.0040949  0.0174301   0.235   0.8143  
## wind              -0.1816763  0.1109844  -1.637   0.1016  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.35 on 195125 degrees of freedom
## Multiple R-squared(full model): 0.2891   Adjusted R-squared: 0.2763 
## Multiple R-squared(proj model): 4.112e-05   Adjusted R-squared: -0.018 
## F-statistic(full model):22.54 on 3520 and 195125 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 2.006 on 4 and 195125 DF, p-value: 0.0907 
## 
## 
## [1] "Phoenix-Mesa-Chandler, AZ"
## [1] "Number of Observations"
## [1] 400667
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.393  -4.640  -1.000   3.353  48.271 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F -0.624647   0.092374  -6.762 1.36e-11 ***
## pr                -0.013711   0.011225  -1.221    0.222    
## rmax               0.011113   0.009767   1.138    0.255    
## wind              -0.135345   0.092413  -1.465    0.143    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.957 on 394246 degrees of freedom
## Multiple R-squared(full model): 0.4151   Adjusted R-squared: 0.4056 
## Multiple R-squared(proj model): 0.0001272   Adjusted R-squared: -0.01616 
## F-statistic(full model):43.58 on 6420 and 394246 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 12.54 on 4 and 394246 DF, p-value: 3.378e-10 
## 
## 
## [1] "Houston-The Woodlands-Sugar Land, TX"
## [1] "Number of Observations"
## [1] 506325
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -35.354  -5.178  -1.605   3.254  46.653 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F -0.870005   0.089862  -9.682  < 2e-16 ***
## pr                -0.003445   0.002188  -1.574 0.115374    
## rmax               0.048637   0.005075   9.583  < 2e-16 ***
## wind              -0.228953   0.059971  -3.818 0.000135 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.038 on 498245 degrees of freedom
## Multiple R-squared(full model): 0.3334   Adjusted R-squared: 0.3226 
## Multiple R-squared(proj model): 0.0004833   Adjusted R-squared: -0.01572 
## F-statistic(full model):30.85 on 8079 and 498245 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 60.23 on 4 and 498245 DF, p-value: < 2.2e-16 
## 
## 
## [1] "San Antonio-New Braunfels, TX"
## [1] "Number of Observations"
## [1] 199543
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.823  -4.981  -1.454   3.557  49.996 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F -0.801102   0.121460  -6.596 4.25e-11 ***
## pr                -0.003553   0.006540  -0.543  0.58695    
## rmax              -0.030785   0.011778  -2.614  0.00896 ** 
## wind              -0.212195   0.128747  -1.648  0.09932 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.98 on 196132 degrees of freedom
## Multiple R-squared(full model): 0.3461   Adjusted R-squared: 0.3347 
## Multiple R-squared(proj model): 0.0002722   Adjusted R-squared: -0.01711 
## F-statistic(full model):30.44 on 3410 and 196132 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 13.35 on 4 and 196132 DF, p-value: 7.063e-11 
## 
## 
## [1] "Austin-Round Rock-Georgetown, TX"
## [1] "Number of Observations"
## [1] 175009
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + pr +      rmax + wind | place_month + date | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.000  -5.295  -1.622   3.559  46.653 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)   
## extreme_heat_100F -0.4427371  0.1440271  -3.074  0.00211 **
## pr                 0.0008874  0.0053204   0.167  0.86753   
## rmax              -0.0077596  0.0111586  -0.695  0.48681   
## wind              -0.1632020  0.1301376  -1.254  0.20982   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.273 on 171950 degrees of freedom
## Multiple R-squared(full model): 0.3357   Adjusted R-squared: 0.3239 
## Multiple R-squared(proj model): 6.916e-05   Adjusted R-squared: -0.01771 
## F-statistic(full model):28.42 on 3058 and 171950 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 2.973 on 4 and 171950 DF, p-value: 0.01817
########################Air temperature###############
######################################################
FE_airtemp_spend_tran <- felm(spend_pertransaction ~ tmax + pr+rmax + wind| 
                                place_month + date|0, 
                              data = df)
summary(FE_airtemp_spend_tran)
## 
## Call:
##    felm(formula = spend_pertransaction ~ tmax + pr + rmax + wind |      place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.827  -5.165  -1.457   3.434  48.672 
## 
## Coefficients:
##        Estimate Std. Error t value Pr(>|t|)    
## tmax -0.2743620  0.0034347 -79.879   <2e-16 ***
## pr   -0.0016458  0.0008875  -1.854   0.0637 .  
## rmax  0.0290125  0.0008697  33.359   <2e-16 ***
## wind  0.1026045  0.0077005  13.324   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.14 on 2143222 degrees of freedom
## Multiple R-squared(full model): 0.3333   Adjusted R-squared: 0.323 
## Multiple R-squared(proj model): 0.006327   Adjusted R-squared: -0.009131 
## F-statistic(full model):32.14 on 33341 and 2143222 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  3412 on 4 and 2143222 DF, p-value: < 2.2e-16
##############LST as temperature######################
######################################################

load("E:/POI_gridmet_daily_weather_data/df_spend_visit_climate_extreme_lst.RData")
print(nrow(df_lst_spend))
## [1] 269456
FE_lst_spend_tran <- felm(spend_pertransaction ~ LST + pr+rmax + wind| 
                                place_month + date|0, 
                              data = df_lst_spend)
summary(FE_lst_spend_tran)
## 
## Call:
##    felm(formula = spend_pertransaction ~ LST + pr + rmax + wind |      place_month + date | 0, data = df_lst_spend) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -822.96   -3.13    0.00    2.62  866.75 
## 
## Coefficients:
##      Estimate Std. Error t value Pr(>|t|)    
## LST  -0.25691    0.03389  -7.580 3.46e-14 ***
## pr   -0.05965    0.02009  -2.970 0.002978 ** 
## rmax  0.04704    0.01285   3.661 0.000252 ***
## wind  0.59109    0.26818   2.204 0.027522 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.9 on 237089 degrees of freedom
## Multiple R-squared(full model): 0.6898   Adjusted R-squared: 0.6475 
## Multiple R-squared(proj model): 0.0003339   Adjusted R-squared: -0.1361 
## F-statistic(full model):16.29 on 32366 and 237089 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  19.8 on 4 and 237089 DF, p-value: 2.609e-16
##############Weekly aggregation regression###########
######################################################
# weekly_df_new <- df %>%group_by(PLACEKEY, DATE_RANGE_START) %>%
#              summarize(average_spend = mean(spend_pertransaction, na.rm = TRUE),
#              average_heat=mean(extreme_heat_100F,na.rm = TRUE),          
#              average_pr = mean(pr, na.rm = TRUE),
#              average_rmax = mean(rmax, na.rm = TRUE),
#              average_wind = mean(wind, na.rm = TRUE),
#              ave_NAME = first(NAME))
load(file="E:/POI_gridmet_daily_weather_data/weekly_df_spend.RData")

#overall regression
FE_weekly_spend_tran <- felm(average_spend ~ average_heat + average_pr+average_rmax + average_wind|
                               PLACEKEY + DATE_RANGE_START|0,
                              data = weekly_df_new)
summary(FE_weekly_spend_tran)
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = weekly_df_new) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -35.784  -3.909  -0.691   3.161  42.692 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## average_heat -1.812947   0.053743 -33.734   <2e-16 ***
## average_pr    0.002410   0.002337   1.031    0.302    
## average_rmax  0.045979   0.001589  28.939   <2e-16 ***
## average_wind  0.016376   0.016413   0.998    0.318    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.525 on 303840 degrees of freedom
## Multiple R-squared(full model): 0.4162   Adjusted R-squared: 0.3987 
## Multiple R-squared(proj model): 0.008784   Adjusted R-squared: -0.02098 
## F-statistic(full model):23.74 on 9125 and 303840 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 673.1 on 4 and 303840 DF, p-value: < 2.2e-16
#for six MSAs
MSAs <- unique(weekly_df_new$ave_NAME)
for (msa in MSAs){
  print(msa)
  df_msa <- weekly_df_new[weekly_df_new$ave_NAME==msa,]
  
  print("Number of Observations")
  print(nrow(df_msa))
  FE_weekly_spend_tran <- felm(average_spend ~ average_heat + average_pr+average_rmax + average_wind| 
                                 PLACEKEY + DATE_RANGE_START|0, 
                               data = df_msa)
  print(summary(FE_weekly_spend_tran))
}
## [1] "Dallas-Fort Worth-Arlington, TX"
## [1] "Number of Observations"
## [1] 99764
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -36.132  -3.866  -0.631   3.175  41.274 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## average_heat -1.397709   0.144980  -9.641  < 2e-16 ***
## average_pr   -0.002068   0.003653  -0.566    0.571    
## average_rmax  0.022213   0.004409   5.038 4.72e-07 ***
## average_wind  0.017585   0.029953   0.587    0.557    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.433 on 96901 degrees of freedom
## Multiple R-squared(full model): 0.3856   Adjusted R-squared: 0.3675 
## Multiple R-squared(proj model): 0.001384   Adjusted R-squared: -0.02811 
## F-statistic(full model):21.25 on 2862 and 96901 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 33.56 on 4 and 96901 DF, p-value: < 2.2e-16 
## 
## 
## [1] "Las Vegas-Henderson-Paradise, NV"
## [1] "Number of Observations"
## [1] 28849
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -36.248  -4.225  -1.137   2.946  43.155 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## average_heat -0.90451    0.20762  -4.357 1.33e-05 ***
## average_pr    0.05453    0.04599   1.186    0.236    
## average_rmax  0.05789    0.01046   5.532 3.19e-08 ***
## average_wind -0.06176    0.06098  -1.013    0.311    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.731 on 27893 degrees of freedom
## Multiple R-squared(full model): 0.3724   Adjusted R-squared: 0.3509 
## Multiple R-squared(proj model): 0.002182   Adjusted R-squared: -0.03198 
## F-statistic(full model):17.33 on 955 and 27893 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 15.25 on 4 and 27893 DF, p-value: 1.856e-12 
## 
## 
## [1] "Phoenix-Mesa-Chandler, AZ"
## [1] "Number of Observations"
## [1] 57679
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -35.610  -3.527  -0.407   2.993  43.290 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## average_heat -0.7581617  0.1477107  -5.133 2.86e-07 ***
## average_pr    0.0005596  0.0258832   0.022    0.983    
## average_rmax  0.0651988  0.0070255   9.280  < 2e-16 ***
## average_wind  0.0653564  0.0704910   0.927    0.354    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.392 on 55983 degrees of freedom
## Multiple R-squared(full model): 0.5197   Adjusted R-squared: 0.5052 
## Multiple R-squared(proj model): 0.002868   Adjusted R-squared: -0.02732 
## F-statistic(full model):35.74 on 1695 and 55983 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 40.25 on 4 and 55983 DF, p-value: < 2.2e-16 
## 
## 
## [1] "Houston-The Woodlands-Sugar Land, TX"
## [1] "Number of Observations"
## [1] 72836
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -32.827  -3.996  -0.836   3.135  42.264 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## average_heat -1.475391   0.196136  -7.522 5.45e-14 ***
## average_pr   -0.006261   0.004283  -1.462    0.144    
## average_rmax  0.030151   0.007531   4.004 6.24e-05 ***
## average_wind  0.053602   0.038671   1.386    0.166    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.437 on 70650 degrees of freedom
## Multiple R-squared(full model): 0.3949   Adjusted R-squared: 0.3761 
## Multiple R-squared(proj model): 0.00118   Adjusted R-squared: -0.02971 
## F-statistic(full model): 21.1 on 2185 and 70650 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 20.87 on 4 and 70650 DF, p-value: < 2.2e-16 
## 
## 
## [1] "San Antonio-New Braunfels, TX"
## [1] "Number of Observations"
## [1] 28509
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.988  -3.822  -0.707   3.248  40.976 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## average_heat -0.73134    0.24974  -2.928  0.00341 ** 
## average_pr    0.01830    0.01078   1.697  0.08972 .  
## average_rmax  0.04985    0.01170   4.260 2.05e-05 ***
## average_wind  0.01630    0.06779   0.240  0.81005    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.393 on 27606 degrees of freedom
## Multiple R-squared(full model): 0.4326   Adjusted R-squared: 0.414 
## Multiple R-squared(proj model): 0.001215   Adjusted R-squared: -0.03142 
## F-statistic(full model):23.33 on 902 and 27606 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 8.398 on 4 and 27606 DF, p-value: 9.113e-07 
## 
## 
## [1] "Austin-Round Rock-Georgetown, TX"
## [1] "Number of Observations"
## [1] 25329
## 
## Call:
##    felm(formula = average_spend ~ average_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_msa) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.691  -4.023  -0.865   3.327  39.393 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## average_heat -0.902849   0.291422  -3.098  0.00195 **
## average_pr    0.019698   0.009347   2.107  0.03509 * 
## average_rmax  0.011768   0.012077   0.974  0.32985   
## average_wind  0.009797   0.064231   0.153  0.87877   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.671 on 24522 degrees of freedom
## Multiple R-squared(full model): 0.4138   Adjusted R-squared: 0.3945 
## Multiple R-squared(proj model): 0.0006581   Adjusted R-squared: -0.03219 
## F-statistic(full model):21.48 on 806 and 24522 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 4.037 on 4 and 24522 DF, p-value: 0.002832
##################Mobility-weighted Heat Exposure##################
###################################################################

load(paste0("E:/POI_gridmet_daily_weather_data/df_weekly_spend_visit_climate",".RData"))

mobility_weighted <- felm(average_spend ~ weighted_heat +average_pr+average_rmax + average_wind| 
                                      PLACEKEY + DATE_RANGE_START|0, 
                                    data = weekly_visit_spend_climate)
summary(mobility_weighted)
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = weekly_visit_spend_climate) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -179.31   -2.90   -0.31    2.39 1423.70 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.013986   0.001082 -12.926  < 2e-16 ***
## average_pr     0.007624   0.004894   1.558 0.119279    
## average_rmax   0.009574   0.002890   3.312 0.000925 ***
## average_wind   0.171056   0.035764   4.783 1.73e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.09 on 352134 degrees of freedom
## Multiple R-squared(full model): 0.6308   Adjusted R-squared: 0.6181 
## Multiple R-squared(proj model): 0.0007172   Adjusted R-squared: -0.03362 
## F-statistic(full model):49.71 on 12101 and 352134 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 63.19 on 4 and 352134 DF, p-value: < 2.2e-16
############Six MSA, mobility-weighted Heat Exposure#########
#############################################################
load(paste0("E:/POI_gridmet_daily_weather_data/df_weekly_spend_climate",".RData"))

MSAs <- unique(weekly_spend_climate$NAME)
for (msa in MSAs){
print(msa)
df_mobility <- weekly_spend_climate[weekly_spend_climate$NAME==msa,]
print(nrow(df_mobility))
mobility_weighted <- felm(average_spend ~ weighted_heat +average_pr+average_rmax + average_wind| 
                            PLACEKEY + DATE_RANGE_START|0, 
                          data = df_mobility)
print(summary(mobility_weighted))
}
## [1] "Dallas-Fort Worth-Arlington, TX"
## [1] 73368
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19.6501  -2.0374  -0.2105   1.8818  21.1739 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.016436   0.001868  -8.801  < 2e-16 ***
## average_pr     0.001082   0.006470   0.167  0.86722    
## average_rmax   0.019510   0.007311   2.669  0.00762 ** 
## average_wind   0.395605   0.085476   4.628 3.69e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.974 on 70657 degrees of freedom
## Multiple R-squared(full model): 0.5469   Adjusted R-squared: 0.5295 
## Multiple R-squared(proj model): 0.00142   Adjusted R-squared: -0.03688 
## F-statistic(full model):31.47 on 2710 and 70657 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 25.12 on 4 and 70657 DF, p-value: < 2.2e-16 
## 
## 
## [1] "Las Vegas-Henderson-Paradise, NV"
## [1] 21650
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.3146  -2.6028  -0.3417   2.3916  22.0003 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)   
## weighted_heat -0.009544   0.003423  -2.788   0.0053 **
## average_pr     0.036446   0.121468   0.300   0.7641   
## average_rmax  -0.014870   0.026412  -0.563   0.5734   
## average_wind  -0.181079   0.232095  -0.780   0.4353   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.686 on 20740 degrees of freedom
## Multiple R-squared(full model): 0.4976   Adjusted R-squared: 0.4756 
## Multiple R-squared(proj model): 0.000425   Adjusted R-squared: -0.04338 
## F-statistic(full model): 22.6 on 909 and 20740 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 2.204 on 4 and 20740 DF, p-value: 0.06586 
## 
## 
## [1] "Phoenix-Mesa-Chandler, AZ"
## [1] 39134
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.6091  -1.7931  -0.0877   1.7652  18.8989 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.013606   0.002392  -5.688  1.3e-08 ***
## average_pr    -0.040970   0.038152  -1.074    0.283    
## average_rmax   0.019913   0.015593   1.277    0.202    
## average_wind   0.118550   0.179984   0.659    0.510    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.647 on 37548 degrees of freedom
## Multiple R-squared(full model): 0.6293   Adjusted R-squared: 0.6137 
## Multiple R-squared(proj model): 0.0009684   Adjusted R-squared: -0.0412 
## F-statistic(full model):40.22 on 1585 and 37548 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 9.099 on 4 and 37548 DF, p-value: 2.418e-07 
## 
## 
## [1] "Houston-The Woodlands-Sugar Land, TX"
## [1] 44869
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.6929  -2.1346  -0.2214   1.9558  22.5727 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.010985   0.001908  -5.759 8.53e-09 ***
## average_pr    -0.030945   0.008522  -3.631 0.000282 ***
## average_rmax   0.012945   0.009777   1.324 0.185488    
## average_wind   0.169459   0.110600   1.532 0.125487    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.088 on 42826 degrees of freedom
## Multiple R-squared(full model): 0.5568   Adjusted R-squared: 0.5357 
## Multiple R-squared(proj model): 0.001234   Adjusted R-squared: -0.04639 
## F-statistic(full model):26.35 on 2042 and 42826 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 13.23 on 4 and 42826 DF, p-value: 9.075e-11 
## 
## 
## [1] "San Antonio-New Braunfels, TX"
## [1] 22622
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -19.0533  -2.1608  -0.2745   2.0487  21.4861 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.010824   0.002968  -3.647 0.000266 ***
## average_pr     0.012307   0.023768   0.518 0.604610    
## average_rmax  -0.014843   0.020819  -0.713 0.475876    
## average_wind   0.431415   0.187194   2.305 0.021196 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.136 on 21761 degrees of freedom
## Multiple R-squared(full model): 0.5639   Adjusted R-squared: 0.5467 
## Multiple R-squared(proj model): 0.0009038   Adjusted R-squared: -0.03858 
## F-statistic(full model):32.72 on 860 and 21761 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 4.921 on 4 and 21761 DF, p-value: 0.0005781 
## 
## 
## [1] "Austin-Round Rock-Georgetown, TX"
## [1] 15165
## 
## Call:
##    felm(formula = average_spend ~ weighted_heat + average_pr + average_rmax +      average_wind | PLACEKEY + DATE_RANGE_START | 0, data = df_mobility) 
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.6577  -2.2881  -0.2875   2.0642  18.4903 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## weighted_heat -0.012991   0.003570  -3.639 0.000274 ***
## average_pr    -0.003243   0.025127  -0.129 0.897311    
## average_rmax  -0.040935   0.023052  -1.776 0.075797 .  
## average_wind   0.182354   0.213909   0.852 0.393959    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.289 on 14424 degrees of freedom
## Multiple R-squared(full model): 0.5449   Adjusted R-squared: 0.5215 
## Multiple R-squared(proj model): 0.001316   Adjusted R-squared: -0.04992 
## F-statistic(full model):23.33 on 740 and 14424 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 4.751 on 4 and 14424 DF, p-value: 0.0007889
################IV regression##################
###############################################

files <- list.files(path = "E:/POI_gridmet_daily_weather_data/grass",  full.names = TRUE) #read grass evaporation data

df_grass_eva<-data.frame()
for (i in 1:40){
  load(files[i])
  print(i)
  daily_grass$eva <- daily_grass$grass$`pet_2019-05-01`
  daily_grass$grass <-NULL
  current_df <- merge(df, daily_grass, by=c("PLACEKEY","date"))
  df_grass_eva <-bind_rows(df_grass_eva,current_df)
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
## [1] 11
## [1] 12
## [1] 13
## [1] 14
## [1] 15
## [1] 16
## [1] 17
## [1] 18
## [1] 19
## [1] 20
## [1] 21
## [1] 22
## [1] 23
## [1] 24
## [1] 25
## [1] 26
## [1] 27
## [1] 28
## [1] 29
## [1] 30
## [1] 31
## [1] 32
## [1] 33
## [1] 34
## [1] 35
## [1] 36
## [1] 37
## [1] 38
## [1] 39
## [1] 40
########stage I: Grass reference evapotranspiration for Heat########
first_stage <- felm(extreme_heat_100F ~eva+ pr+rmax + wind| 
                    PLACEKEY + date|0, 
                    data = df_grass_eva)
summary(first_stage)
## 
## Call:
##    felm(formula = extreme_heat_100F ~ eva + pr + rmax + wind | PLACEKEY +      date | 0, data = df_grass_eva) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.1619 -0.1931 -0.0001  0.1573  1.1186 
## 
## Coefficients:
##        Estimate Std. Error t value Pr(>|t|)    
## eva   2.719e-02  3.078e-04   88.35   <2e-16 ***
## pr    2.662e-03  2.796e-05   95.21   <2e-16 ***
## rmax -5.872e-03  2.809e-05 -209.07   <2e-16 ***
## wind -2.421e-02  2.884e-04  -83.96   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2837 on 2163342 degrees of freedom
## Multiple R-squared(full model): 0.5332   Adjusted R-squared: 0.5312 
## Multiple R-squared(proj model): 0.06106   Adjusted R-squared: 0.05697 
## F-statistic(full model):261.8 on 9441 and 2163342 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 3.517e+04 on 4 and 2163342 DF, p-value: < 2.2e-16
##get the fitted values
fixed_effects <- getfe(first_stage)$fe
model_coefs <- coef(first_stage) # Extracting model coefficients
model_mat <- model.matrix(~ 0+eva + pr + rmax + wind, data = df_grass_eva) #create matrix
linear_predictor <- model_mat %*% model_coefs
df_grass_eva$fitted_heat <-linear_predictor

#########stage II: Fitted heat for spend########
second_stage <- felm(spend_pertransaction ~fitted_heat+ pr+rmax + wind| 
                      PLACEKEY + date|0, 
                    data = df_grass_eva)

summary(second_stage)
## 
## Call:
##    felm(formula = spend_pertransaction ~ fitted_heat + pr + rmax +      wind | PLACEKEY + date | 0, data = df_grass_eva) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.231  -5.267  -1.515   3.529  48.543 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## fitted_heat -15.324357   0.366575  -41.80   <2e-16 ***
## pr            0.034172   0.001179   28.97   <2e-16 ***
## rmax         -0.064236   0.002846  -22.57   <2e-16 ***
## wind         -0.139193   0.008340  -16.69   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.19 on 2163342 degrees of freedom
## Multiple R-squared(full model): 0.3186   Adjusted R-squared: 0.3156 
## Multiple R-squared(proj model): 0.003584   Adjusted R-squared: -0.0007649 
## F-statistic(full model):107.1 on 9441 and 2163342 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  1945 on 4 and 2163342 DF, p-value: < 2.2e-16
################Long-term effects of extreme heat##################
###################################################################
FE_airtemp_spend_tran_7days <- felm(spend_pertransaction ~ extreme_heat_100F+extreme_heat_7days + pr+rmax + wind| 
                                      place_month + date|0, 
                                    data = df)
summary(FE_airtemp_spend_tran_7days)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + extreme_heat_7days +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.548  -5.190  -1.454   3.462  48.537 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F  -0.6674952  0.0284429 -23.468  < 2e-16 ***
## extreme_heat_7days -0.9881667  0.0426329 -23.178  < 2e-16 ***
## pr                  0.0044162  0.0009147   4.828 1.38e-06 ***
## rmax                0.0501979  0.0008056  62.312  < 2e-16 ***
## wind                0.0300137  0.0077705   3.863 0.000112 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.154 on 2110714 degrees of freedom
##   (32513 observations deleted due to missingness)
## Multiple R-squared(full model): 0.332   Adjusted R-squared: 0.3215 
## Multiple R-squared(proj model): 0.004433   Adjusted R-squared: -0.01129 
## F-statistic(full model):31.47 on 33336 and 2110714 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  1880 on 5 and 2110714 DF, p-value: < 2.2e-16
FE_airtemp_spend_tran_14days <- felm(spend_pertransaction ~ extreme_heat_100F+extreme_heat_14days + pr+rmax + wind| 
                                       place_month + date|0, 
                                     data = df)
summary(FE_airtemp_spend_tran_14days)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + extreme_heat_14days +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.465  -5.191  -1.459   3.455  48.575 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F   -0.7009335  0.0261440 -26.811  < 2e-16 ***
## extreme_heat_14days -1.5652202  0.0496750 -31.509  < 2e-16 ***
## pr                   0.0062878  0.0010072   6.243 4.31e-10 ***
## rmax                 0.0493541  0.0008115  60.815  < 2e-16 ***
## wind                 0.0325882  0.0078544   4.149 3.34e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.16 on 2073163 degrees of freedom
##   (70071 observations deleted due to missingness)
## Multiple R-squared(full model): 0.3326   Adjusted R-squared: 0.3219 
## Multiple R-squared(proj model): 0.004742   Adjusted R-squared: -0.01126 
## F-statistic(full model):31.01 on 33329 and 2073163 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  1976 on 5 and 2073163 DF, p-value: < 2.2e-16
FE_airtemp_spend_tran_21days <- felm(spend_pertransaction ~ extreme_heat_100F+extreme_heat_21days + pr+rmax + wind| 
                                       place_month + date|0, 
                                     data = df)
summary(FE_airtemp_spend_tran_21days)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + extreme_heat_21days +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.343  -5.190  -1.464   3.445  48.603 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F   -0.6858297  0.0255530 -26.839  < 2e-16 ***
## extreme_heat_21days -2.2644277  0.0560406 -40.407  < 2e-16 ***
## pr                   0.0073856  0.0010339   7.143 9.11e-13 ***
## rmax                 0.0486307  0.0008122  59.873  < 2e-16 ***
## wind                 0.0437729  0.0080362   5.447 5.12e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.162 on 2035402 degrees of freedom
##   (107839 observations deleted due to missingness)
## Multiple R-squared(full model): 0.3336   Adjusted R-squared: 0.3227 
## Multiple R-squared(proj model): 0.005062   Adjusted R-squared: -0.01123 
## F-statistic(full model):30.58 on 33322 and 2035402 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  2071 on 5 and 2035402 DF, p-value: < 2.2e-16
FE_airtemp_spend_tran_28days <- felm(spend_pertransaction ~ extreme_heat_100F+extreme_heat_28days + pr+rmax + wind| 
                                       place_month + date|0, 
                                     data = df)
summary(FE_airtemp_spend_tran_28days)
## 
## Call:
##    felm(formula = spend_pertransaction ~ extreme_heat_100F + extreme_heat_28days +      pr + rmax + wind | place_month + date | 0, data = df) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -37.247  -5.183  -1.463   3.435  48.627 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## extreme_heat_100F   -0.7508903  0.0252191 -29.775  < 2e-16 ***
## extreme_heat_28days -2.4235458  0.0622031 -38.962  < 2e-16 ***
## pr                   0.0086110  0.0010353   8.317  < 2e-16 ***
## rmax                 0.0491522  0.0008183  60.063  < 2e-16 ***
## wind                 0.0322120  0.0081916   3.932 8.41e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.159 on 1997488 degrees of freedom
##   (145760 observations deleted due to missingness)
## Multiple R-squared(full model): 0.3355   Adjusted R-squared: 0.3245 
## Multiple R-squared(proj model): 0.005011   Adjusted R-squared: -0.01158 
## F-statistic(full model):30.28 on 33315 and 1997488 DF, p-value: < 2.2e-16 
## F-statistic(proj model):  2012 on 5 and 1997488 DF, p-value: < 2.2e-16