Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Forecasting Economic Indicators | Economic Modeling and Regression
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for Economists

bookForecasting Economic Indicators

Economic forecasting is a vital part of economics, helping you anticipate future trends and make informed decisions. By using regression models, you can predict future values of key economic indicators, such as GDP, inflation, or unemployment, based on historical data. Simple linear regression is one of the most accessible methods for this task. It allows you to model the relationship between a single independent variable (like time) and a dependent variable (such as GDP), and then use this relationship to forecast what might happen next.

123456789101112131415
import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression # Example: Historical GDP data (in billions) years = np.array([2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]).reshape(-1, 1) gdp = np.array([18000, 18500, 19000, 19500, 20000, 19800, 20500, 21000]) # Fit linear regression model model = LinearRegression() model.fit(years, gdp) # Print model coefficients print("Intercept:", model.intercept_) print("Slope:", model.coef_[0])
copy

Once you have fitted a linear regression model, you can use it to forecast future values by plugging in new values for the independent variable. In the GDP example above, the model learns the relationship between year and GDP. To forecast next year's GDP, you provide the next year as input to the model's prediction method. This approach is widely used in economics for short-term forecasting, as it leverages historical trends to make informed predictions about the future.

12345678910111213141516171819202122
import matplotlib.pyplot as plt # Forecast GDP for 2023 next_year = np.array([[2023]]) gdp_forecast = model.predict(next_year) # Combine historical and forecast data for plotting years_extended = np.append(years.flatten(), 2023) gdp_extended = np.append(gdp, gdp_forecast[0]) # Plot historical data plt.plot(years.flatten(), gdp, marker='o', label='Historical GDP') # Plot forecast plt.plot(2023, gdp_forecast[0], 'ro', label="Forecast 2023") plt.plot(years_extended, gdp_extended, 'k--', alpha=0.4, label="Trend Line") plt.xlabel("Year") plt.ylabel("GDP (billions)") plt.title("GDP Forecast for 2023") plt.legend() plt.show()
copy

1. What is the main purpose of forecasting in economics?

2. Fill in the blank: To predict future values using a regression model, you would use _ _ _.

3. Why is it important to visualize forecasts together with historical data?

question mark

What is the main purpose of forecasting in economics?

Select the correct answer

question-icon

Fill in the blank: To predict future values using a regression model, you would use _ _ _.

question mark

Why is it important to visualize forecasts together with historical data?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookForecasting Economic Indicators

Deslize para mostrar o menu

Economic forecasting is a vital part of economics, helping you anticipate future trends and make informed decisions. By using regression models, you can predict future values of key economic indicators, such as GDP, inflation, or unemployment, based on historical data. Simple linear regression is one of the most accessible methods for this task. It allows you to model the relationship between a single independent variable (like time) and a dependent variable (such as GDP), and then use this relationship to forecast what might happen next.

123456789101112131415
import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression # Example: Historical GDP data (in billions) years = np.array([2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]).reshape(-1, 1) gdp = np.array([18000, 18500, 19000, 19500, 20000, 19800, 20500, 21000]) # Fit linear regression model model = LinearRegression() model.fit(years, gdp) # Print model coefficients print("Intercept:", model.intercept_) print("Slope:", model.coef_[0])
copy

Once you have fitted a linear regression model, you can use it to forecast future values by plugging in new values for the independent variable. In the GDP example above, the model learns the relationship between year and GDP. To forecast next year's GDP, you provide the next year as input to the model's prediction method. This approach is widely used in economics for short-term forecasting, as it leverages historical trends to make informed predictions about the future.

12345678910111213141516171819202122
import matplotlib.pyplot as plt # Forecast GDP for 2023 next_year = np.array([[2023]]) gdp_forecast = model.predict(next_year) # Combine historical and forecast data for plotting years_extended = np.append(years.flatten(), 2023) gdp_extended = np.append(gdp, gdp_forecast[0]) # Plot historical data plt.plot(years.flatten(), gdp, marker='o', label='Historical GDP') # Plot forecast plt.plot(2023, gdp_forecast[0], 'ro', label="Forecast 2023") plt.plot(years_extended, gdp_extended, 'k--', alpha=0.4, label="Trend Line") plt.xlabel("Year") plt.ylabel("GDP (billions)") plt.title("GDP Forecast for 2023") plt.legend() plt.show()
copy

1. What is the main purpose of forecasting in economics?

2. Fill in the blank: To predict future values using a regression model, you would use _ _ _.

3. Why is it important to visualize forecasts together with historical data?

question mark

What is the main purpose of forecasting in economics?

Select the correct answer

question-icon

Fill in the blank: To predict future values using a regression model, you would use _ _ _.

question mark

Why is it important to visualize forecasts together with historical data?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
some-alt