## 1. Correlation Plot (Quarterly Nowcasting Model Data)

## Source details

**Canonical URL:** [1. Correlation Plot (Quarterly Nowcasting Model Data)](https://www.imf.org/-/media/files/publications/cr/2024/english/1lsoea2024002-print-pdf.pdf)

## Other formats

- [Markdown version](/-/media/files/publications/cr/2024/english/1lsoea2024002-print-pdf.pdf.md)
- [Structured JSON version](/-/media/files/publications/cr/2024/english/1lsoea2024002-print-pdf.pdf.json)

---

### Overview
- Purpose: Use machine learning (ML) to nowcast Lesotho GDP growth in real time given delayed and frequently revised official GDP data.
- Key questions:
  - What is GDP growth at present?
  - Is economic activity under- or over-estimated by the standard statistics?
  - Where is inflation heading? (contextual; GDP nowcasting section focuses on first two questions)
- Data context:
  - Delayed and frequently revised quarterly GDP.
  - Outdated GDP base year: 2012.
  - Structural shift toward a larger informal economy since the pandemic in 2020-21.

### Methodology and ML fundamentals
- ML objective: prioritize out-of-sample predictive accuracy rather than inference or causal identification.
- Validation approaches:
  - Holdout validation: split into training and testing sets to compute validation error.
  - Cross validation: K-fold example (K=3) described; applied 5-fold cross validation to tune hyperparameters and assess models.
- Interpretability tools:
  - Variable importance via scrambling each variable to measure impact on model performance.
  - Shapley Values to explain contributions of variables to individual predictions.

### Nowcasting model specification
- Predictor set: 29 possible predictors including trade-related variables, fiscal outturns (water royalties, government spending), activity in South Africa (PMI, business confidence), electricity consumption, tax revenues (PAYE Receipts, VAT), REER, CPI, and alternative data (e.g., Google searches on “travel to Lesotho”).
- Data split for model evaluation:
  - Training set: 48 quarterly observations leading up to Q4 2022.
  - Testing set: 4 quarterly observations in 2023.
- Models evaluated: eight different model types ranging from OLS to a neural net.
- Model tuning and selection: 5-fold cross validation used to optimize models and tune hyperparameters; models ranked by validation performance (“horserace”).

### Model comparison and ensemble construction
- Horserace training-set validation result:
  - Support Vector Machine (SVM) with a linear kernel identified as most likely to perform well out of sample.
  - Classic OLS performed worst.
- Horserace stability:
  - Rankings changed significantly when judged only on the small test set, indicating potential instability of single-model selection.
- Ensemble approach:
  - Built to stabilize nowcasts by combining predictions from candidate models.
  - Ensemble weights determined optimally via 5-fold cross validation across the training set.
  - Final ensemble: a weighted average of five types of model, with most of the weight given to the SVM (linear) model and the Extreme Gradient Boosting (“XGBoost”) model.
  - Ensemble constructed via a Lasso regression of GDP growth using predictions from a pool of candidate models (including a broader set of top-performing hyperparameter combinations).

### Variable importance (ensemble results)
- Correlation structure:
  - Strong cluster of predictors associated with GDP growth, including trade-related indicators, electricity consumption, and tax revenue.
  - Second cluster largely comprises indicators from South Africa.
- Most important predictors for the ensemble (variable-importance ranking):
  - Leading indicator of activity in South Africa (highest importance; scrambling this variable does the most damage to model performance).
  - Imports from South Africa.
  - Tax revenues.
  - Textile exports to the USA.
  - Alternative data such as Google trends included in the predictor set.

### Nowcast results and drivers
- Temporal pattern: Lesotho’s real GDP growth improved significantly in Q1-2024 after bottoming out in Q3-2023.
- Exact nowcast figures:
  - 0.5 percent at end-2023
  - 1.8 percent in March 2024
- Shapley Value decomposition for March 2024 nowcast:
  - Main upward contributors: strong boost in water royalties; improvement in textile exports to the USA.
  - Main downward contributor: lower exports to South Africa.

### Real GDP evaluation: motivation and approach
- Motivation:
  - Potential misestimation of real economic activity by Lesotho’s Bureau of Statistics due to lack of data, capacity constraints, and other barriers.
  - Covid-19 pandemic may have expanded the informal economy, changing previous sensitivities.
- Methodology:
  - Machine learning technique used: LASSO regression.
  - Estimation sample: 40 observations covering the period prior to the pandemic (i.e., Q1-2010 – Q4-2019).
  - Goal: track closely the actual series; validated by in-sample fit close to 1, with an R2 higher than 0.9.
- Regressor set:
  - Standard macroeconomic indicators, fiscal variables, and alternative series such as night lights, air pollution, and precipitation.
  - Most relevant variables selected by LASSO are related to fiscal outturns.
  - Specific selected variables and their importance:
    - Government’s goods and services variable: highest standardized coefficient (2.4).
    - Water royalties and fiscal balance: selected as significant.
    - Water consumption and imports of construction materials: equally relevant.
    - From alternative sources: air pollution and Google searches selected.

### Key findings on GDP estimation bias
- Out-of-sample deviations (post-pandemic, 2020–2023):
  - Predicted “out-of-sample” GDP series deviate significantly from the actual data over the post-pandemic period.
  - Estimated potential underestimation of real GDP close to 9 percent at end-2023.
  - Largest deviation is in 2022, with the estimated series being about 14 percent greater than the actual.

### Inflation forecasting: objectives and data
- Motivation:
  - Inflation surprised to the upside in recent years due to sequential exogenous shocks (pandemic demand resurgence, higher food/cereal prices because of the war in Ukraine, supply-chain disruptions).
  - Inflation rates in Lesotho and South Africa diverged in 2023–24 primarily due to a larger share of food items in Lesotho’s CPI basket; trends started to slowly converge in 2024.
  - Systematic forecasting errors may misestimate fiscal and other variables, potentially leading to welfare costs.
- Data and predictors:
  - Inflation series in Lesotho: 70 quarterly observations.
  - Large set of regressors includes global (oil, international food prices, Baltic Freight Index), regional (South Africa indicators including inflation expectations, leading indicators, business satisfaction, PMIs), and local variables (nominal exchange rates, Rand to USD, business activity proxies).
  - Four lags are included for each predictor plus inflation lags.
  - International prices for food and oil obtained from the WEO database, which offers forecasts for upcoming quarters based on futures markets.

### Models, cross-validation, and performance for inflation
- Models highlighted:
  - Random Forests: ensemble technique, good at capturing nonlinearities.
  - Elastic Net Regression: regularization technique balancing Lasso and Ridge, parsimonious and explainable.
- Cross-validation scheme:
  - Goal: forecast inflation four quarters ahead.
  - Training starts with the first five years and evaluates the next year; at each step expand training set by one year and shift testing set by one year until end of sample.
  - With 70 quarters, this yields 12 different training and testing sets.
  - Tuning parameters chosen to minimize the Mean Absolute Scaled Error (MASE).
- Out-of-sample performance:
  - Elastic Net has the lowest RMSE compared to other models and the AR(4) benchmark for both South Africa and Lesotho.
  - For Lesotho: substantial improvement in RMSE compared to AR(4), with a reduction of about 30 percent at the median for the Elastic Net.
  - Variables selected by Elastic Net for Lesotho include South Africa’s inflation expectations, the leading indicator, the PMI, and international food prices.
  - For South Africa: out-of-sample improvement is smaller, with the median RMSE just under 1 for the Elastic Net; primary variables include business satisfaction and global oil prices.

### Inflation forecast outcomes and implications
- One-year-ahead forecasts (across models):
  - South Africa: one-year ahead predictions vary between 4.9 and 6.2 percent across the three models.
    - Elastic Net prediction is close to 5 percent at the end of Q1-2025.
  - Lesotho: one-year ahead forecasts range from 5.6 to 6.4 percent across models.
    - Elastic Net forecast ends FY24/25 at 5.9 percent and closely tracks the Random Forest.
- Key interpretation:
  - Models consistently predict a narrower divergence between inflation trends in South Africa and Lesotho over the next four quarters, signaling further convergence.

### Conclusions and policy implications
- Data and policy challenge:
  - Accurate and timely data are essential for policymakers; Lesotho faces delayed and often revised quarterly GDP data, absence of high-frequency measures, coordination issues among public agencies, and an outdated GDP base.
  - The pandemic likely expanded the informal economy’s share, complicating measurement.
- Role of machine learning:
  - ML techniques provide a flexible framework for nowcasting and forecasting focused on prediction accuracy over causality.
  - ML helps circumvent data scarcity by leveraging alternative datasets to provide real-time insights into GDP growth, evaluate potential bias in standard statistics, and improve inflation forecasts amidst global and regional shocks.
- Policy takeaways:
  - Use ML-based estimates as complementary inputs to official statistics to reduce risks from mismeasured GDP and misforecasted inflation.
  - Incorporate alternative data sources (e.g., air pollution, Google searches, imports of construction materials, water consumption) and fiscal variables into monitoring systems to better capture informal activity and government footprint.
  - Adopt Elastic Net and ensemble approaches (Random Forests) for inflation forecasting to improve RMSE relative to AR(4) benchmarks and to better capture turning points and convergence dynamics between Lesotho and South Africa.

*Source: 1lsoea2024002-print-pdf - 1. Correlation Plot (Quarterly Nowcasting Model Data)*

### 1. Correlation Plot (Quarterly Nowcasting Model Data)  __________________________________ 6

### 1. Correlation Plot (Quarterly Nowcasting Model Data)

### Overview
- Purpose: Use machine learning (ML) to nowcast Lesotho GDP growth in real time given delayed and frequently revised official GDP data.
- Key questions addressed:
  - What is GDP growth at present?
  - Is economic activity under- or over-estimated by the standard statistics?
  - Where is inflation heading? (contextual aim—GDP nowcasting section focuses on the first two questions)
- Data context: Lesotho faces delayed and frequently revised quarterly GDP, an outdated base year (2012) for GDP, and a structural shift toward a larger informal economy since the pandemic in 2020-21.

### Methodology and ML Fundamentals
- ML focus: prioritize out-of-sample predictive accuracy rather than inference or causal identification.
- Validation approaches described:
  - Holdout validation: split into training and testing sets to compute validation error.
  - Cross validation: K-fold example (K=3) and applied 5-fold cross validation to tune hyperparameters and assess models.
- Interpretability tools:
  - Variable importance via scrambling each variable to measure impact on model performance.
  - Shapley Values used to explain contributions of variables to individual predictions.

### Nowcasting Model Specification
- Predictor set: 29 possible predictors including trade-related variables, fiscal outturns (water royalties, government spending), activity in South Africa (PMI, business confidence), electricity consumption, tax revenues (PAYE Receipts, VAT), REER, CPI, and alternative data (e.g., Google searches on “travel to Lesotho”).
- Data split for model evaluation:
  - Training set: 48 quarterly observations leading up to Q4 2022.
  - Testing set: 4 quarterly observations in 2023.
- Models evaluated: eight different model types ranging from OLS to a neural net (Appendix A).
- Model selection: 5-fold cross validation used to optimize models and tune hyperparameters; models ranked by validation performance (“horserace”).

### Model Comparison and Ensemble Construction
- Horserace outcome on training-set validation: Support Vector Machine (SVM) with a linear kernel identified as most likely to perform well out of sample; classic OLS performed worst.
- Horserace stability: rankings changed significantly when judged only on the small test set, indicating potential instability of single-model selection.
- Ensemble approach:
  - Built to stabilize nowcasts by combining predictions from candidate models.
  - Ensemble weights determined optimally via 5-fold cross validation across the training set.
  - Final ensemble: a weighted average of five types of model, with most of the weight given to the SVM (linear) model and the Extreme Gradient Boosting (“XGBoost”) model.
  - Ensemble constructed via a Lasso regression of GDP growth using predictions from a pool of candidate models (including a broader set of top-performing hyperparameter combinations).

### Variable Importance (Ensemble Results)
- Correlation structure: strong cluster of predictors associated with GDP growth, including trade-related indicators, electricity consumption, and tax revenue; a second cluster largely comprises indicators from South Africa.
- Most important predictors for the ensemble (variable-importance ranking):
  - Leading indicator of activity in South Africa (highest importance; scrambling this variable does the most damage to model performance).
  - Imports from South Africa.
  - Tax revenues.
  - Textile exports to the USA.
  - (Alternative data such as Google trends included in the predictor set.)

### Nowcast Results and Drivers
- Temporal pattern: Lesotho’s real GDP growth improved significantly in Q1-2024 after bottoming out in Q3-2023.
- Exact nowcast figures:
  - 0.5 percent at end-2023
  - 1.8 percent in March 2024
- Shapley Value decomposition for March 2024 nowcast:
  - Main upward contributors: strong boost in water royalties; improvement in textile exports to the USA.
  - Main downward contributor: lower exports to South Africa.

*Source: 1lsoea2024002-print-pdf - 1. Correlation Plot (Quarterly Nowcasting Model Data)*

### 18.      In this section, real GDP series are empirically evaluated using historical quarterly data.

### 1lsoea2024002-print-pdf - 18.      In this section, real GDP series are empirically evaluated using historical quarterly data.

### Real GDP evaluation: motivation and approach
- Motivation
  - Potential misestimation of real economic activity by Lesotho’s Bureau of Statistics due to lack of data, capacity constraints, and other barriers common in developing countries.
  - The Covid-19 pandemic was a significant shock which may have notably impacted the informal economy, potentially changing previous sensitivities (e.g., to taxes, consumption, etc.).
- Methodology
  - Machine learning technique used: LASSO regression.
  - Estimation sample: 40 observations covering the period prior to the pandemic (i.e., Q1-2010 – Q4-2019).
  - Goal: track closely the actual series; validated by in-sample fit close to 1, with an R2 higher than 0.9.
- Regressor set
  - Standard macroeconomic indicators, fiscal variables, and alternative series such as night lights, air pollution, and precipitation.
  - Most relevant variables selected by LASSO are related to fiscal outturns, validating the large footprint of the government in the economy.
  - Specific selected variables and their importance:
    - Government’s goods and services variable: highest standardized coefficient (2.4).
    - Water royalties and fiscal balance: selected as significant.
    - Water consumption and imports of construction materials: equally relevant.
    - From alternative sources: air pollution and Google searches selected, helping avoid overfitting and multicollinearity.

### Key findings on GDP estimation bias
- Out-of-sample deviations (post-pandemic, 2020–2023)
  - Predicted “out-of-sample” GDP series deviate significantly from the actual data over the post-pandemic period.
  - Estimated potential underestimation of real GDP close to 9 percent at end-2023.
  - The largest deviation is in 2022, with the estimated series being about 14 percent greater than the actual, potentially reflecting the lack of post-pandemic rebound and issues stemming from a larger informal sector.

### Inflation forecasting: objectives and data
- Motivation for improved forecasts
  - Inflation has surprised to the upside in recent years due to sequential exogenous shocks (pandemic demand resurgence, higher food/cereal prices because of the war in Ukraine, supply-chain disruptions).
  - Inflation rates in Lesotho and South Africa diverged in 2023–24 primarily due to a larger share of food items in Lesotho’s CPI basket; trends started to slowly converge in 2024.
  - Systematic forecasting errors may misestimate fiscal and other variables, potentially leading to welfare costs.
- Data and predictors
  - Inflation series in Lesotho: 70 quarterly observations.
  - Large set of regressors includes global (oil, international food prices, Baltic Freight Index), regional (South Africa indicators including inflation expectations, leading indicators, business satisfaction, PMIs), and local variables (nominal exchange rates, Rand to USD, business activity proxies).
  - Four lags are included for each predictor plus inflation lags to allow for delayed pass-through.
  - International prices for food and oil are obtained from the WEO database, which additionally offers forecasts for upcoming quarters based on futures markets.

### Models, cross-validation, and performance
- Models highlighted
  - Random Forests: ensemble technique, good at capturing nonlinearities.
  - Elastic Net Regression: regularization technique balancing Lasso and Ridge, parsimonious and explainable.
- Cross-validation scheme
  - Goal: forecast inflation four quarters ahead.
  - Training starts with the first five years and evaluates the next year; at each step expand training set by one year and shift testing set by one year until end of sample.
  - With 70 quarters, this yields 12 different training and testing sets.
  - Tuning parameters chosen to minimize the Mean Absolute Scaled Error (MASE).
- Out-of-sample performance
  - Elastic Net has the lowest RMSE compared to other models and the AR(4) benchmark for both South Africa and Lesotho.
  - For Lesotho: substantial improvement in RMSE compared to AR(4), with a reduction of about 30 percent at the median for the Elastic Net.
  - Variables selected by Elastic Net for Lesotho include South Africa’s inflation expectations, the leading indicator, the PMI, and international food prices.
  - For South Africa: out-of-sample improvement is smaller, with the median RMSE just under 1 for the Elastic Net; primary variables include business satisfaction and global oil prices among others.

### Inflation forecast outcomes and implications
- One-year-ahead forecasts (across models)
  - South Africa: one-year ahead predictions vary between 4.9 and 6.2 percent across the three models.
    - Elastic Net prediction is close to 5 percent at the end of Q1-2025.
  - Lesotho: one-year ahead forecasts range from 5.6 to 6.4 percent across models.
    - Elastic Net forecast ends FY24/25 at 5.9 percent and closely tracks the Random Forest.
- Key interpretation
  - Models consistently predict a narrower divergence between inflation trends in South Africa and Lesotho over the next four quarters, signaling further convergence.

### Conclusions and policy implications
- Data and policy challenge
  - Accurate and timely data are essential for policymakers; Lesotho faces delayed and often revised quarterly GDP data, absence of high-frequency measures, coordination issues among public agencies, and an outdated GDP base.
  - The pandemic likely expanded the informal economy’s share, complicating measurement.
- Role of machine learning
  - ML techniques provide a flexible framework for nowcasting and forecasting focused on prediction accuracy over causality.
  - In Lesotho, ML helps circumvent data scarcity by leveraging alternative datasets to provide real-time insights into GDP growth, evaluate potential bias in standard statistics, and improve inflation forecasts amidst global and regional shocks.
- Policy takeaways
  - Use ML-based estimates as complementary inputs to official statistics to reduce risks from mismeasured GDP and misforecasted inflation.
  - Incorporate alternative data sources (e.g., air pollution, Google searches, imports of construction materials, water consumption) and fiscal variables into monitoring systems to better capture informal activity and government footprint.
  - Adopt Elastic Net and ensemble approaches (Random Forests) for inflation forecasting to improve RMSE relative to AR(4) benchmarks and to better capture turning points and convergence dynamics between Lesotho and South Africa.

*Source: https://www.imf.org/-/media/files/publications/cr/2024/english/1lsoea2024002-print-pdf.pdf*

---


_Source: https://www.imf.org/-/media/files/publications/cr/2024/english/1lsoea2024002-print-pdf.pdf_
