This repository implements a Structural Dynamic Factor Model (SDFM) based on the methodology of Alessio and Kerssenfischer (2019). The model provides a framework for analyzing macroeconomic time series data through the lens of dynamic factors.
The SDFM approach combines dimension reduction techniques with structural analysis to identify economic shocks and analyze their propagation through the economy. The implementation follows these main steps:
- Factor Selection: Determining the optimal number of static and dynamic factors using Bai & Ng (2002) criteria and Amengual & Watson (2007) method.
- Factor Estimation: Extracting static factors via Principal Component Analysis and dynamic factors through VAR residuals.
- Impulse Response Analysis: Computing and visualizing the responses of economic variables to structural shocks.
The repository is organized into the following main components:
-
📄 factor_estimation.R: Contains functions for factor selection and estimation, including:
bai_ng_criteria()
: Implementation of Bai & Ng information criteria.amengual_watson()
: Method for determining dynamic factors.estimate_dfm()
: Main function for estimating the dynamic factor model.
-
📄 impulse_response.R: Functions for impulse response analysis:
compute_irf_dfm()
: Calculates impulse responses with bootstrap confidence intervals.plot_irf()
: Visualizes impulse response functions.
The model works by:
- Standardizing the data using first differences.
- Extracting static factors through PCA.
- Fitting a VAR model to the static factors with Kilian bias correction.
- Identifying dynamic factors from VAR residuals.
- Computing impulse response functions through bootstrapping.
# Load required functions
source("R/factor_estimation.R")
source("R/impulse_responde.R")
# Load and preprocess data
data <- readr::read_csv("data/processed/final_data.csv") |>
dplyr::select(-ref.date) |>
tidyr::drop_na() |>
as.matrix()
# Determine optimal number of factors
bai_ng <- bai_ng_criteria(data, standardize = TRUE)
amengual <- amengual_watson(data, r = 7, p = 1, scale = TRUE)
# Estimate the model
r <- 7 # number of static factors
q <- 5 # number of dynamic factors
p <- 1 # VAR lag order
dfm_results <- estimate_dfm(data, r, q, p)
# Compute impulse responses
irf_results <- compute_irf_dfm(dfm_results, h = 50, nboot = 800)
# Plot responses for selected variables
response_vars <- list(
"Variable 1" = 1,
"Variable 2" = 2
)
plot_irf(irf_results, response_vars, shock = 1)
- Alessi, L., & Kerssenfischer, M. (2019). The response of asset prices to monetary policy shocks: Stronger than thought. Journal of Applied Econometrics, 34(5), 661-672.
- Bai, J., & Ng, S. (2002). "Determining the Number of Factors in Approximate Factor Models Econometrica, 70(1), 191-221.
- Amengual, D., & Watson, M. W. (2007). "Consistent Estimation of the Number of Dynamic Factors in a Large N and T Panel." Journal of Business & Economic Statistics, 25(1), 91-96.
- Stock, J. H., & Watson, M. W. (2016). "Dynamic Factor Models, Factor-Augmented Vector Autoregressions, and Structural Vector Autoregressions in Macroeconomics." Handbook of Macroeconomics, 2, 415-525.