library(readxl)
## Warning: package 'readxl' was built under R version 4.4.3
# EL SALVADOR
datos_PIB_trim_CA <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "C7:C144",
col_types = "numeric"
)
# GUATEMALA
PIBT_GT <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "D51:D144",
col_types = "numeric"
)
# HONDURAS
PIBT_HN <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "E47:E144",
col_types = "numeric"
)
# NICARAGUA
PIBT_NI <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "F71:F144",
col_types = "numeric"
)
# COSTA RICA
PIBT_CR <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "B11:B144",
col_types = "numeric"
)
# PANAMÁ
PIBT_PA <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "H31:H137",
col_types = "numeric"
)
# REPÚBLICA DOMINICANA
PIBT_RD <- read_excel(
"C:/Users/Latitude_7390/Downloads/datos_PIB_trim_CA.xlsx",
range = "G11:G144",
col_types = "numeric"
)
EL SALVADOR
library(mFilter)
## Warning: package 'mFilter' was built under R version 4.4.3
library(forecast)
## Warning: package 'forecast' was built under R version 4.4.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
datos_PIB_trim_CA <- ts(datos_PIB_trim_CA , start = c(2006, 1), frequency = 4)
# aplicando el filtro hp y escogiendo el valor de lambda de 1600 dado que es trimestral
hp_SV <- hpfilter(datos_PIB_trim_CA , freq = 1600)
trend_SV <- hp_SV$trend
cycle_SV <- hp_SV$cycle
Implementación Personalizada
plot(
datos_PIB_trim_CA,
type = "l",
col = "blue",
main = "EL SALVADOR (1990 I - 2024 II) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_SV, col = "red", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("blue", "red"),
lty = 1,
lwd = 2
)
plot(
cycle_SV,
type = "l",
main = "EL SALVADOR (1990 I - 2024 II) - Componente Ciclico",
ylab = "Ciclo",
xlab = "Tiempo"
)
Implementación más rápida del gráfico
plot(hp_SV, ask = FALSE)
GUATEMALA
PIBT_GT <- ts(PIBT_GT, start = c(2006, 1), frequency = 4)
hp_GT <- hpfilter(PIBT_GT, freq = 1600)
trend_GT <- hp_GT$trend
cycle_GT <- hp_GT$cycle
Implementación Personalizada
plot(
PIBT_GT,
type = "l",
col = "blue",
main = "GUATEMALA (2001 I - 2024 II) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_GT, col = "red", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("blue", "red"),
lty = 1,
lwd = 2
)
plot(
cycle_GT,
type = "l",
main = "GUATEMALA (2001 I - 2024 II) - Componente Ciclico",
ylab = "Ciclo",
xlab = "Tiempo"
)
plot(hp_GT, ask = FALSE)
HONDURAS
PIBT_HN <- ts(PIBT_HN, start = c(2006, 1), frequency = 4)
hp_HN <- hpfilter(PIBT_HN, freq = 1600)
trend_HN <- hp_HN$trend
cycle_HN <- hp_HN$cycle
Implementación Personalizada
plot(
PIBT_HN,
type = "l",
col = "blue",
main = "HONDURAS (2000 I - 2024 II) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_HN, col = "red", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("blue", "red"),
lty = 1,
lwd = 2
)
plot(
cycle_HN,
type = "l",
main = "HONDURAS (2000 I - 2024 II) - Componente Ciclico",
ylab = "Ciclo",
xlab = "Tiempo"
)
plot(hp_HN, ask = FALSE)
NICARAGUA
PIBT_NI <- ts(PIBT_NI, start = c(2006, 1), frequency = 4)
hp_NI <- hpfilter(PIBT_NI, freq = 1600)
trend_NI <- hp_NI$trend
cycle_NI <- hp_NI$cycle
Implementación Personalizada
plot(
PIBT_NI,
type = "l",
col = "blue",
main = "NICARAGUA (2006 I - 2024 II) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_NI, col = "red", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("blue", "red"),
lty = 1,
lwd = 2
)
plot(
cycle_NI,
type = "l",
main = "NICARAGUA (2006 I - 2024 II) - Componente Ciclico",
ylab = "Ciclo",
xlab = "Tiempo"
)
plot(hp_NI, ask = FALSE)
COSTA RICA
PIBT_CR <- ts(PIBT_CR, start = c(2006, 1), frequency = 4)
hp_CR <- hpfilter(PIBT_CR, freq = 1600)
trend_CR <- hp_CR$trend
cycle_CR <- hp_CR$cycle
Implementación Personalizada
PIBT_PA <- ts(PIBT_PA, start = c(2006, 1), frequency = 4)
hp_PA <- hpfilter(PIBT_PA, freq = 1600)
trend_PA <- hp_PA$trend
cycle_PA <- hp_PA$cycle
Implementación Personalizada
plot(
PIBT_PA,
type = "l",
main = "PANAMÁ (1996 I - 2022 III) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_PA, col = "green", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("black", "green"),
lty = 1,
lwd = 2
)
REPÚBLICA DOMINICANA
PIBT_RD <- ts(PIBT_RD, start = c(2006, 1), frequency = 4)
hp_RD <- hpfilter(PIBT_RD, freq = 1600)
trend_RD <- hp_RD$trend
cycle_RD <- hp_RD$cycle
Implementación Personalizada
plot(
PIBT_RD,
type = "l",
main = "REPÚBLICA DOMINICANA (1991 I - 2024 II) - Filtro de Hodrick-Prescott",
ylab = "PIB",
xlab = "Tiempo"
)
lines(trend_RD, col = "green", lwd = 2)
legend(
"topleft",
legend = c("PIB Original", "Tendencia (Filtro HP)"),
col = c("black", "green"),
lty = 1,
lwd = 2
)