# Load necessary libraries library(stats) library(dplyr) #create lagged data # Generate some example data (replace this with your actual data) # Let's assume 'data' is a data frame with columns: past_inflation, unemployment_gap, output_gap, and target_inflation # You should replace this with your actual data # Create a data frame with example data output_gap <- read.csv("C:/Work/DMU Teaching/ECON 5001/Block teaching/Block 6/UK_annual_output_gap.csv", sep = ",", header = TRUE) CPI_data <- read.csv("C:/Work/DMU Teaching/ECON 5001/Block teaching/Block 6/UK_annual_inflation.csv", sep = ",", header = TRUE) CPI <- CPI_data$CPI.INDEX.00..ALL.ITEMS.2015.100 CPI_L1 <- dplyr::lag(CPI, n=1) inflation <- (CPI-CPI_L1)/CPI_L1*100 inflation_L1 <- dplyr::lag(inflation, n=1) #remove the first two years as there are no lags inflation <- inflation[3:27] inflation_L1 <- inflation_L1[3:27] output_gap <- output_gap[3:27,4] data <- data.frame(y=inflation, x1=inflation_L1, x2=output_gap) # Fit a linear regression model model <- lm(y ~ x1 + x2, data = data) # Summary of the regression model summary(model) # Predict inflation in 2023 using the model new_data <- data.frame( x1 = c(inflation[25]), x2 = c(-2.4) #you can put any current inflation number in this ) inflation_2023 <- predict(model, newdata = new_data) print(inflation_2023) # Predict inflation in 2024 using the model new_data <- data.frame( x1 = c(inflation_2023), x2 = c(-2.6) #you can put any current inflation number in this ) inflation_2024 <- predict(model, newdata = new_data) # Print the predicted inflation print(inflation_2024)