The data to use in this set of exercises includes the PPP loans, the industry codes and some Census data that I pulled and categorized at the zip code level. When joining, be careful to join the census_zip column, not the borrwer_zip column - they’re slightly different.
ppp_loans <- readRDS( url ( "https://cronkitedata.s3.amazonaws.com/rdata/ppp_az_loans.RDS" ))
industries <- readRDS (url ( "https://cronkitedata.s3.amazonaws.com/rdata/naics_lookup.RDS" ))
The Census dataset includes information from the 2015-2019 American Community Survey by “ZCTA”, which is a Zip Code Tabulation Area. It has, added to it, the estimated number of businesses derived from US Postal Service addresses.
census <- readRDS ( url ( "https://cronkitedata.s3.amazonaws.com/rdata/az_zipcodes.RDS" ))
ppp_industry <- ppp_loans %>%
left_join ( industries, by=c("naics_code" = "naics_code"))
glimpse(ppp_industry)
## Rows: 169,268
## Columns: 29
## $ loan_id <dbl> 2008847101, 3057347105, 3470877104, 3530847305, 377…
## $ date_approved <date> 2020-04-10, 2020-04-11, 2020-04-11, 2020-04-29, 20…
## $ draw <chr> "First", "First", "First", "First", "First", "First…
## $ borrower_name <chr> "SFE HOLDINGS LLC", "NAVAJO TRIBAL UTILITY AUTHORIT…
## $ borrower_address <chr> "9366 East Raintree Drive", "Po Box 170", "2999 N44…
## $ borrower_city <chr> "Scottsdale", "Fort Defiance", "Phoenix", "Tucson",…
## $ borrower_state <chr> "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ…
## $ borrower_zip <chr> "85260", "86504", "85018", "85711", "85250", "85012…
## $ franchise_name <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ loan_status <chr> "Paid in Full", "Exemption 4", "Paid in Full", "Exe…
## $ loan_status_date <date> 2021-08-17, NA, 2021-09-25, NA, 2021-08-07, NA, 20…
## $ amount <dbl> 10000000, 10000000, 10000000, 10000000, 10000000, 1…
## $ forgiveness_amount <dbl> 10108219, NA, 10133389, 10131667, 10126027, NA, 101…
## $ forgiveness_date <date> 2021-06-11, NA, 2021-08-17, 2021-08-26, 2021-07-22…
## $ lender <chr> "The Huntington National Bank", "Great Western Bank…
## $ rural_urban <chr> "U", "R", "U", "U", "U", "U", "U", "U", "U", "U", "…
## $ low_income_area <chr> "N", "Y", "N", "Y", "Y", "Y", "N", "N", "Y", "N", "…
## $ project_county <chr> "MARICOPA", "APACHE", "MARICOPA", "PIMA", "MARICOPA…
## $ project_state <chr> "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ", "AZ…
## $ project_cong_dist <chr> "AZ-06", "AZ-01", "AZ-09", "AZ-02", "AZ-06", "AZ-09…
## $ employees <dbl> 500, 500, 500, 500, 500, 500, 500, 378, 500, 500, 5…
## $ business_type <chr> "Limited Liability Company(LLC)", "Non-Profit Orga…
## $ naics_code <chr> "722310", "221122", "621610", "621111", "517311", "…
## $ census_zip <chr> "85260", "86504", "85018", "85711", "85250", "85012…
## $ sector_code <chr> "72", "22", "62", "62", "51", "62", "56", "62", "48…
## $ subsector_code <chr> "722", "221", "621", "621", "517", "621", "561", "6…
## $ sector_desc <chr> "Accommodation and Food Services", "Utilities", "He…
## $ subsector_desc <chr> "Food Services and Drinking Places", "Utilities", "…
## $ naics_desc <chr> "Food Service Contractors", "Electric Power Distrib…
Write the code chunks and explain what you see in the results for these five questions:
ppp_industry %>%
mutate ( difference = forgiveness_amount - amount,
pct_difference = difference / amount * 100) %>%
filter ( difference > 0 ) %>%
arrange ( desc(pct_difference )) %>%
select ( borrower_name, borrower_city, amount, pct_difference)
head(25)
## [1] 25
There’s really nothing interesting here - we’d have to look at how forgiveness works in the program. This could be forgiven interest or fees.
A: An examination of the industry list showed no hair salons, but beauty salons are listed as industry 812112. We have to decide how much is “little money”. I’m going to look at the distribution of the amounts across the whole dataset and see what “small” is by using the skimr::skim command:
ppp_industry %>%
skimr::skim(amount)
| Name | Piped data |
| Number of rows | 169268 |
| Number of columns | 29 |
| _______________________ | |
| Column type frequency: | |
| numeric | 1 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| amount | 0 | 1 | 73214.08 | 259961.2 | 10 | 9522 | 20800 | 47027.01 | 10000000 | ▇▁▁▁▁ |
Now look at the distribution of beauty salons:
ppp_industry %>%
filter ( naics_code == "812112") %>%
skimr::skim(amount)
| Name | Piped data |
| Number of rows | 6693 |
| Number of columns | 29 |
| _______________________ | |
| Column type frequency: | |
| numeric | 1 |
| ________________________ | |
| Group variables | None |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| amount | 0 | 1 | 20841.47 | 73982.39 | 10 | 5265 | 12972 | 20832 | 2033088 | ▇▁▁▁▁ |
So the distribution is a bit lower than in the full list, but that’s to be expected – these are pretty small businesses. So now we want to see if the micro-loans are all in beauty salons. Let’s see what percent of industry loans are under 1000. That means creating a couple of categories:
ppp_industry %>%
mutate ( small_large = if_else ( amount <= 1000, "Small", "Larger")) %>%
group_by ( naics_desc, small_large) %>%
summarise ( loans = n() ) %>%
mutate ( pct_industry = loans / sum(loans) * 100) %>%
filter ( small_large == "Small" & loans > 50) %>%
arrange ( desc (pct_industry))
## `summarise()` has grouped output by 'naics_desc'. You can override using the `.groups` argument.
So there are only four industries with more than a few loans under $1000, and Beauty Salons is one of them. But it’s not that many of them – only 1 percent of their loans were under 1000, so I guess our anecdote wasn’t very telling.
A: This is actually kind of tricky. There are several ways to do it, but here’s one: Pull out the first round into one data frame, and the second into another, then join them by name. We’ll want to find the ones that are in the second round, and not the first. There’s a join called an anti_join, which does just that, but you haven’t seen it yet, so I’ll do it both ways .
Create two different data frames. (I rename the “amount” column in one of them so they don’t end up with the same name in both)
first <- ppp_industry %>% filter ( draw == "First") %>% select (borrower_name, borrower_city, first_draw_amount = amount)
second <- ppp_industry %>% filter ( draw=="Second")
The first way is to use a “left_join” and then filter for the missing ones in the first data frame:
second %>%
left_join ( first, by=c("borrower_name", "borrower_city")) %>%
filter ( is.na(first_draw_amount ))
There aer a lot of them – 10,403, matching by name and city. You could try just matching by name and see if it drops down. Here’s how you’d do that using the anti_join instead:
second %>%
anti_join ( first, by="borrower_name")
That takes it down a little. You’d probably want to find an industry or a city that interests you to go talk with people since there are so many. You might also be interested in the lenders to these second-round only – the government set aside more money for lenders who specialize in underserved areas, so they might be disporportionately in minority or low income zip codes.
second %>%
anti_join (first, by="borrower_name") %>%
group_by (lender) %>%
summarise ( loans = n(), amount = sum(amount)) %>%
arrange (desc ( loans))
This is kind of strange, regarding Jame’s Prestamos bank – most of their loans were categorized as “first draw” from the SBA, but many of them were very late in the program – May 2021. They are definitely worth looking into.
A: We did this in class, but it’s the same idea as above. We just need to convert the NA in the forgiveness amount to 0 first:
ppp_industry %>%
mutate ( forgiveness_amount = replace_na (forgiveness_amount, 0),
forgiveness_yn = if_else ( forgiveness_amount > 0, "Something forgiven", "Nothing forgiven")) %>%
group_by ( draw , forgiveness_yn ) %>%
summarise ( loans = n() ) %>%
mutate ( pct_forgiven = loans / sum(loans) * 100)
## `summarise()` has grouped output by 'draw'. You can override using the `.groups` argument.
This one should be pretty easy for you:
ppp_industry %>%
group_by ( subsector_desc ) %>%
summarise ( loans = n(), amount = sum(amount)) %>%
arrange ( desc(loans))
One thing that is surprising is that we all heard so much about restaurants getting help, but other industries got more loans.
Same idea here, but you have to be careful about NA’s in the employee totals – you should exclude them before you try to compute the average, or they’ll be counted as zero, which we don’t know is true. I’m just doing the subsectors here - you could do these or the detailed industries
ppp_industry %>%
filter ( ! is.na (employees)) %>%
group_by ( subsector_desc ) %>%
summarise ( loans = n(), amount = sum(amount), employees=sum(employees)) %>%
mutate ( per_employee = amount / employees) %>%
arrange ( desc(per_employee))
It’s interesting that the very industries we dont think of as getting hammered by the pandemic got the most per employee – though there aren’t a lot of loans in those groups. I’m not sure what this tells us!
This could be hard! You might limit yourself to the first round (draw) of the loan program, which had fewer controls than the second, so you don’t get confused by those that got loans in both rounds.
I’ve added a new summary function that you haven’t seen: n_distinct (borrower_name), which tells us how many different names are on the loans.
ppp_industry %>%
filter ( draw == "First") %>%
group_by (borrower_address , borrower_city ) %>%
summarise ( loans = n() , amount = sum(amount), borrowers = n_distinct (borrower_name), .groups="drop") %>%
filter ( loans > 1) %>%
arrange ( desc ( borrowers))
There are several ways to whittle this down a little - You might use your superpowers of filtering to eliminate anything that has Suite or Ste . You have to be a little careful not to eliminate “St”, though. You could also get the average amount of loan, and focus on those with small amounts that might not be scrutinized. Or you could look to see if there are lenders who seem to have an awful lot of them.
None of these prove “fraud”, and they may actually be quite legitimate and exactly what was intended. But you have to think broadly about how to start finding good leads.
We could try to add some census data to the loans, and see if we can find those that are in Zip Codes that have wildly more residents than businesses – or practically no businesses at all. But it’s quite possible to run a business out your home, which makes it difficult to analyze. Let’s just try it.
duplicates <-
ppp_industry %>%
filter ( draw == "First") %>%
group_by (borrower_address , borrower_city, census_zip ) %>%
summarise ( loans = n() ,
amount = sum(amount),
borrowers = n_distinct (borrower_name),
avg_amount = mean(amount),
.groups="drop") %>%
filter ( loans > 1)
#now join it to the census data , and check the number of USPS businesses.
#
duplicates %>%
inner_join ( census, by=c("census_zip" = "zcta")) %>%
filter ( usps_businesses < 50 & households > 1000)
#
That gets us down to 88 possible places to look at. Let’s use this output to get a full list of companies and loans from those 88 addresses. That means joining it back.
We want to check the “low and moderate income area” designation on the loans. HUD says that moderate income areas have median incomes of 80% of the area total. We don’t have metro areas in this data, so we’ll use household income of $58,000 – approximately what it is for the state.
(I realized I made this way more complicated than it had to be in the original document - you can just filter after joining! )
ppp_industry %>%
inner_join ( census, by=c("census_zip" = "zcta")) %>%
filter ( low_income_area == "Y" & median_inc_2018 < 58000 ) %>%
arrange ( desc ( median_inc_2018))
That’s a lot! I’m not sure what I’d do next on this – I think I’d probably try to find out why they are designated that way by talking with some of the lenders.
You can do this two ways - attach the census ethnicity to the loans, then add them up - or add them up and then get the census data. We’ll do the first one. (You have to use na.rm=T in the forgiveness amount because we want to treat NA’s as zero)
ppp_industry %>%
left_join (census, by=c("census_zip"="zcta")) %>%
group_by (zcta_ethnic) %>%
summarise ( loans = n(),
amount = sum(amount),
forgiven = sum(forgiveness_amount , na.rm=T)
) %>%
mutate ( forgiven_pct = forgiven / amount * 100) %>%
arrange (forgiven_pct)
A: We kind of did this above by looking at the multiple loans at the addresses - see if you can do it more generally, or choose something that might be a good screen.
Let’s first get the Prestamos loans:
prestamos <-
ppp_industry %>%
filter ( str_detect (lender, "Prestamos")) %>%
select (borrower_name:borrower_zip, date_approved, amount, forgiveness_amount,
rural_urban, project_cong_dist, employees, business_type, subsector_desc, census_zip)
Now let’s join it and see what the income, ethnicity and other characteristics are of their loans:
prestamos %>%
inner_join (census, by=c("census_zip"="zcta")) %>%
select ( census_zip, median_inc_2018, zcta_ethnic, pct_hispanic, borrower_name:subsector_desc) %>%
mutate ( pct_hispanic = pct_hispanic* 100) %>%
arrange ( desc(amount))
It does appear that they loaned in areas that are diverse or primarily Latino - we’d have to keep working on this to learn more.