0% found this document useful (0 votes)
2 views

Topic 2 - Code

The document outlines a statistical analysis process using R, including data preparation, unit root testing, and ARDL model selection for forecasting unemployment based on GDP growth and inflation. It details the steps for conducting ADF tests to check for stationarity, selecting the best ARDL model, and refitting the model for forecasting. Finally, it demonstrates how to predict unemployment under a hypothetical scenario using the fitted model.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Topic 2 - Code

The document outlines a statistical analysis process using R, including data preparation, unit root testing, and ARDL model selection for forecasting unemployment based on GDP growth and inflation. It details the steps for conducting ADF tests to check for stationarity, selecting the best ARDL model, and refitting the model for forecasting. Finally, it demonstrates how to predict unemployment under a hypothetical scenario using the fitted model.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

# === 1.

Load Required Packages ===

install.packages(c("readxl", "dplyr", "tseries", "ARDL"))

library(readxl)

library(dplyr)

library(tseries)

library(ARDL)

# === 2. Import and Prepare Data ===

rename(

GDPG = `GDP growth (annual %)`,

INFL = `Inflation, consumer prices (annual %)`,

UNEMP = `Unemployment, total (% of total labor force) (modeled ILO


estimate)`

# === 3. ADF Unit Root Test ===

adf.test(data$GDPG) # Non-stationary at level

adf.test(data$INFL) # Non-stationary at level

adf.test(data$UNEMP) # Non-stationary at level

adf.test(diff(data$GDPG)) # Check at first difference

adf.test(diff(data$INFL))

adf.test(diff(data$UNEMP))

# === 4. ARDL Model Selection ===

ardl_model <- auto_ardl(UNEMP ~ GDPG + INFL, data = data, max_order =


3)
best_ardl <- ardl_model$best_model

summary(best_ardl)

# === 5. Bounds Test for Cointegration ===

bounds_f_test(best_ardl, case = 3)

# === 6. Refit ARDL as lm() for Forecasting ===

data <- data %>%

mutate(

UNEMP_L1 = lag(UNEMP, 1),

UNEMP_L2 = lag(UNEMP, 2),

GDPG_L1 = lag(GDPG, 1)

data2 <- na.omit(data) # Remove NA due to lags

lm_model <- lm(UNEMP ~ UNEMP_L1 + UNEMP_L2 + GDPG + GDPG_L1 +


INFL, data = data2)

summary(lm_model)

# === 7. Forecast Under a Hypothetical Scenario ===

newdata <- data.frame(

UNEMP_L1 = 2.2,

UNEMP_L2 = 2.25,

GDPG = 6.0,

GDPG_L1 = 5.5,

INFL = 4.5
)

predict(lm_model, newdata = newdata)

You might also like