setwd("C:/Users/chesl/Desktop/DATA110")DATA110_Final_Project
Warning: dataset/graphs load very slowly
Background information
ForeignAssistance.gov is the U.S. government’s official website for storing and sharing data about foreign assistence, operated and regularly updated by the Department of State. Formal reporting requirements were established by the Foreign Assistance Act of 1961, although the dataset has data since 1946. Since then, the U.S. has declared a commitment to being transparent about its foreign assistance, passing acts such as the Foreign Aid Transparency and Accountability Act of 2016 (FATAA), and being a member of the Organization for Economic Cooperation and Development (OECD), and the International Aid Transparency Initiative (IATI). Although it is irrelevant to this project, the site already has several pre-made interactive maps/graphs available to the public.
Methodology: per itself, ForeignAssistance.gov
collects data about foreign aid at two stages of the financial process: budgetary and financial.
Budgetary data are about funds requested by the various U.S. government agencies (compiled in the President’s Budget submitted to Congress), and appropriations passed by Congress.
Financial data are: obligations: a legal requirement for the U.S. government to commit to a payment, and disbursements: paid obligations.
Dataset information
The complete dataset is 3967456 obs. * 56 vars. large, but for the purposes of my analysis, the file is bloated with many variables having unnecessary duplicates: in the form of numeric IDs, separate acronym vars, and branching vars (agency, sub-agency, etc.).
The most relevant vars are: country_name, constant_dollar_amount (in U.S. dollars, “constant” = adjusted for inflation), fiscal_year, funding_account_name, funding_agency_name, managing_agency_name, and us_category_name (type of aid).
I learned about this database in the beginning of the semester and used a pre-made subset of it for my midterm project. However, I felt like I could definitely improve upon the analysis I performed then, so I chose the complete dataset for the final project now. I was interested in the sum flow of money: in what year(s), from which funding account/agency, through which managing agency/entity, and to which countries foreign assistance was sent, and what type of assistance it was.
# load libraries
library(tidyverse)
library(viridis)
library(dplyr)
# load dataset
df <- read_csv("us_foreign_aid_complete.csv")
# dataset dimensions: 3967456*56
dim(df)[1] 3967456 56
Cleaning the dataset was relatively easy: remove the unnecessary vars, rename the remaining vars (tolower(), gsub(), rename()); filter for after 1990, but before 2024 (2025–6 columns are blank), and remove na values. Note: using “constant” dollar amounts, i.e. adjusted for inflation.
# selecting important vars
df2 <- df |> select(
"Country Name",
"Managing Agency Name", "Managing Sub-agency or Bureau Name",
"Implementing Partner Category Name", "Implementing Partner Sub-category Name", "Implementing Partner Name",
"US Category Name", "US Sector Name",
"Funding Account Name", "Funding Agency Name",
"Activity Name", "Activity Description",
"Transaction Type Name", "Fiscal Year", "Current Dollar Amount", "Constant Dollar Amount")
# standardize var names
names(df2) <- tolower(names(df2))
names(df2) <- gsub(" ", "_", names(df2))
# refine vars: rename and filter
df3 <- df2 |>
rename(constant = constant_dollar_amount) |>
rename(year = fiscal_year) |>
rename(funding_agency = funding_agency_name) |>
rename(managing_agency = managing_agency_name) |>
rename(category = us_category_name) |>
filter((year >= 1990) & (year <= 2024)) |>
filter(category != "Multi-sector") |>
filter(!is.na(constant) & !is.na(year) &
!is.na(funding_agency) & !is.na(managing_agency) & !is.na(category))Visualization(s) No.1: Heatmaps
# heatmap() has no native legend or caption
# "plasma" color gradient: blue (lowest value) -> purple -> orange -> yellow (highest value)
# ?viridis() -> Viridis Color Palettes
# subsetting for heatmap No.1
df4 <- df3 |>
group_by(funding_agency, year) |>
summarize(annual = sum(constant)) |>
pivot_wider(
names_from = year,
values_from = annual
) |>
relocate("2001", .after = 1:12) # reorder column 2001
matrix_funding <- data.matrix(df4[, -1])
row.names(matrix_funding) <- df4$funding_agency
heatmap_funding <- heatmap(matrix_funding,
Rowv = NA,
Colv = NA,
scale = "column",
main = "Foreign aid by funding U.S. agency, 1990–2024",
xlab = "Year",
ylab = "", # otherwise overlaps with labels
col = viridis(1015, option = "plasma") # chosen because its darkest color is blue instead of black
)# subsetting for heatmap No.2
df5 <- df3 |>
group_by(managing_agency, year) |>
summarize(annual = sum(constant)) |>
pivot_wider(
names_from = year,
values_from = annual
) |>
relocate("2001", .after = 1:12) # reorder column 2001
matrix_managing <- data.matrix(df5[, -1])
row.names(matrix_managing) <- df5$managing_agency
heatmap_funding <- heatmap(matrix_managing,
Rowv = NA,
Colv = NA,
scale = "column",
main = "Foreign aid by managing U.S. agency, 1990–2024",
xlab = "Year",
ylab = "", # otherwise overlaps with labels
col = viridis(1015, option = "plasma")
)These two plots reveal alot about the distribution of money across U.S. agencies. First, it is obvious that the Dept. of State and USAID handle most of the money delegated for foreign aid. However, whereas the Dept. of State manages most of the money, U.S.A.I.D. is the agency that actually carries out/manages most of the funds. Other anomalies: the Dept. of the Army funded in the 2000s, the Dept. of Defense also managed a lot of funds, likely due to the War on Terror. Its spending flairs up again in 2022–2024, likely due to relevant conflicts in Ukraine and Gaza.
Visualization(s) No.2: Alluvial Graph + Map in Tableau
Link to graphs: https://public.tableau.com/views/data110_final_project_tableau/data110_final_project_tableau?:language=en-US&:sid=&:redirect=auth&:display_count=n&:origin=viz_share_link
Dataset used: df (original)
This visualization puts into a wider perspective the overall flow of money from funding agency to type of aid, and eventually country. For example, countries in South Africa tend to have received noticeably more aid in the “Health” category, a trend obviously explained by the region’s vulnerability to diseases, hunger, and other health-related problems. Likewise, “Humanitarian Assistance” is especially prevalent in Eastern Africa, uncoincidentally given to countries in distress, such as the recently formed South Sudan. “Peace and Security” take out enormous proportions of total aid in the countries of Israel, Egypt, Iraq, Afghanistan, and Colombia: countries in conflict that the U.S. has intervened in/supported in the 21st century.
fit2 <- lm(constant ~ current_dollar_amount, data = df3)
summary(fit2)
Call:
lm(formula = constant ~ current_dollar_amount, data = df3)
Residuals:
Min 1Q Median 3Q Max
-2.333e+09 5.672e+03 1.059e+04 1.098e+04 1.391e+09
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.076e+04 2.890e+03 -3.725 0.000196 ***
current_dollar_amount 1.343e+00 1.204e-04 11152.485 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 5565000 on 3711812 degrees of freedom
Multiple R-squared: 0.971, Adjusted R-squared: 0.971
F-statistic: 1.244e+08 on 1 and 3711812 DF, p-value: < 2.2e-16
# adjusted R-squared: 0.971, p-value: 2.2e-16.
par(mfrow = c(2, 2)) # to ensure residual plots are created at the same time
plot(fit2, ask = FALSE)This statistical analyis is that of current/constant dollar amounts. “Constant” are the sums adjusted for inflation. When comparing the original sums to the adjusted ones, the R-squared value is 0.971—the model can predict the aid’s current value 97% of the time. This indicates that the inflation coefficient is linear, and has remained mostly unchanged througout the years: without any other vars, the model must be performing the same operation on values from different years and coutries and agencies, etc.. This suggests that inflation has been relatively stagnant for the last 34 years.
The residuals vs. fitted plot is not linear, however, or random, suggesting that the infation has not increased in a linear way. The Q-Q plot, however, is more reasonable: within the theoretical quartiles, almost all points fall on the straight line, suggesting the assumed distribution, with the exception of outliers.
I would like to return to this dataset in a couple of years, especially as it is updated for the 2025–2026 years, to see whether the patterns/priorities will have continued or not.
Work Cited:
U.S. Foreign Assistance Complete Dataset. foreignassistance.gov/data, us_foreign_aid_complete.csv, accessed July 1 2026.