Basic Set Up and install and load all necessary libraries

options(scipen=999, digits = 2)
library(ggplot2)
library(ggthemes)  
library(ggfortify)
library(ggpubr) 
library(corrplot)
library(tidyverse)
library(dplyr)
library(RColorBrewer)
library(haven)
library(lcsm)
library(car)
library(psych)
library(plm)
library(stargazer)
library(choroplethr)
library(choroplethrMaps)
library(tidycensus)
library(usdata)

Research Questions (Tentative)

Research Question 1: What are the dominant trajectories of philanthropic capacity observed over a 7-year time span?

  • Part 1: Descriptive Analysis

Research Question 2: Is philanthropy subject to Matthew effect—Significant disparities exist in the philanthropic capacity between advantaged communities and disadvantaged communities over time?

  • Part 2: Regression Analysis

Research Question 3: If variation in philanthropic capacity exists across communities, to what extent is this variation explained by community-level structural factors (e.g., differences in resources and demand for services based on organizational location), or factors related to the capacity of the local nonprofit sector?

  • Part 2: Regression Analysis

Research Question 4: How do minority population, racial segregation, and ruralness moderate the philanthropic trajectory over time?

  • Interaction and Mediation Analysis in the future

Read dta file to R

hs_1yr <- read_dta("df_dta_990_by_fips_year_HU_acs1.dta")
hs_5yr <- read_dta("df_dta_990_by_fips_year_HU_acs5_03282022.dta")

Exploratory Data Analysis

summary(hs_1yr) # more missing data for hs_1yr
##      index           FIPS                year      GvrnmntGrntsAmt     
##  Min.   :  126   Length:19059       Min.   :2014   Min.   :         0  
##  1st Qu.: 4890   Class :character   1st Qu.:2015   1st Qu.:         0  
##  Median : 9655   Mode  :character   Median :2016   Median :    487606  
##  Mean   : 9655                      Mean   :2016   Mean   :  15594761  
##  3rd Qu.:14420                      3rd Qu.:2018   3rd Qu.:   4617548  
##  Max.   :19184                      Max.   :2019   Max.   :4873851024  
##                                                                        
##  TtlCntrbtnsAmt       TtlRvn_TtlRvnClmnAmt  TtlPrgrmSrvcRvnAmt  
##  Min.   :         0   Min.   :    -175569   Min.   :   -229109  
##  1st Qu.:    122428   1st Qu.:     442733   1st Qu.:     90447  
##  Median :   1367988   Median :    3999608   Median :   1583555  
##  Mean   :  31936229   Mean   :   86045011   Mean   :  48713719  
##  3rd Qu.:   9221397   3rd Qu.:   24882562   3rd Qu.:  13246322  
##  Max.   :7886687938   Max.   :14182582618   Max.   :8003958358  
##                                                                 
##  TtlAssts_EOYAmt       TtlLblts_EOYAmt      TtlFnctnlExpnss_FndrsngAmt
##  Min.   :     -88626   Min.   :    -21977   Min.   :  -120361         
##  1st Qu.:     670936   1st Qu.:     33409   1st Qu.:        0         
##  Median :    5780763   Median :   1133968   Median :    10132         
##  Mean   :  139070379   Mean   :  63758853   Mean   :  1200143         
##  3rd Qu.:   36010289   3rd Qu.:   9561173   3rd Qu.:   207700         
##  Max.   :21151470598   Max.   :9531011011   Max.   :385501706         
##                                                                       
##  EIN_count_all   EIN_count_HE    EIN_count_HU  county_giving       
##  Min.   :   1   Min.   : NA     Min.   :   1   Min.   :         0  
##  1st Qu.:  14   1st Qu.: NA     1st Qu.:  14   1st Qu.:     32276  
##  Median :  33   Median : NA     Median :  33   Median :    518629  
##  Mean   : 117   Mean   :NaN     Mean   : 116   Mean   :  16341469  
##  3rd Qu.:  86   3rd Qu.: NA     3rd Qu.:  86   3rd Qu.:   3507468  
##  Max.   :8853   Max.   : NA     Max.   :8829   Max.   :6677536401  
##                 NA's   :19059                                      
##      NAME              state              county          unemployed_int  
##  Length:19059       Length:19059       Length:19059       Min.   :   388  
##  Class :character   Class :character   Class :character   1st Qu.:  2611  
##  Mode  :character   Mode  :character   Mode  :character   Median :  4489  
##                                                           Mean   : 10101  
##                                                           3rd Qu.:  9890  
##                                                           Max.   :456214  
##                                                           NA's   :14422   
##  bachelor_degr_int total_popu_int     gini_income_float  white_alone     
##  Min.   :   4455   Min.   :   62385   Min.   :0         Min.   :   8544  
##  1st Qu.:  17887   1st Qu.:  102144   1st Qu.:0         1st Qu.:  83615  
##  Median :  34266   Median :  164765   Median :0         Median : 138022  
##  Mean   :  86222   Mean   :  348591   Mean   :0         Mean   : 245741  
##  3rd Qu.:  84169   3rd Qu.:  356495   3rd Qu.:0         3rd Qu.: 265422  
##  Max.   :2512048   Max.   :10170292   Max.   :1         Max.   :5313124  
##  NA's   :14422     NA's   :14422      NA's   :14422     NA's   :14422    
##   black_alone      indian_alaska_alone  asian_alone      hawaiian_alone  
##  Min.   :      0   Min.   :    0       Min.   :      0   Min.   :     0  
##  1st Qu.:   3499   1st Qu.:  246       1st Qu.:   1231   1st Qu.:     0  
##  Median :  11525   Median :  693       Median :   3314   Median :    61  
##  Mean   :  45615   Mean   : 2372       Mean   :  22343   Mean   :   710  
##  3rd Qu.:  39502   3rd Qu.: 1887       3rd Qu.:  11816   3rd Qu.:   273  
##  Max.   :1251913   Max.   :93358       Max.   :1500637   Max.   :101448  
##  NA's   :14422     NA's   :14422       NA's   :14422     NA's   :14422   
##  other_race_alone  two_more_race    two_other_race   two_more_other_race
##  Min.   :      0   Min.   :   215   Min.   :     0   Min.   :    57     
##  1st Qu.:   1023   1st Qu.:  2426   1st Qu.:   154   1st Qu.:  2147     
##  Median :   3033   Median :  4713   Median :   513   Median :  4179     
##  Mean   :  19746   Mean   : 12065   Mean   :  1899   Mean   : 10166     
##  3rd Qu.:   9947   3rd Qu.: 11321   3rd Qu.:  1511   3rd Qu.:  9828     
##  Max.   :2310179   Max.   :436362   Max.   :135124   Max.   :301238     
##  NA's   :14422     NA's   :14422    NA's   :14422    NA's   :14422      
##    race_total          race_hhi      poverty_rate mh_income_usd   
##  Min.   :   63580   Min.   :0       Min.   :0     Min.   : 21658  
##  1st Qu.:  104243   1st Qu.:0       1st Qu.:0     1st Qu.: 41798  
##  Median :  169615   Median :0       Median :0     Median : 48759  
##  Mean   :  360656   Mean   :0       Mean   :0     Mean   : 50746  
##  3rd Qu.:  366141   3rd Qu.:0       3rd Qu.:0     3rd Qu.: 56741  
##  Max.   :10543419   Max.   :1       Max.   :1     Max.   :151806  
##  NA's   :14422      NA's   :14422   NA's   :573   NA's   :573     
##  GvrnmntGrntsAmt_log1p TtlCntrbtnsAmt_log1p TtlRvn_TtlRvnClmnAmt_log1p
##  Min.   : 0.0          Min.   : 0.0         Min.   : 0.0              
##  1st Qu.: 0.0          1st Qu.:11.7         1st Qu.:13.0              
##  Median :13.1          Median :14.1         Median :15.2              
##  Mean   :10.5          Mean   :12.3         Mean   :13.5              
##  3rd Qu.:15.3          3rd Qu.:16.0         3rd Qu.:17.0              
##  Max.   :22.3          Max.   :22.8         Max.   :23.4              
##                                             NA's   :22                
##  TtlPrgrmSrvcRvnAmt_log1p TtlAssts_EOYAmt_log1p TtlLblts_EOYAmt_log1p
##  Min.   : 0.0             Min.   : 0.0          Min.   : 0.0         
##  1st Qu.:11.4             1st Qu.:13.4          1st Qu.:10.4         
##  Median :14.3             Median :15.6          Median :13.9         
##  Mean   :12.2             Mean   :13.8          Mean   :12.0         
##  3rd Qu.:16.4             3rd Qu.:17.4          3rd Qu.:16.1         
##  Max.   :22.8             Max.   :23.8          Max.   :23.0         
##  NA's   :2                NA's   :12            NA's   :10           
##  TtlFnctnlExpnss_FndrsngAmt_log1p county_giving_log1p mh_income_usd_log1p
##  Min.   : 0.0                     Min.   : 0.0        Min.   :10         
##  1st Qu.: 0.0                     1st Qu.:10.4        1st Qu.:11         
##  Median : 9.2                     Median :13.2        Median :11         
##  Mean   : 7.0                     Mean   :11.3        Mean   :11         
##  3rd Qu.:12.2                     3rd Qu.:15.1        3rd Qu.:11         
##  Max.   :19.8                     Max.   :22.6        Max.   :12         
##  NA's   :3                                            NA's   :573        
##  unemployed_int_log1p bachelor_degr_int_log1p total_popu_int_log1p
##  Min.   : 6           Min.   : 8              Min.   :11          
##  1st Qu.: 8           1st Qu.:10              1st Qu.:12          
##  Median : 8           Median :10              Median :12          
##  Mean   : 9           Mean   :11              Mean   :12          
##  3rd Qu.: 9           3rd Qu.:11              3rd Qu.:13          
##  Max.   :13           Max.   :15              Max.   :16          
##  NA's   :14422        NA's   :14422           NA's   :14422       
##  npo_per_capita_all npo_per_capita_HU npo_per_capita_HE
##  Min.   :0          Min.   :0         Min.   : NA      
##  1st Qu.:0          1st Qu.:0         1st Qu.: NA      
##  Median :0          Median :0         Median : NA      
##  Mean   :0          Mean   :0         Mean   :NaN      
##  3rd Qu.:0          3rd Qu.:0         3rd Qu.: NA      
##  Max.   :0          Max.   :0         Max.   : NA      
##  NA's   :14422      NA's   :14422     NA's   :19059
summary(hs_5yr)
##      index           FIPS                year      GvrnmntGrntsAmt     
##  Min.   :  126   Length:19059       Min.   :2014   Min.   :         0  
##  1st Qu.: 4890   Class :character   1st Qu.:2015   1st Qu.:         0  
##  Median : 9655   Mode  :character   Median :2016   Median :    487606  
##  Mean   : 9655                      Mean   :2016   Mean   :  15594761  
##  3rd Qu.:14420                      3rd Qu.:2018   3rd Qu.:   4617548  
##  Max.   :19184                      Max.   :2019   Max.   :4873851024  
##                                                                        
##  TtlCntrbtnsAmt       TtlRvn_TtlRvnClmnAmt  TtlPrgrmSrvcRvnAmt  
##  Min.   :         0   Min.   :    -175569   Min.   :   -229109  
##  1st Qu.:    122428   1st Qu.:     442733   1st Qu.:     90447  
##  Median :   1367988   Median :    3999608   Median :   1583555  
##  Mean   :  31936229   Mean   :   86045011   Mean   :  48713719  
##  3rd Qu.:   9221397   3rd Qu.:   24882562   3rd Qu.:  13246322  
##  Max.   :7886687938   Max.   :14182582618   Max.   :8003958358  
##                                                                 
##  TtlAssts_EOYAmt       TtlLblts_EOYAmt      TtlFnctnlExpnss_FndrsngAmt
##  Min.   :     -88626   Min.   :    -21977   Min.   :  -120361         
##  1st Qu.:     670936   1st Qu.:     33409   1st Qu.:        0         
##  Median :    5780763   Median :   1133968   Median :    10132         
##  Mean   :  139070379   Mean   :  63758853   Mean   :  1200143         
##  3rd Qu.:   36010289   3rd Qu.:   9561173   3rd Qu.:   207700         
##  Max.   :21151470598   Max.   :9531011011   Max.   :385501706         
##                                                                       
##  EIN_count_all   EIN_count_HE    EIN_count_HU      NAME          
##  Min.   :   1   Min.   : NA     Min.   :   1   Length:19059      
##  1st Qu.:  14   1st Qu.: NA     1st Qu.:  14   Class :character  
##  Median :  33   Median : NA     Median :  33   Mode  :character  
##  Mean   : 117   Mean   :NaN     Mean   : 116                     
##  3rd Qu.:  86   3rd Qu.: NA     3rd Qu.:  86                     
##  Max.   :8853   Max.   : NA     Max.   :8829                     
##                 NA's   :19059                                    
##     state              county          unemployed_int   bachelor_degr_int
##  Length:19059       Length:19059       Min.   :     0   Min.   :      4  
##  Class :character   Class :character   1st Qu.:   308   1st Qu.:   1275  
##  Mode  :character   Mode  :character   Median :   823   Median :   3355  
##                                        Mean   :  3633   Mean   :  22464  
##                                        3rd Qu.:  2306   3rd Qu.:  10540  
##                                        Max.   :564669   Max.   :2396090  
##                                        NA's   :230      NA's   :230      
##  total_popu_int     gini_income_float  white_alone       black_alone     
##  Min.   :     228   Min.   :0         Min.   :    226   Min.   :      0  
##  1st Qu.:   11295   1st Qu.:0         1st Qu.:   9277   1st Qu.:    107  
##  Median :   26297   Median :0         Median :  22329   Median :    810  
##  Mean   :  101519   Mean   :0         Mean   :  74477   Mean   :  12539  
##  3rd Qu.:   66972   3rd Qu.:0         3rd Qu.:  57375   3rd Qu.:   5466  
##  Max.   :10105722   Max.   :1         Max.   :5346316   Max.   :1264466  
##  NA's   :230        NA's   :230       NA's   :230       NA's   :230      
##  indian_alaska_alone  asian_alone      hawaiian_alone  other_race_alone 
##  Min.   :    0       Min.   :      0   Min.   :    0   Min.   :      0  
##  1st Qu.:   30       1st Qu.:     30   1st Qu.:    0   1st Qu.:     48  
##  Median :  112       Median :    132   Median :    3   Median :    241  
##  Mean   :  809       Mean   :   5329   Mean   :  177   Mean   :   5006  
##  3rd Qu.:  417       3rd Qu.:    685   3rd Qu.:   33   3rd Qu.:   1129  
##  Max.   :85876       Max.   :1473221   Max.   :93980   Max.   :2121102  
##  NA's   :230         NA's   :230       NA's   :230     NA's   :230      
##  two_more_race    two_other_race   two_more_other_race   race_total      
##  Min.   :     0   Min.   :     0   Min.   :     0      Min.   :     228  
##  1st Qu.:   166   1st Qu.:     6   1st Qu.:   143      1st Qu.:   11597  
##  Median :   467   Median :    41   Median :   417      Median :   26847  
##  Mean   :  3182   Mean   :   498   Mean   :  2685      Mean   :  104702  
##  3rd Qu.:  1666   3rd Qu.:   170   3rd Qu.:  1487      3rd Qu.:   68660  
##  Max.   :402767   Max.   :115953   Max.   :286814      Max.   :10495732  
##  NA's   :230      NA's   :230      NA's   :230         NA's   :230       
##     race_hhi    poverty_rate mh_income_usd     urban_rural 
##  Min.   :0     Min.   :0     Min.   : 21658   Min.   :1    
##  1st Qu.:0     1st Qu.:0     1st Qu.: 41798   1st Qu.:2    
##  Median :0     Median :0     Median : 48759   Median :6    
##  Mean   :0     Mean   :0     Mean   : 50746   Mean   :5    
##  3rd Qu.:0     3rd Qu.:0     3rd Qu.: 56741   3rd Qu.:7    
##  Max.   :1     Max.   :1     Max.   :151806   Max.   :9    
##  NA's   :230   NA's   :573   NA's   :573      NA's   :567  
##  county_giving        npo_per1kcapita_all npo_per1kcapita_HU npo_per1kcapita_HE
##  Min.   :         0   Min.   : 0          Min.   : 0         Min.   : NA       
##  1st Qu.:     32276   1st Qu.: 1          1st Qu.: 1         1st Qu.: NA       
##  Median :    518629   Median : 1          Median : 1         Median : NA       
##  Mean   :  16341469   Mean   : 2          Mean   : 2         Mean   :NaN       
##  3rd Qu.:   3507468   3rd Qu.: 2          3rd Qu.: 2         3rd Qu.: NA       
##  Max.   :6677536401   Max.   :14          Max.   :14         Max.   : NA       
##                       NA's   :230         NA's   :230        NA's   :19059     
##  county_giving_per1kcapital GvrnmntGrntsAmt_log1p TtlCntrbtnsAmt_log1p
##  Min.   :       0           Min.   : 0.0          Min.   : 0.0        
##  1st Qu.:    2179           1st Qu.: 0.0          1st Qu.:11.7        
##  Median :   20329           Median :13.1          Median :14.1        
##  Mean   :   61607           Mean   :10.5          Mean   :12.3        
##  3rd Qu.:   60217           3rd Qu.:15.3          3rd Qu.:16.0        
##  Max.   :10055065           Max.   :22.3          Max.   :22.8        
##  NA's   :230                                                          
##  TtlRvn_TtlRvnClmnAmt_log1p TtlPrgrmSrvcRvnAmt_log1p TtlAssts_EOYAmt_log1p
##  Min.   : 0.0               Min.   : 0.0             Min.   : 0.0         
##  1st Qu.:13.0               1st Qu.:11.4             1st Qu.:13.4         
##  Median :15.2               Median :14.3             Median :15.6         
##  Mean   :13.5               Mean   :12.2             Mean   :13.8         
##  3rd Qu.:17.0               3rd Qu.:16.4             3rd Qu.:17.4         
##  Max.   :23.4               Max.   :22.8             Max.   :23.8         
##  NA's   :22                 NA's   :2                NA's   :12           
##  TtlLblts_EOYAmt_log1p TtlFnctnlExpnss_FndrsngAmt_log1p EIN_count_all_log1p
##  Min.   : 0.0          Min.   : 0.0                     Min.   :0.7        
##  1st Qu.:10.4          1st Qu.: 0.0                     1st Qu.:2.7        
##  Median :13.9          Median : 9.2                     Median :3.5        
##  Mean   :12.0          Mean   : 7.0                     Mean   :3.7        
##  3rd Qu.:16.1          3rd Qu.:12.2                     3rd Qu.:4.5        
##  Max.   :23.0          Max.   :19.8                     Max.   :9.1        
##  NA's   :10            NA's   :3                                           
##  EIN_count_HE_log1p EIN_count_HU_log1p unemployed_int_log1p
##  Min.   : NA        Min.   :0.7        Min.   : 0          
##  1st Qu.: NA        1st Qu.:2.7        1st Qu.: 6          
##  Median : NA        Median :3.5        Median : 7          
##  Mean   :NaN        Mean   :3.7        Mean   : 7          
##  3rd Qu.: NA        3rd Qu.:4.5        3rd Qu.: 8          
##  Max.   : NA        Max.   :9.1        Max.   :13          
##  NA's   :19059                         NA's   :230         
##  bachelor_degr_int_log1p total_popu_int_log1p gini_income_float_log1p
##  Min.   : 2              Min.   : 5           Min.   :0              
##  1st Qu.: 7              1st Qu.: 9           1st Qu.:0              
##  Median : 8              Median :10           Median :0              
##  Mean   : 8              Mean   :10           Mean   :0              
##  3rd Qu.: 9              3rd Qu.:11           3rd Qu.:0              
##  Max.   :15              Max.   :16           Max.   :1              
##  NA's   :230             NA's   :230          NA's   :230            
##  white_alone_log1p black_alone_log1p indian_alaska_alone_log1p
##  Min.   : 5        Min.   : 0        Min.   : 0               
##  1st Qu.: 9        1st Qu.: 5        1st Qu.: 3               
##  Median :10        Median : 7        Median : 5               
##  Mean   :10        Mean   : 7        Mean   : 5               
##  3rd Qu.:11        3rd Qu.: 9        3rd Qu.: 6               
##  Max.   :15        Max.   :14        Max.   :11               
##  NA's   :230       NA's   :230       NA's   :230              
##  asian_alone_log1p hawaiian_alone_log1p other_race_alone_log1p
##  Min.   : 0        Min.   : 0           Min.   : 0            
##  1st Qu.: 3        1st Qu.: 0           1st Qu.: 4            
##  Median : 5        Median : 1           Median : 5            
##  Mean   : 5        Mean   : 2           Mean   : 5            
##  3rd Qu.: 7        3rd Qu.: 4           3rd Qu.: 7            
##  Max.   :14        Max.   :11           Max.   :15            
##  NA's   :230       NA's   :230          NA's   :230           
##  two_more_race_log1p two_other_race_log1p two_more_other_race_log1p
##  Min.   : 0          Min.   : 0           Min.   : 0               
##  1st Qu.: 5          1st Qu.: 2           1st Qu.: 5               
##  Median : 6          Median : 4           Median : 6               
##  Mean   : 6          Mean   : 4           Mean   : 6               
##  3rd Qu.: 7          3rd Qu.: 5           3rd Qu.: 7               
##  Max.   :13          Max.   :12           Max.   :13               
##  NA's   :230         NA's   :230          NA's   :230              
##  race_total_log1p race_hhi_log1p poverty_rate_log1p mh_income_usd_log1p
##  Min.   : 5       Min.   :0      Min.   :0          Min.   :10         
##  1st Qu.: 9       1st Qu.:0      1st Qu.:0          1st Qu.:11         
##  Median :10       Median :0      Median :0          Median :11         
##  Mean   :10       Mean   :0      Mean   :0          Mean   :11         
##  3rd Qu.:11       3rd Qu.:0      3rd Qu.:0          3rd Qu.:11         
##  Max.   :16       Max.   :1      Max.   :0          Max.   :12         
##  NA's   :230      NA's   :230    NA's   :573        NA's   :573        
##  urban_rural_log1p county_giving_log1p npo_per1kcapita_all_log1p
##  Min.   :1         Min.   : 0.0        Min.   :0                
##  1st Qu.:1         1st Qu.:10.4        1st Qu.:1                
##  Median :2         Median :13.2        Median :1                
##  Mean   :2         Mean   :11.3        Mean   :1                
##  3rd Qu.:2         3rd Qu.:15.1        3rd Qu.:1                
##  Max.   :2         Max.   :22.6        Max.   :3                
##  NA's   :567                           NA's   :230              
##  npo_per1kcapita_HU_log1p npo_per1kcapita_HE_log1p
##  Min.   :0                Min.   : NA             
##  1st Qu.:1                1st Qu.: NA             
##  Median :1                Median : NA             
##  Mean   :1                Mean   :NaN             
##  3rd Qu.:1                3rd Qu.: NA             
##  Max.   :3                Max.   : NA             
##  NA's   :230              NA's   :19059           
##  county_giving_per1kcapital_log1p
##  Min.   : 0                      
##  1st Qu.: 8                      
##  Median :10                      
##  Mean   : 8                      
##  3rd Qu.:11                      
##  Max.   :16                      
##  NA's   :230
# Q for Ji:  EIN_count_HU in 1000 pop? How was npo_per1kcapita_allcalculated? 

Variable Transformation

# create pct variables for unemployed, bachelor, nonwhite
summary(hs_5yr$unemployed_pct <- hs_5yr$unemployed_int/hs_5yr$total_popu_int*100)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       2       3       3       4      14     230
summary(hs_5yr$bachelor_pct <- hs_5yr$bachelor_degr_int/hs_5yr$total_popu_int*100)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       1      11      14      15      18      62     230
summary(hs_5yr$nonwhite_pct <- 100 - (hs_5yr$white_alone/hs_5yr$total_popu_int*100))
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       5      10      17      23      92     230
# log transformation
hist(hs_5yr$unemployed_pct)

describe(hs_5yr$unemployed_pct)
##    vars     n mean  sd median trimmed mad min max range skew kurtosis   se
## X1    1 18829  3.1 1.5      3       3 1.3   0  14    14  1.3      4.2 0.01
hs_5yr$unemployed_pct1 <- ifelse(hs_5yr$unemployed_pct <= 1, 1, hs_5yr$unemployed_pct)
hs_5yr$unemployed_pct_log1p <- log(hs_5yr$unemployed_pct1)
hist(hs_5yr$unemployed_pct_log1p)

hist(hs_5yr$bachelor_pct)

describe(hs_5yr$bachelor_pct)
##    vars     n mean  sd median trimmed mad min max range skew kurtosis   se
## X1    1 18829   15 6.7     14      14 5.4 0.7  62    62  1.5      3.4 0.05
hs_5yr$bachelor_pct1 <- ifelse(hs_5yr$bachelor_pct <= 1, 1, hs_5yr$bachelor_pct)
hs_5yr$bachelor_pct_log1p <- log(hs_5yr$bachelor_pct1)
hist(hs_5yr$bachelor_pct_log1p)

hist(hs_5yr$nonwhite_pct)

describe(hs_5yr$nonwhite_pct)
##    vars     n mean sd median trimmed mad min max range skew kurtosis   se
## X1    1 18829   17 16     10      14 9.9   0  92    92  1.7      2.6 0.12
hs_5yr$nonwhite_pct1 <- ifelse(hs_5yr$nonwhite_pct <= 1, 1, hs_5yr$nonwhite_pct)
hs_5yr$nonwhite_pct_log1p <- log(hs_5yr$nonwhite_pct1)
hist(hs_5yr$nonwhite_pct_log1p)

hist(hs_5yr$race_hhi)

describe(hs_5yr$race_hhi)
##    vars     n mean   sd median trimmed  mad min max range skew kurtosis se
## X1    1 18829 0.27 0.17   0.23    0.26 0.19   0 0.8   0.8 0.57    -0.81  0
hs_5yr$race_hhi1 <- ifelse(hs_5yr$race_hhi <= 0.1, 0.1, hs_5yr$race_hhi)
hs_5yr$race_hhi_log1p <- log(hs_5yr$race_hhi1)
hist(hs_5yr$race_hhi_log1p)

hist(hs_5yr$gini_income_float)

describe(hs_5yr$gini_income_float)
##    vars     n mean   sd median trimmed  mad  min  max range skew kurtosis se
## X1    1 18829 0.45 0.04   0.44    0.44 0.03 0.32 0.71  0.39 0.56      1.2  0
hs_5yr$gini_log <- log(hs_5yr$gini_income_float) # min = 0.32
hist(hs_5yr$gini_log)

hist(hs_5yr$poverty_rate)

describe(hs_5yr$poverty_rate)
##    vars     n mean   sd median trimmed  mad  min  max range skew kurtosis se
## X1    1 18486 0.16 0.06   0.15    0.15 0.06 0.03 0.57  0.54  1.1        2  0
hs_5yr$poverty_log <- log(hs_5yr$poverty_rate) # min = 0.03
summary(hs_5yr$poverty_log)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##      -4      -2      -2      -2      -2      -1     573
hist(hs_5yr$poverty_log)

Merging Urbanity Data

urbanity <- read.csv("Rural.Urban2013.csv")
urbanity$urban <- ifelse(urbanity$urban_rural <=3, 1, 0)

urbanity$urban <- factor(urbanity$urban, 
                              levels = c(0,1),
                              labels = c("Rural", "Urban"))


hs_5yr$FIPS <- as.numeric(hs_5yr$FIPS)

hs_1yr <- merge(hs_1yr, urbanity[c("FIPS", "urban")], by = "FIPS", all.x = TRUE)
hs_5yr <- merge(hs_5yr, urbanity[c("FIPS", "urban","State")], by = "FIPS", all.x = TRUE)

table(hs_5yr$urban, hs_5yr$year)
##        
##         2014 2015 2016 2017 2018 2019
##   Rural 1950 1950 1950 1947 1948 1945
##   Urban 1134 1133 1134 1134 1134 1133
hs_5yr_urban <- subset(hs_5yr, hs_5yr$urban=="Urban")
hs_5yr_rural <- subset(hs_5yr, hs_5yr$urban=="Rural")

Part 1: Descriptive Analysis

RQ1: What are the dominant trajectories of philanthropic capacity observed over a 6-year time span?

Dependent Variable: County Giving

table(factor(hs_1yr$year))
## 
## 2014 2015 2016 2017 2018 2019 
## 3179 3177 3180 3178 3173 3172
table(factor(hs_5yr$year))
## 
## 2014 2015 2016 2017 2018 2019 
## 3179 3177 3180 3178 3173 3172
summary(hs_5yr$county_giving) # same as 5yr data
##       Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
##          0      32276     518629   16341469    3507468 6677536401
summary(hs_5yr$county_giving_per1kcapital)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
##        0     2179    20329    61607    60217 10055065      230
hist(hs_5yr$county_giving)

hist(hs_5yr$county_giving_log1p)

hist(hs_5yr$county_giving_per1kcapital)

Total County Giving by State (Presentation)

data(fips_codes)
unique(unlist(fips_codes$state_name))
##  [1] "Alabama"                     "Alaska"                     
##  [3] "Arizona"                     "Arkansas"                   
##  [5] "California"                  "Colorado"                   
##  [7] "Connecticut"                 "Delaware"                   
##  [9] "District of Columbia"        "Florida"                    
## [11] "Georgia"                     "Hawaii"                     
## [13] "Idaho"                       "Illinois"                   
## [15] "Indiana"                     "Iowa"                       
## [17] "Kansas"                      "Kentucky"                   
## [19] "Louisiana"                   "Maine"                      
## [21] "Maryland"                    "Massachusetts"              
## [23] "Michigan"                    "Minnesota"                  
## [25] "Mississippi"                 "Missouri"                   
## [27] "Montana"                     "Nebraska"                   
## [29] "Nevada"                      "New Hampshire"              
## [31] "New Jersey"                  "New Mexico"                 
## [33] "New York"                    "North Carolina"             
## [35] "North Dakota"                "Ohio"                       
## [37] "Oklahoma"                    "Oregon"                     
## [39] "Pennsylvania"                "Rhode Island"               
## [41] "South Carolina"              "South Dakota"               
## [43] "Tennessee"                   "Texas"                      
## [45] "Utah"                        "Vermont"                    
## [47] "Virginia"                    "Washington"                 
## [49] "West Virginia"               "Wisconsin"                  
## [51] "Wyoming"                     "American Samoa"             
## [53] "Guam"                        "Northern Mariana Islands"   
## [55] "Puerto Rico"                 "U.S. Minor Outlying Islands"
## [57] "U.S. Virgin Islands"
fips_codes1 <- fips_codes[!duplicated(fips_codes$state_name),]

hs_5yr$state_code <- hs_5yr$state
hs_5yr <- merge(hs_5yr, fips_codes1[c("state_code","state_name")], by = "state_code", all.x = TRUE)

sum <- hs_5yr %>%
  group_by(year, state_name) %>%
  summarise(state_giving = sum(county_giving))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
sum_per1000 <- hs_5yr %>%
  group_by(year, state_name) %>%
  summarise(state_giving = sum(county_giving_per1kcapital))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# aggregate data by state
hs_5yr_2014 <- subset(hs_5yr, hs_5yr$year=="2014") # 3179 obs
hs_5yr_2019 <- subset(hs_5yr, hs_5yr$year=="2019") # 3172 obs

hs_5yr_2014$region <- tolower(hs_5yr_2014$state_name)
unique(unlist(hs_5yr_2014$region))
##  [1] NA                     "alabama"              "alaska"              
##  [4] "arizona"              "arkansas"             "california"          
##  [7] "colorado"             "connecticut"          "delaware"            
## [10] "district of columbia" "florida"              "georgia"             
## [13] "hawaii"               "idaho"                "illinois"            
## [16] "indiana"              "iowa"                 "kansas"              
## [19] "kentucky"             "louisiana"            "maine"               
## [22] "maryland"             "massachusetts"        "michigan"            
## [25] "minnesota"            "mississippi"          "missouri"            
## [28] "montana"              "nebraska"             "nevada"              
## [31] "new hampshire"        "new jersey"           "new mexico"          
## [34] "new york"             "north carolina"       "north dakota"        
## [37] "ohio"                 "oklahoma"             "oregon"              
## [40] "pennsylvania"         "rhode island"         "south carolina"      
## [43] "south dakota"         "tennessee"            "texas"               
## [46] "utah"                 "vermont"              "virginia"            
## [49] "washington"           "west virginia"        "wisconsin"           
## [52] "wyoming"              "puerto rico"
hs_5yr_2019$region <- tolower(hs_5yr_2019$state_name)
unique(unlist(hs_5yr_2019$region))
##  [1] NA                     "alabama"              "alaska"              
##  [4] "arizona"              "arkansas"             "california"          
##  [7] "colorado"             "connecticut"          "delaware"            
## [10] "district of columbia" "florida"              "georgia"             
## [13] "hawaii"               "idaho"                "illinois"            
## [16] "indiana"              "iowa"                 "kansas"              
## [19] "kentucky"             "louisiana"            "maine"               
## [22] "maryland"             "massachusetts"        "michigan"            
## [25] "minnesota"            "mississippi"          "missouri"            
## [28] "montana"              "nebraska"             "nevada"              
## [31] "new hampshire"        "new jersey"           "new mexico"          
## [34] "new york"             "north carolina"       "north dakota"        
## [37] "ohio"                 "oklahoma"             "oregon"              
## [40] "pennsylvania"         "rhode island"         "south carolina"      
## [43] "south dakota"         "tennessee"            "texas"               
## [46] "utah"                 "vermont"              "virginia"            
## [49] "washington"           "west virginia"        "wisconsin"           
## [52] "wyoming"              "puerto rico"
map_2014 <- hs_5yr_2014 %>%
  select(county_giving_per1kcapital, region) %>%
  group_by(region) %>%
  summarise(value = sum(county_giving_per1kcapital)/1000000)

# create the map
state_choropleth(map_2014, 
                 num_colors=9) +
  scale_fill_brewer(palette="YlOrBr") +
  labs(title = "Total State Giving per 1,000 population",
       subtitle = "Year: 2014",
       fill = "Dollors in million") 
## Warning in super$initialize(map.df, user.df): Your data.frame contains the
## following regions which are not mappable: puerto rico, NA
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.

ggsave("map_2014.jpg", width = 7, height = 7)


# 2019
map_2019 <- hs_5yr_2019 %>%
  select(county_giving_per1kcapital, region) %>%
  group_by(region) %>%
  summarise(value = sum(county_giving_per1kcapital)/1000000)

# create the map
state_choropleth(map_2019, 
                 num_colors=9) +
  scale_fill_brewer(palette="BuPu") +
  labs(title = "Total State Giving per 1,000 population",
       subtitle = "Year: 2019",
       fill = "Dollors in million") 
## Warning in super$initialize(map.df, user.df): Your data.frame contains the
## following regions which are not mappable: puerto rico, NA
## Scale for 'fill' is already present. Adding another scale for 'fill', which
## will replace the existing scale.

ggsave("map_2019.jpg", width = 7, height = 7)

Total County Giving by Year (Presentation)

# Scatterplot by year
hs_year <- hs_5yr[!is.na(hs_5yr$county_giving_per1kcapital),] %>%
  select(year, county_giving_per1kcapital, FIPS) %>%
  group_by(year) %>%
  summarise(year_giving = sum(county_giving_per1kcapital)/1000000)

plot <- ggplot(hs_year, aes(x=year, y=year_giving)) + geom_point() +
  stat_smooth(method="lm", se=TRUE,colour="darkred", size=0.5) +
  labs(title = "Total County Giving by Year, 2014-2019",
       x = "Year", y = "Total County Giving (in million)") +
  theme_pubclean(base_size = 10, base_family = "sans") 
plot
## `geom_smooth()` using formula 'y ~ x'

ggsave("plot_giving_year.jpg", width = 7, height = 4)
## `geom_smooth()` using formula 'y ~ x'
# Boxplot of County Giving by Year
boxplot_year <- ggboxplot(hs_5yr, x = "year", y = "county_giving_per1kcapital", 
          color = "year", 
          ylab = "County Giving", xlab = "Year")
boxplot_year
## Warning: Removed 230 rows containing non-finite values (stat_boxplot).

boxplot_urban <- ggboxplot(hs_5yr, x = "urban", y = "county_giving_per1kcapital", 
          color = "year", 
          ylab = "County Giving", xlab = "Urbanity")
boxplot_urban
## Warning: Removed 230 rows containing non-finite values (stat_boxplot).

County Giving by Year, County and Urbanity

hs_small <- hs_5yr %>%
  select(year, county_giving, FIPS, urban) %>%
  group_by(year, FIPS)

hs_small <- subset(hs_small, !is.na(hs_small$urban))

p <- ggplot(data = hs_small, aes(x = year, y = county_giving, group = FIPS, color = year)) + geom_line()
p + geom_line() + facet_grid(. ~ urban) +
  theme_minimal()

County Giving by year, urbanity (Presentation)

hs_year_urban <- hs_5yr[!is.na(hs_5yr$county_giving_per1kcapital),] %>%
  select(year, county_giving_per1kcapital, urban) %>%
  group_by(urban, year) %>%
  summarise(year_giving = sum(county_giving_per1kcapital)/1000000)

hs_year_urban <- subset(hs_year_urban, !is.na(hs_year_urban$urban))

p1 <- ggplot(data = hs_year_urban, aes(x = year, y = year_giving, group = urban, color = urban)) + 
  geom_line() +
    labs(title = "Total County Giving by Year and Urbanity, 2014-2019",
       x = "Year", y = "Total County Giving (in million)") +
  theme_pubclean(base_size = 10, base_family = "sans") 
p1 + geom_line() +  coord_cartesian(ylim = c(70,120)) +
  geom_text(aes(label= as.character(round(year_giving),2)),hjust=0,vjust=-1)

ggsave("plot_giving_year_urban.jpg", width = 7, height = 5)

County Giving by Year and Race (5yr est)

We notice a consistent postive relationship between race hhi and county giving across the years.

summary(hs_1yr$race_hhi) # 14422 NAs -> yse 5yr
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       1   14422
summary(hs_5yr$race_hhi) # 230 NAs
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       1     230
summary(hs_5yr$race_hhi)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       0       0       0       0       1     230
plot_race <- ggplot(hs_5yr, aes(x=race_hhi, y= (county_giving_per1kcapital)/1000000, color = race_hhi)) + geom_point() +
   stat_smooth(span = 0.5, colour = "black", method="lm", se=FALSE) + 
  theme_pubclean()  + theme(legend.position = "none") +
  labs(title = "Total County Giving and Race HHI",
       x = "Race HHI", y = "Total County Giving (in million)") 
plot_race

ggsave("plot_race.jpg", width = 7, height = 5)


plot_nonwhite <- ggplot(hs_5yr, aes(x=nonwhite_pct, y= (county_giving_per1kcapital)/1000000, color = nonwhite_pct)) + geom_point() +
   stat_smooth(span = 0.5, colour = "black", method="lm", se=FALSE) +  theme_pubclean() 
plot_nonwhite

ggsave("plot_nonwhite.jpg", width = 7, height = 5)


# by year and race measures

plot_race_yr <- ggplot(hs_5yr, aes(x=race_hhi, y= (county_giving_per1kcapital)/1000000, color = year)) + geom_point() +
   stat_smooth(span = 0.5, colour = "black", method="lm", se=FALSE) +  
      labs(title = "Total County Giving by Year and Race HHI, 2014-2019",
       x = "Year", y = "Total County Giving (in million)") + 
  theme_pubclean(base_size = 10, base_family = "sans") + theme(legend.position = "none") + facet_grid(. ~ year) 
plot_race_yr

ggsave("plot_race_year.jpg", width = 7, height = 5)

summary(hs_5yr$nonwhite_pct)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##       0       5      10      17      23      92     230
plot_nonwhite_yr <- ggplot(hs_5yr, aes(x=nonwhite_pct, y= (county_giving_per1kcapital)/1000000, color = year)) + geom_point() +
  stat_smooth(span = 0.5, colour = "black", method="lm", se=FALSE) +  theme_minimal() + facet_grid(. ~ year) 
plot_nonwhite_yr

Summary Statistics

Summary Statistics
Statistic N Mean St. Dev. Min Pctl(25) Median Pctl(75) Max
county_giving 19,059 16,341,469.000 114,601,455.000 0 32,276.0 518,629 3,507,468 6,677,536,401
GvrnmntGrntsAmt 19,059 15,594,761.000 103,874,096.000 0 0 487,606 4,617,548 4,873,851,024
TtlPrgrmSrvcRvnAmt 19,059 48,713,719.000 257,488,899.000 -229,109 90,447 1,583,555 13,246,322 8,003,958,358
TtlFnctnlExpnss_FndrsngAmt 19,059 1,200,143.000 8,762,056.000 -120,361 0 10,132 207,700.0 385,501,706
TtlAssts_EOYAmt 19,059 139,070,379.000 741,085,420.000 -88,626 670,936.0 5,780,763 36,010,289 21,151,470,598
npo_per1kcapita_all 18,829 1.500 1.100 0.012 0.850 1.300 1.900 14.000
mh_income_usd 18,486 50,746.000 13,393.000 21,658 41,798 48,759 56,741.0 151,806
poverty_rate 18,486 0.160 0.062 0.026 0.110 0.150 0.190 0.570
gini_income_float 18,829 0.440 0.036 0.320 0.420 0.440 0.470 0.710
unemployed_pct 18,829 3.100 1.500 0.000 2.200 3.000 3.900 14.000
bachelor_pct 18,829 15.000 6.700 0.700 11.000 14.000 18.000 62.000
race_hhi 18,829 0.270 0.170 0.000 0.120 0.230 0.410 0.800
nonwhite_pct 18,829 17.000 16.000 0.000 4.700 10.000 23.000 92.000
total_popu_int 18,829 101,519.000 326,155.000 228 11,295 26,297 66,972 10,105,722
Summary Statistics for Urban Counties
Statistic N Mean St. Dev. Min Median Max
county_giving 6,802 42,447,403.000 188,368,817.000 0 4,157,605 6,677,536,401
GvrnmntGrntsAmt 6,802 39,497,712.000 170,768,223.000 0 4,259,406.0 4,873,851,024
TtlPrgrmSrvcRvnAmt 6,802 125,850,624.000 418,923,097.000 0 14,388,168 8,003,958,358
TtlFnctnlExpnss_FndrsngAmt 6,802 3,099,808.000 14,367,947.000 -120,361 247,300.0 385,501,706
TtlAssts_EOYAmt 6,802 359,973,778.000 1,206,203,684.000 -86,345 41,721,525 21,151,470,598
npo_per1kcapita_all 6,801 1.200 0.560 0.059 1.100 6.300
mh_income_usd 6,801 58,180.000 15,313.000 30,241 55,299 151,806
poverty_rate 6,801 0.140 0.052 0.026 0.130 0.400
gini_income_float 6,801 0.440 0.034 0.340 0.440 0.600
unemployed_pct 6,801 3.300 1.200 0.460 3.100 8.300
bachelor_pct 6,801 19.000 7.700 4.700 17.000 62.000
race_hhi 6,801 0.320 0.170 0.011 0.300 0.790
nonwhite_pct 6,801 19.000 15.000 0.410 14.000 87.000
total_popu_int 6,801 237,900.000 514,185.000 724 98,320 10,105,722
Summary Statistics for Rural Counties
Statistic N Mean St. Dev. Min Median Max
county_giving 11,690 1,373,573.000 6,518,508.000 0 207,290 305,191,328
GvrnmntGrntsAmt 11,690 2,053,912.000 6,666,152.000 0 189,451.0 180,333,472
TtlPrgrmSrvcRvnAmt 11,690 5,015,779.000 13,208,750.000 -229,109 613,341 279,006,315
TtlFnctnlExpnss_FndrsngAmt 11,690 108,299.000 1,056,994.000 -5,776 0 51,195,479
TtlAssts_EOYAmt 11,690 13,629,055.000 33,373,585.000 -88,626 2,661,670.0 683,460,399
npo_per1kcapita_all 11,683 1.800 1.200 0.070 1.500 14.000
mh_income_usd 11,685 46,419.000 9,818.000 21,658 45,718 124,947
poverty_rate 11,685 0.170 0.065 0.035 0.150 0.570
gini_income_float 11,683 0.440 0.036 0.320 0.440 0.710
unemployed_pct 11,683 3.000 1.500 0.000 2.800 14.000
bachelor_pct 11,683 13.000 5.300 0.700 13.000 53.000
race_hhi 11,683 0.240 0.160 0.000 0.180 0.800
nonwhite_pct 11,683 15.000 17.000 0.000 7.500 92.000
total_popu_int 11,683 23,572.000 22,103.000 228 16,723 199,459

Correlation

Correlation Matrix
county_giving GvrnmntGrntsAmt TtlAssts_EOYAmt TtlPrgrmSrvcRvnAmt TtlFnctnlExpnss_FndrsngAmt race_hhi poverty_rate mh_income_usd unemployed_pct bachelor_pct nonwhite_pct total_popu_int
county_giving 1 0.690 0.860 0.830 0.860 0.190 -0.039 0.170 0.058 0.260 0.150 0.640
GvrnmntGrntsAmt 0.690 1 0.810 0.740 0.700 0.200 -0.030 0.160 0.071 0.240 0.150 0.790
TtlAssts_EOYAmt 0.860 0.810 1 0.950 0.900 0.230 -0.072 0.240 0.062 0.350 0.170 0.710
TtlPrgrmSrvcRvnAmt 0.830 0.740 0.950 1 0.890 0.220 -0.075 0.240 0.066 0.350 0.160 0.660
TtlFnctnlExpnss_FndrsngAmt 0.860 0.700 0.900 0.890 1 0.190 -0.038 0.180 0.058 0.280 0.150 0.540
race_hhi 0.190 0.200 0.230 0.220 0.190 1 0.340 -0.014 0.350 0.056 0.870 0.290
poverty_rate -0.039 -0.030 -0.072 -0.075 -0.038 0.340 1 -0.780 0.480 -0.520 0.500 -0.088
mh_income_usd 0.170 0.160 0.240 0.240 0.180 -0.014 -0.780 1 -0.320 0.700 -0.150 0.260
unemployed_pct 0.058 0.071 0.062 0.066 0.058 0.350 0.480 -0.320 1 -0.180 0.420 0.110
bachelor_pct 0.260 0.240 0.350 0.350 0.280 0.056 -0.520 0.700 -0.180 1 -0.059 0.320
nonwhite_pct 0.150 0.150 0.170 0.160 0.150 0.870 0.500 -0.150 0.420 -0.059 1 0.200
total_popu_int 0.640 0.790 0.710 0.660 0.540 0.290 -0.088 0.260 0.110 0.320 0.200 1

Part 2: Regression Analysis

lm1: Linear Regression + Time Dummies

attach(hs_5yr)
## The following object is masked from package:usdata:
## 
##     county
lm1 <- lm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all + 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p +
                                  race_hhi_log1p + 
                                  total_popu_int_log1p + factor(year), data = hs_5yr)

summary(lm1)
vif(lm1)
##                                  GVIF Df GVIF^(1/(2*Df))
## GvrnmntGrntsAmt_log1p             3.1  1             1.8
## TtlPrgrmSrvcRvnAmt_log1p          6.0  1             2.4
## TtlFnctnlExpnss_FndrsngAmt_log1p  3.1  1             1.8
## TtlAssts_EOYAmt_log1p             6.3  1             2.5
## npo_per1kcapita_all               1.8  1             1.3
## mh_income_usd_log1p               8.4  1             2.9
## poverty_log                       8.9  1             3.0
## gini_log                          1.7  1             1.3
## unemployed_pct_log1p              1.9  1             1.4
## bachelor_pct_log1p                2.8  1             1.7
## race_hhi_log1p                    1.7  1             1.3
## total_popu_int_log1p              4.7  1             2.2
## factor(year)                      1.3  5             1.0
# using ggplot and ggfortify for residual plots
autoplot(lm1, which = 1:6, ncol = 3, label.size = 3)

lm2: Panel Regression with Variable Transformation + County and Time Fixed Effects

Further reading on state vs. county fixed effects: https://www.statalist.org/forums/forum/general-stata-discussion/general/1564591-panel-data-county-level-data-but-state-level-intercept

# can only do FIPS county level fixed effects 

is.pbalanced(hs_5yr)  # FALSE since same state for multiple FIPS
## Warning in pdata.frame(x, index): duplicate couples (id-time) in resulting pdata.frame
##  to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
hs_5yr$year <- factor(hs_5yr$year)
lm2 <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + race_hhi_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr)

summary(lm2)

lm2_urban <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + race_hhi_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_urban)

summary(lm2_urban)


lm2_rural <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + race_hhi_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_rural)

summary(lm2_rural)

lm3: Panel Regression with County and Time Fixed Effects + Nonwhite Covariates

lm3 <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + nonwhite_pct_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr)

summary(lm3)

lm3_urban <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + nonwhite_pct_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_urban)

summary(lm3_urban)


lm3_rural <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + nonwhite_pct_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_rural)

summary(lm3_rural)

lm4: Panel Regression with County and Time Fixed Effects using 2014 and 2019 Data

# the set of observations on all variables for 2014 and 2019 for the last model
hs_5yr_2014_2019 <- hs_5yr[with(hs_5yr, year == 2014 | year == 2019), ]

lm4 <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + race_hhi_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                       data = hs_5yr_2014_2019)
summary(lm4)

lm4_nonwhite <- plm(county_giving_per1kcapital_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  mh_income_usd_log1p + poverty_log + gini_log +
                                  unemployed_pct_log1p + bachelor_pct_log1p + nonwhite_pct_log1p + 
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                       data = hs_5yr_2014_2019)
summary(lm4_nonwhite)

Regression table

Panel Regression Models of County Giving
Dependent Variable: County Giving
county_giving_per1kcapital_log1p
OLS panel
linear
OLS HS Panel HS Urban Rural NonWhite NWUrban NWRural 2014&2019 NW 2014&2019
(1) (2) (3) (4) (5) (6) (7) (8) (9)
GvrnmntGrntsAmt_log1p 0.034*** 0.024* 0.008 0.027* 0.024* 0.008 0.026* 0.044** 0.044**
(0.006) (0.012) (0.023) (0.013) (0.012) (0.023) (0.013) (0.017) (0.017)
TtlPrgrmSrvcRvnAmt_log1p -0.074*** -0.023 -0.027 -0.023 -0.023 -0.027 -0.023 -0.023 -0.023
(0.009) (0.018) (0.034) (0.021) (0.018) (0.034) (0.021) (0.025) (0.025)
TtlFnctnlExpnss_FndrsngAmt_log1p 0.170*** 0.110*** 0.120*** 0.110*** 0.110*** 0.120*** 0.110*** 0.130*** 0.130***
(0.005) (0.009) (0.018) (0.011) (0.009) (0.018) (0.011) (0.013) (0.013)
TtlAssts_EOYAmt_log1p 0.590*** 0.500*** 0.470*** 0.500*** 0.500*** 0.470*** 0.500*** 0.470*** 0.470***
(0.009) (0.022) (0.046) (0.025) (0.022) (0.046) (0.025) (0.029) (0.029)
npo_per1kcapita_all 0.150*** 0.180** 0.150 0.190** 0.180** 0.140 0.180** 0.270** 0.260**
(0.020) (0.059) (0.180) (0.062) (0.059) (0.180) (0.062) (0.096) (0.094)
mh_income_usd_log1p -0.310 0.140 0.930* -0.190 0.150 0.950* -0.180 0.920 1.000
(0.200) (0.290) (0.370) (0.380) (0.290) (0.370) (0.380) (0.640) (0.650)
poverty_log -0.470*** -0.200 0.096 -0.390+ -0.200 0.100 -0.390+ 0.036 0.040
(0.120) (0.140) (0.160) (0.200) (0.140) (0.160) (0.200) (0.330) (0.330)
gini_log 1.200*** 0.660 0.470 0.680 0.660 0.480 0.670 1.900** 1.900**
(0.280) (0.430) (1.200) (0.460) (0.430) (1.200) (0.460) (0.610) (0.620)
unemployed_pct_log1p 0.130* -0.120 0.042 -0.160+ -0.120 0.047 -0.160+ -0.058 -0.056
(0.052) (0.085) (0.180) (0.097) (0.086) (0.180) (0.097) (0.130) (0.130)
bachelor_pct_log1p -0.140* -0.063 0.420 -0.120 -0.070 0.420 -0.130 -0.190 -0.220
(0.060) (0.260) (0.710) (0.280) (0.260) (0.720) (0.280) (0.410) (0.400)
race_hhi_log1p -0.066* 0.370* 0.450 0.340+ 0.790**
(0.033) (0.170) (0.350) (0.190) (0.250)
nonwhite_pct_log1p 0.170* 0.190 0.160+ 0.360*
(0.085) (0.230) (0.092) (0.150)
total_popu_int_log1p -0.360*** -0.550 -1.300 0.130 -0.450 -1.100 0.230 -0.800 -0.590
(0.024) (0.640) (0.820) (0.970) (0.640) (0.830) (0.960) (0.750) (0.740)
factor(year)2015 0.072
(0.049)
factor(year)2016 0.069
(0.050)
factor(year)2017 0.110*
(0.052)
factor(year)2018 0.140*
(0.055)
factor(year)2019 0.200***
(0.057)
Constant 6.500***
(1.900)
Observations 18,467 18,467 6,797 11,670 18,467 6,797 11,670 6,156 6,156
R2 0.780 0.410 0.370 0.430 0.410 0.370 0.430 0.440 0.440
Adjusted R2 0.780 0.300 0.240 0.310 0.300 0.240 0.310 -0.120 -0.130
Note: (+ p<0.1; * p<0.05; ** p<0.01; *** p<0.001)

Export data

write.csv(hs_5yr, "hs_5yr.csv")
write.csv(hs_5yr_urban, "hs_5yr_urban.csv")
write.csv(hs_5yr_rural, "hs_5yr_rural.csv")

Appendix 1: Social Vulnerability Index Data (2014, 2016, 2018 only)

See data and documentation here: https://www.atsdr.cdc.gov/placeandhealth/svi/data_documentation_download.html

  1. RPL_THEME1: Socioeconomic Status
  • Below Poverty, Unemployed, Income, No High School Diploma
  1. RPL_THEME2: Household Composition & Disability
  • Aged 65 or Older, Aged 17 or Younger, Civilian with a Disability, Single-Parent Households
  1. RPL_THEME3: Minority Status & Language
  • Minority, Speaks English “Less than Well”
  1. RPL_THEME4: Housing Type & Transportation
  • Multi-Unit Structures, Mobile Homes, Crowding, No Vehicle, Group Quarters

Import SVI data

svi_18 <- read.csv("SVI2018_US_COUNTY.csv")
svi_18$year <- 2018
svi_18$RPL_THEMES <- ifelse(svi_18$RPL_THEMES == "-999", NA, svi_18$RPL_THEMES)

svi_18 <- svi_18[,c("FIPS", "year", "RPL_THEME1", "RPL_THEME2", "RPL_THEME3",
                                  "RPL_THEME4", "RPL_THEMES")]

svi_16 <- read.csv("SVI2016_US_COUNTY.csv")
svi_16$year <- 2016
svi_16 <- svi_16[,c("FIPS", "year", "RPL_THEME1", "RPL_THEME2", "RPL_THEME3",
                                  "RPL_THEME4", "RPL_THEMES")]

svi_14 <- read.csv("SVI2014_US_COUNTY.csv")
svi_14$year <- 2014
svi_14 <- svi_14[,c("FIPS", "year", "RPL_THEME1", "RPL_THEME2", "RPL_THEME3",
                                  "RPL_THEME4", "RPL_THEMES")]

# combine rows
svi <- bind_rows(svi_18, svi_16, svi_14)

# merge with hs_5yr data
hs_5yr_svi <- merge(hs_5yr, svi[c("FIPS", "year", "RPL_THEME1", "RPL_THEME2", "RPL_THEME3",
                                  "RPL_THEME4", "RPL_THEMES")],
                    by = c("FIPS", "year"), all.x = TRUE)


# create urban and rural panels

hs_5yr_svi_urban <- subset(hs_5yr_svi, hs_5yr_svi$urban=="Urban")
hs_5yr_svi_rural <- subset(hs_5yr_svi, hs_5yr_svi$urban=="Rural")


describe(hs_5yr_svi$RPL_THEMES)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis se
## X1    1 9246  0.5 0.29    0.5     0.5 0.37   0   1     1    0     -1.2  0
describe(hs_5yr_svi$RPL_THEME1)
##    vars    n mean sd median trimmed  mad  min max range skew kurtosis   se
## X1    1 9247 0.39 10    0.5     0.5 0.37 -999   1  1000  -96     9226 0.11
describe(hs_5yr_svi$RPL_THEME2)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis se
## X1    1 9247  0.5 0.29    0.5     0.5 0.37   0   1     1    0     -1.2  0
describe(hs_5yr_svi$RPL_THEME3)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis se
## X1    1 9247  0.5 0.29   0.49     0.5 0.37   0   1     1 0.02     -1.2  0
describe(hs_5yr_svi$RPL_THEME4)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis se
## X1    1 9247  0.5 0.29    0.5     0.5 0.37   0   1     1 0.01     -1.2  0
svi1 <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ RPL_THEMES +                     
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi)

summary(svi1)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEMES + total_popu_int_log1p, 
##     data = hs_5yr_svi, effect = "twoways", model = "within", 
##     index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 3085, T = 1-3, N = 9236
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -9.16348 -0.20427 -0.00785  0.20607 12.00151 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p             0.02994    0.00859    3.49
## TtlPrgrmSrvcRvnAmt_log1p         -0.02095    0.01187   -1.77
## TtlFnctnlExpnss_FndrsngAmt_log1p  0.14784    0.00978   15.12
## TtlAssts_EOYAmt_log1p             0.59679    0.01315   45.39
## npo_per1kcapita_all               0.21743    0.06934    3.14
## RPL_THEMES                        0.06999    0.37261    0.19
## total_popu_int_log1p              0.88412    0.93551    0.95
##                                              Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                         0.00049 ***
## TtlPrgrmSrvcRvnAmt_log1p                      0.07744 .  
## TtlFnctnlExpnss_FndrsngAmt_log1p < 0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            < 0.0000000000000002 ***
## npo_per1kcapita_all                           0.00172 ** 
## RPL_THEMES                                    0.85101    
## total_popu_int_log1p                          0.34466    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    23800
## Residual Sum of Squares: 14100
## R-Squared:      0.408
## Adj. R-Squared: 0.11
## F-statistic: 604.842 on 7 and 6142 DF, p-value: <0.0000000000000002
svi1_urban <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ RPL_THEMES +                     
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi_urban)

summary(svi1_urban)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEMES + total_popu_int_log1p, 
##     data = hs_5yr_svi_urban, effect = "twoways", model = "within", 
##     index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 1134, T = 1-3, N = 3399
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -8.22362 -0.15175 -0.00742  0.14580 11.85909 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p             -0.0146     0.0156   -0.94
## TtlPrgrmSrvcRvnAmt_log1p          -0.0489     0.0201   -2.43
## TtlFnctnlExpnss_FndrsngAmt_log1p   0.1543     0.0147   10.51
## TtlAssts_EOYAmt_log1p              0.6147     0.0226   27.16
## npo_per1kcapita_all                0.0573     0.1947    0.29
## RPL_THEMES                         0.1207     0.6329    0.19
## total_popu_int_log1p              -1.6874     1.2747   -1.32
##                                             Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                          0.349    
## TtlPrgrmSrvcRvnAmt_log1p                       0.015 *  
## TtlFnctnlExpnss_FndrsngAmt_log1p <0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            <0.0000000000000002 ***
## npo_per1kcapita_all                            0.769    
## RPL_THEMES                                     0.849    
## total_popu_int_log1p                           0.186    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    4900
## Residual Sum of Squares: 3090
## R-Squared:      0.369
## Adj. R-Squared: 0.049
## F-statistic: 188.181 on 7 and 2256 DF, p-value: <0.0000000000000002
svi1_rural <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ RPL_THEMES +                     
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi_rural)

summary(svi1_rural)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEMES + total_popu_int_log1p, 
##     data = hs_5yr_svi_rural, effect = "twoways", model = "within", 
##     index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 1951, T = 1-3, N = 5837
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -9.1471 -0.2641 -0.0108  0.2638  9.3360 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p              0.0392     0.0106    3.71
## TtlPrgrmSrvcRvnAmt_log1p          -0.0154     0.0148   -1.04
## TtlFnctnlExpnss_FndrsngAmt_log1p   0.1469     0.0127   11.56
## TtlAssts_EOYAmt_log1p              0.5913     0.0164   36.15
## npo_per1kcapita_all                0.2347     0.0804    2.92
## RPL_THEMES                         0.0212     0.4662    0.05
## total_popu_int_log1p               2.2752     1.3988    1.63
##                                              Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                         0.00021 ***
## TtlPrgrmSrvcRvnAmt_log1p                      0.29993    
## TtlFnctnlExpnss_FndrsngAmt_log1p < 0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            < 0.0000000000000002 ***
## npo_per1kcapita_all                           0.00352 ** 
## RPL_THEMES                                    0.96380    
## total_popu_int_log1p                          0.10392    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    18900
## Residual Sum of Squares: 11000
## R-Squared:      0.42
## Adj. R-Squared: 0.126
## F-statistic: 400.347 on 7 and 3877 DF, p-value: <0.0000000000000002
svi2 <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + RPL_THEME4 +
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi)

summary(svi2)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + 
##     RPL_THEME4 + total_popu_int_log1p, data = hs_5yr_svi, effect = "twoways", 
##     model = "within", index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 3085, T = 1-3, N = 9236
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -9.19579 -0.20483 -0.00672  0.20654 12.04017 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p             0.02962    0.00859    3.45
## TtlPrgrmSrvcRvnAmt_log1p         -0.02103    0.01187   -1.77
## TtlFnctnlExpnss_FndrsngAmt_log1p  0.14764    0.00978   15.09
## TtlAssts_EOYAmt_log1p             0.59748    0.01316   45.41
## npo_per1kcapita_all               0.21925    0.06936    3.16
## RPL_THEME1                       -0.31176    0.36494   -0.85
## RPL_THEME2                        0.30691    0.20709    1.48
## RPL_THEME3                        0.06029    0.36822    0.16
## RPL_THEME4                       -0.02982    0.25398   -0.12
## total_popu_int_log1p              0.88457    0.94203    0.94
##                                              Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                         0.00057 ***
## TtlPrgrmSrvcRvnAmt_log1p                      0.07640 .  
## TtlFnctnlExpnss_FndrsngAmt_log1p < 0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            < 0.0000000000000002 ***
## npo_per1kcapita_all                           0.00158 ** 
## RPL_THEME1                                    0.39299    
## RPL_THEME2                                    0.13839    
## RPL_THEME3                                    0.86994    
## RPL_THEME4                                    0.90655    
## total_popu_int_log1p                          0.34777    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    23800
## Residual Sum of Squares: 14100
## R-Squared:      0.408
## Adj. R-Squared: 0.11
## F-statistic: 423.623 on 10 and 6139 DF, p-value: <0.0000000000000002
svi2_urban <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + RPL_THEME4 +
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi_urban)

summary(svi2_urban)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + 
##     RPL_THEME4 + total_popu_int_log1p, data = hs_5yr_svi_urban, 
##     effect = "twoways", model = "within", index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 1134, T = 1-3, N = 3399
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -8.1968 -0.1555 -0.0079  0.1488 11.8458 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p             -0.0132     0.0156   -0.85
## TtlPrgrmSrvcRvnAmt_log1p          -0.0473     0.0201   -2.35
## TtlFnctnlExpnss_FndrsngAmt_log1p   0.1535     0.0147   10.46
## TtlAssts_EOYAmt_log1p              0.6140     0.0226   27.14
## npo_per1kcapita_all                0.0872     0.1951    0.45
## RPL_THEME1                        -0.2758     0.5800   -0.48
## RPL_THEME2                         0.2985     0.3489    0.86
## RPL_THEME3                         1.2675     0.6149    2.06
## RPL_THEME4                        -0.2972     0.4402   -0.68
## total_popu_int_log1p              -1.9279     1.2803   -1.51
##                                             Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                          0.396    
## TtlPrgrmSrvcRvnAmt_log1p                       0.019 *  
## TtlFnctnlExpnss_FndrsngAmt_log1p <0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            <0.0000000000000002 ***
## npo_per1kcapita_all                            0.655    
## RPL_THEME1                                     0.634    
## RPL_THEME2                                     0.392    
## RPL_THEME3                                     0.039 *  
## RPL_THEME4                                     0.500    
## total_popu_int_log1p                           0.132    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    4900
## Residual Sum of Squares: 3080
## R-Squared:      0.37
## Adj. R-Squared: 0.05
## F-statistic: 132.383 on 10 and 2253 DF, p-value: <0.0000000000000002
svi2_rural <- plm(county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p +
                                  TtlFnctnlExpnss_FndrsngAmt_log1p +
                                  TtlAssts_EOYAmt_log1p + npo_per1kcapita_all+ 
                                  RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + RPL_THEME4 +
                                  total_popu_int_log1p,
                                  index = c("FIPS","year"),
                                  model = "within",
                                  effect = "twoways", 
                                  data = hs_5yr_svi_rural)

summary(svi2_rural)
## Twoways effects Within Model
## 
## Call:
## plm(formula = county_giving_log1p ~ GvrnmntGrntsAmt_log1p + TtlPrgrmSrvcRvnAmt_log1p + 
##     TtlFnctnlExpnss_FndrsngAmt_log1p + TtlAssts_EOYAmt_log1p + 
##     npo_per1kcapita_all + RPL_THEME1 + RPL_THEME2 + RPL_THEME3 + 
##     RPL_THEME4 + total_popu_int_log1p, data = hs_5yr_svi_rural, 
##     effect = "twoways", model = "within", index = c("FIPS", "year"))
## 
## Unbalanced Panel: n = 1951, T = 1-3, N = 5837
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -9.18834 -0.26682 -0.00828  0.25978  9.35941 
## 
## Coefficients:
##                                  Estimate Std. Error t-value
## GvrnmntGrntsAmt_log1p              0.0388     0.0106    3.67
## TtlPrgrmSrvcRvnAmt_log1p          -0.0156     0.0148   -1.05
## TtlFnctnlExpnss_FndrsngAmt_log1p   0.1469     0.0127   11.56
## TtlAssts_EOYAmt_log1p              0.5924     0.0164   36.17
## npo_per1kcapita_all                0.2390     0.0804    2.97
## RPL_THEME1                        -0.2978     0.4658   -0.64
## RPL_THEME2                         0.3155     0.2591    1.22
## RPL_THEME3                        -0.3453     0.4637   -0.74
## RPL_THEME4                         0.0245     0.3157    0.08
## total_popu_int_log1p               2.4678     1.4112    1.75
##                                              Pr(>|t|)    
## GvrnmntGrntsAmt_log1p                         0.00025 ***
## TtlPrgrmSrvcRvnAmt_log1p                      0.29244    
## TtlFnctnlExpnss_FndrsngAmt_log1p < 0.0000000000000002 ***
## TtlAssts_EOYAmt_log1p            < 0.0000000000000002 ***
## npo_per1kcapita_all                           0.00298 ** 
## RPL_THEME1                                    0.52266    
## RPL_THEME2                                    0.22347    
## RPL_THEME3                                    0.45656    
## RPL_THEME4                                    0.93811    
## total_popu_int_log1p                          0.08041 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    18900
## Residual Sum of Squares: 11000
## R-Squared:      0.42
## Adj. R-Squared: 0.126
## F-statistic: 280.441 on 10 and 3874 DF, p-value: <0.0000000000000002
rob_se1 <- list(
  sqrt(diag(vcovHC(svi1, type="HC1"))),
  sqrt(diag(vcovHC(svi1_urban, type="HC1"))),
  sqrt(diag(vcovHC(svi1_rural, type="HC1"))),
  sqrt(diag(vcovHC(svi2, type="HC1"))),
  sqrt(diag(vcovHC(svi2_urban, type="HC1"))),
  sqrt(diag(vcovHC(svi2_rural, type="HC1")))
)