library(lfe)
## Warning: package 'lfe' was built under R version 4.3.2
## Loading required package: Matrix
load("E:/POI_gridmet_daily_weather_data/df_spend_visit_climate_extreme_lst.RData")
Q1 <- quantile(df_lst_spend$spend_pertransaction, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df_lst_spend$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_lst_spend <- df_lst_spend[df_lst_spend$spend_pertransaction >= lower_bound & df_lst_spend$spend_pertransaction <= upper_bound, ]
#air temp bin
# Define the breaks with a step size of 2
breaks <- seq(10, 70,by = 5)

# Define custom labels for bins
custom_labels <- paste0("(", breaks[-length(breaks)], ", ", breaks[-1], "]")

# Categorize the column into bins with a step size of 2
df_lst_spend$temp_bin <- cut(df_lst_spend$LST, breaks = breaks, labels = custom_labels, include.lowest = TRUE)

df_lst_spend$temp_bin <- relevel(df_lst_spend$temp_bin, ref = "(20, 25]")

FE_tempbin_spend_tran_lst <- felm(spend_pertransaction ~ temp_bin + pr+rmax + wind| 
                                place_month + date|0, 
                              data = df_lst_spend)
summary(FE_tempbin_spend_tran_lst)
## 
## Call:
##    felm(formula = spend_pertransaction ~ temp_bin + pr + rmax +      wind | place_month + date | 0, data = df_lst_spend) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -30.170  -2.272   0.000   1.944  34.373 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## temp_bin(10, 15] -5.414142   9.584897  -0.565 0.572168    
## temp_bin(25, 30] -3.028724   1.440311  -2.103 0.035482 *  
## temp_bin(30, 35] -4.419479   1.346831  -3.281 0.001033 ** 
## temp_bin(35, 40] -3.833173   1.336050  -2.869 0.004118 ** 
## temp_bin(40, 45] -4.033800   1.339107  -3.012 0.002593 ** 
## temp_bin(45, 50] -3.917013   1.341315  -2.920 0.003498 ** 
## temp_bin(50, 55] -3.820008   1.344411  -2.841 0.004492 ** 
## temp_bin(55, 60] -4.035163   1.354667  -2.979 0.002895 ** 
## temp_bin(60, 65] -3.692000   1.426662  -2.588 0.009658 ** 
## temp_bin(65, 70]  2.247179   1.977942   1.136 0.255908    
## pr               -0.027244   0.007988  -3.411 0.000648 ***
## rmax              0.032838   0.005054   6.497 8.20e-11 ***
## wind             -0.593571   0.106682  -5.564 2.64e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.706 on 220425 degrees of freedom
##   (9 observations deleted due to missingness)
## Multiple R-squared(full model): 0.695   Adjusted R-squared: 0.6517 
## Multiple R-squared(proj model): 0.0005547   Adjusted R-squared: -0.1415 
## F-statistic(full model):16.04 on 31319 and 220425 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 9.411 on 13 and 220425 DF, p-value: < 2.2e-16
nrow(df_lst_spend)
## [1] 251754
load("E:/POI_gridmet_daily_weather_data/df_spend_visit_climate_extreme_lst.RData")
Q1 <- quantile(df_lst_spend$visit, 0.25, na.rm = TRUE) # 1st Quartile
Q3 <- quantile(df_lst_spend$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_lst_spend <- df_lst_spend[df_lst_spend$visit >= lower_bound & df_lst_spend$visit <= upper_bound, ]
nrow(df_lst_spend)
## [1] 242021
#air temp bin
# Define the breaks with a step size of 2
breaks <- seq(10, 70,by = 5)

# Define custom labels for bins
custom_labels <- paste0("(", breaks[-length(breaks)], ", ", breaks[-1], "]")

# Categorize the column into bins with a step size of 2
df_lst_spend$temp_bin <- cut(df_lst_spend$LST, breaks = breaks, labels = custom_labels, include.lowest = TRUE)

df_lst_spend$temp_bin <- relevel(df_lst_spend$temp_bin, ref = "(20, 25]")

FE_tempbin_spend_tran_lst <- felm(visit ~ temp_bin + pr+rmax + wind| 
                                place_month + date|0, 
                              data = df_lst_spend)
summary(FE_tempbin_spend_tran_lst)
## 
## Call:
##    felm(formula = visit ~ temp_bin + pr + rmax + wind | place_month +      date | 0, data = df_lst_spend) 
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -22.152  -1.476   0.000   1.353  25.015 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## temp_bin(10, 15] -5.247458   6.046179  -0.868  0.38545    
## temp_bin(25, 30] -2.130621   1.099764  -1.937  0.05270 .  
## temp_bin(30, 35] -1.704921   1.060746  -1.607  0.10799    
## temp_bin(35, 40] -0.715500   1.056135  -0.677  0.49811    
## temp_bin(40, 45] -0.394872   1.057382  -0.373  0.70882    
## temp_bin(45, 50] -0.502013   1.059031  -0.474  0.63548    
## temp_bin(50, 55]  0.109583   1.060760   0.103  0.91772    
## temp_bin(55, 60]  0.258546   1.065139   0.243  0.80821    
## temp_bin(60, 65] -1.604378   1.106436  -1.450  0.14705    
## temp_bin(65, 70]  4.391425   1.406133   3.123  0.00179 ** 
## pr                0.021534   0.005084   4.236 2.28e-05 ***
## rmax              0.031407   0.003320   9.461  < 2e-16 ***
## wind              0.016506   0.068479   0.241  0.80953    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.206 on 208938 degrees of freedom
##   (3705 observations deleted due to missingness)
## Multiple R-squared(full model): 0.8022   Adjusted R-squared: 0.7744 
## Multiple R-squared(proj model): 0.001938   Adjusted R-squared: -0.1384 
## F-statistic(full model):28.85 on 29377 and 208938 DF, p-value: < 2.2e-16 
## F-statistic(proj model): 31.21 on 13 and 208938 DF, p-value: < 2.2e-16
nrow(df_lst_spend)
## [1] 242021