The Impact of COVID-19 on Unemployment and Participation Rate
In this project, which will be completed in the Python coding language, we will pull data from the FRED website to analyze the effects of COVID-19 on each state’s respective unemployment and participation rates. The goal of this project is to display each state’s rates for further evaluation.
Code Explanation
Library Imports & API Setup:
Imports:
Imports
pandas
andnumpy
for data handling,matplotlib
andplotly
for visualization, andfredapi
to access FRED’s economic data.
Configuration:
Sets plot style with
plt.style.use('fivethirtyeight')
.Adjusts
pandas
display settings usingpd.set_option('display.max_columns', 500)
.
API Initialization:
Stores the FRED API key and initializes
Fred(api_key = fred_key)
for authenticated access.
Data Retrieval:
Key Economic Indicators:
S&P 500 (
sp500
):fred.get_series('SP500')
pulls the historical stock market data.Unemployment Rate (
unrate
):fred.get_series('UNRATE')
retrieves U.S. unemployment data.CPI (
cpi
):fred.get_series('CPIAUCSL')
gathers inflation data.Treasury Yields: Uses
fred.get_series()
with different series IDs (e.g., 'DGS1', 'DGS5', 'DGS10') to pull various Treasury yields.Participation Rate (
participation_rate
):fred.get_series('CIVPART')
fetches labor force participation data.
Data Preview:
Displays data using
print()
or by outputting the variable directly to confirm each dataset was loaded successfully.
Data Exploration & Initial Visualization:
Trend Plots:
Plots each dataset individually (e.g.,
sp500.plot(figsize=(10,5), title='S&P 500')
) to visualize historical trends.Uses parameters like
figsize
,title
, andlw
(line width) for enhanced readability.
Purpose of Initial Visualizations:
These visualizations allow for spotting trends, peaks, and cycles in each dataset.
Indicators like unemployment and participation rates offer a snapshot of workforce health and economic cycles.
Data Transformation:
Percentage Change Calculations:
Calculates percentage changes with
.pct_change()
on critical indicators:S&P 500:
sp500.pct_change()
shows market growth trends.CPI:
cpi.pct_change()
calculates inflation rate changes.
Growth Rate Visualization:
Plots these percentage changes (e.g.,
sp500.pct_change().plot()
), making it easier to identify fluctuations in growth rates.
Purpose:
Observing these transformed metrics over time provides insights into the cyclical nature of stock performance and inflation trends.
Combining Data for Comparative Analysis:
Data Merging:
Uses
pd.concat([sp500, unrate, cpi, participation_rate], axis=1, join='inner')
to align and combine data for all indicators by date.
Data Cleaning:
Uses
.dropna()
to remove rows with missing data, ensuring that each entry has complete values for analysis.
Purpose of Merging:
The merged DataFrame enables multi-variable analysis across stock performance, inflation, unemployment, and workforce participation.
COVID-19 Impact Analysis:
Focused Analysis of Unemployment and Participation Rates:
Filters data to isolate pre-COVID and COVID periods using conditions like
unrate['2020-01-01':'2021-12-31']
andparticipation_rate['2020-01-01':'2021-12-31']
.
Comparative Visualizations:
Plots unemployment and participation rate data, using
unrate.plot()
andparticipation_rate.plot()
with highlighted sections for the pandemic.These visualizations underscore sharp shifts in unemployment and participation as COVID-19 hit.
Insights on COVID-19 Impact:
Observes dramatic spikes in unemployment and significant drops in participation, reflecting the economic shock of COVID-19 as many people left the workforce or lost jobs.
Visual comparisons highlight how COVID-19 created unique challenges, impacting workforce participation alongside unemployment levels.
Final Visualization & Comparative Analysis:
Comparative Plots:
Plots merged data (e.g.,
combined_data.plot()
) to observe relationships across indicators, comparing trends before, during, and after COVID-19.COVID-19-Specific Comparisons: Highlights COVID-19 within broader trends, emphasizing the pandemic’s unique impact on both employment and participation.
Conclusive Insights:
These visualizations reveal COVID-19’s dual impact on job availability and workforce engagement, as shown by shifts in both unemployment and participation rates.
A multi-indicator view offers valuable insights into economic dependencies and interactions, setting a foundation for further econometric analysis or predictive modeling.
Written Explanation
Setting Up the Tools:
The code starts by bringing in tools (libraries) to help with handling data, creating graphs, and getting economic information from the Federal Reserve (FRED).
It then sets up a style for the graphs to make them look nice and makes sure that tables can show a lot of columns if needed.
Finally, it connects to FRED using an access key, so we can download economic data.
Getting Important Economic Data:
The code pulls key economic data that helps us understand the U.S. economy:
S&P 500: This shows how the stock market is doing over time.
Unemployment Rate: Tracks how many people are out of work and looking for jobs.
Consumer Price Index (CPI): Measures inflation by looking at the prices of goods and services.
Treasury Yields: Shows interest rates on government bonds, giving a picture of long-term economic expectations.
Participation Rate: Shows the percentage of people actively working or looking for work.
After retrieving this data, the code quickly checks to make sure each dataset loaded correctly.
Making Basic Graphs of Each Data Type:
For each economic indicator (like the stock market or unemployment rate), the code creates a graph showing how it has changed over time.
These graphs give a quick visual of patterns, like:
S&P 500: Shows market ups and downs.
CPI: Highlights inflationary periods.
Unemployment & Participation Rates: Gives a look at how many people are working or actively seeking work, especially through economic cycles.
Looking at Growth Rates:
The code then calculates how quickly certain data points are changing each year:
Stock Market (S&P 500): Calculates yearly growth to see when the market grew fast or slowed down.
CPI (Inflation): Measures how inflation changes each year, helping spot high-inflation periods.
The growth rates are then graphed to make it easier to see cycles, like booms and busts in the market or sharp rises in inflation.
Bringing All the Data Together:
The code combines all the different datasets (S&P 500, unemployment, CPI, Treasury yields, and participation rate) into one big table where each row is a specific date.
It also removes any rows with missing data, so every date has complete information for all indicators.
Combining the data lets us compare everything at once to see if, for example, stock market trends match up with unemployment changes.
Analyzing the COVID-19 Impact:
The code looks specifically at how the unemployment rate and participation rate changed during COVID-19 (focusing on 2020-2021).
It filters the data to show just before COVID and during the pandemic:
Graphing Unemployment & Participation Rates: Creates focused graphs on unemployment and participation rates, highlighting the COVID period.
Observing Trends:
Unemployment Spike: Shows a large jump in unemployment at the start of COVID, reflecting job loss or temporary layoffs.
Participation Rate Drop: Highlights how fewer people were either working or looking for work, likely due to health risks, caregiving, or other pandemic-related reasons.
Final Comparison and COVID Impact Summary:
After combining everything, the code creates a set of comparison graphs showing how different economic factors relate, both over the long term and specifically during COVID-19.
This lets us see things like:
Participation & Stock Market: How workforce engagement may have affected economic stability.
COVID’s Unique Impact: By looking at the sudden rise in unemployment and drop in participation, we can better understand how the pandemic disrupted the economy.
The final graphs give a comprehensive view, showing both normal economic patterns and COVID-19’s unusual effects on the workforce and economy.