A34_MAE118_GRUPO

Tarea A34

Métodos para el Análisis Económico GT-03

Docente: Carlos Ademir Pérez Alas

Ciclo II - 2024

Integrantes:

Carpaño Benites, Brandon Edenilson CB22013
Jimenez Carrillo, Sabrina Elizabeth JC22006
López Cabrera, Katherine Lissette LC22029

Indicaciones generales: Aplique el filtro HP para cada uno de los países de Centroamérica, para los periodos disponibles para cada país.

• Represente sus resultados de forma gráfica:

    1. Usando la versión personalizada y
    1. Usando la representación rápida.
    1. En todos los gráficos indique el país y el periodo al que corresponden los datos.

- Datos de PIB Trimestral de los paises de Centro América

library(tidyr)
library(tidyverse)
library(dplyr)
library(readxl)
library(forecast)
library(kableExtra)
library(mFilter)

# Carga de los datos
Data_PIB <- read_excel("C:/Users/MovilDell/Downloads/datos_PIB_trim_CA (1).xlsx", skip = 5)
colnames(Data_PIB) <- c("Fecha", "Costa_Rica", "El_Salvador", "Guatemala", 
                        "Honduras", "Nicaragua", "RD", "Panama")
Data_PIB$Costa_Rica <- as.numeric(Data_PIB$Costa_Rica)
Data_PIB$El_Salvador<- as.numeric(Data_PIB$El_Salvador)
Data_PIB$Guatemala<- as.numeric(Data_PIB$Guatemala)
  Data_PIB$Honduras<- as.numeric(Data_PIB$Honduras)
  Data_PIB$Nicaragua<- as.numeric(Data_PIB$Nicaragua)
  Data_PIB$RD<- as.numeric(Data_PIB$RD)
  Data_PIB$Panama<- as.numeric(Data_PIB$Panama)
  
#  tabla estilizada e interactiva
Data_PIB %>% 
  kable(caption = "PIB por trimestres de los países de Centroamérica", align = "c", digits = 2) %>%  
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), 
                full_width = FALSE, 
                position = "center") %>% 
  scroll_box(width = "100%", height = "400px") %>% 
  footnote(general = "Elaboración propia con datos de Secretaría Ejecutiva del Consejo Monetario Centroamericano    en Millones de Moneda Nacional",
           general_title = "Fuente:", 
           footnote_as_chunk = TRUE)
PIB por trimestres de los países de Centroamérica
Fecha Costa_Rica El_Salvador Guatemala Honduras Nicaragua RD Panama
1990-I NA 48.97 NA NA NA NA NA
1990-II NA 56.32 NA NA NA NA NA
1990-III NA 56.41 NA NA NA NA NA
1990-IV NA 59.88 NA NA NA NA NA
1991-I 2730298 50.54 NA NA NA 43.20 NA
1991-II 2585733 58.01 NA NA NA 40.69 NA
1991-III 2614917 56.98 NA NA NA 37.78 NA
1991-IV 2873790 59.37 NA NA NA 41.06 NA
1992-I 2966525 53.82 NA NA NA 46.32 NA
1992-II 2788824 59.47 NA NA NA 46.39 NA
1992-III 2963548 61.02 NA NA NA 42.25 NA
1992-IV 3079994 66.38 NA NA NA 46.04 NA
1993-I 3217280 58.28 NA NA NA 49.16 NA
1993-II 2995772 64.10 NA NA NA 50.26 NA
1993-III 3112131 64.13 NA NA NA 46.68 NA
1993-IV 3311098 68.18 NA NA NA 48.23 NA
1994-I 3326797 59.02 NA NA NA 51.45 NA
1994-II 3204764 66.44 NA NA NA 50.63 NA
1994-III 3254567 68.02 NA NA NA 47.21 NA
1994-IV 3421190 73.16 NA NA NA 50.08 NA
1995-I 3579342 63.70 NA NA NA 52.71 NA
1995-II 3296179 71.95 NA NA NA 53.09 NA
1995-III 3327732 70.06 NA NA NA 50.87 NA
1995-IV 3552691 73.55 NA NA NA 54.05 NA
1996-I 3565450 65.03 NA NA NA 58.08 2749.87
1996-II 3309375 70.82 NA NA NA 55.34 2833.49
1996-III 3386476 71.02 NA NA NA 53.21 2929.32
1996-IV 3680411 74.67 NA NA NA 56.69 3102.78
1997-I 3632809 67.54 NA NA NA 61.14 2879.11
1997-II 3554621 74.72 NA NA NA 62.16 3012.00
1997-III 3562233 72.10 NA NA NA 57.88 3140.23
1997-IV 3955521 76.01 NA NA NA 61.97 3338.59
1998-I 4027204 69.01 NA NA NA 66.53 3141.11
1998-II 3758269 77.03 NA NA NA 66.11 3189.71
1998-III 3784926 74.15 NA NA NA 61.19 3369.47
1998-IV 4186986 77.88 NA NA NA 65.64 3582.31
1999-I 4119646 71.75 NA NA NA 68.07 3329.58
1999-II 3963344 77.98 NA NA NA 68.24 3365.15
1999-III 3982567 75.28 NA NA NA 67.23 3510.98
1999-IV 4355972 79.51 NA NA NA 71.35 3593.06
2000-I 4355808 72.25 NA 26904.1 NA 72.59 3356.21
2000-II 4101429 77.62 NA 26411.5 NA 72.27 3452.64
2000-III 4133379 77.25 NA 25580.3 NA 70.21 3605.78
2000-IV 4466217 80.83 NA 27758.3 NA 72.64 3761.93
2001-I 4492066 74.45 70060.6 27539.0 NA 72.75 3393.13
2001-II 4252053 79.89 66509.1 27279.6 NA 73.40 3535.50
2001-III 4299653 76.43 66314.4 26057.8 NA 73.08 3591.36
2001-IV 4608543 79.88 71106.3 28682.6 NA 75.55 3735.60
2002-I 4540875 73.57 72155.3 27872.3 NA 77.13 3464.39
2002-II 4487161 81.08 69896.2 28330.8 NA 78.42 3595.61
2002-III 4463358 78.87 70306.1 27887.0 NA 75.86 3645.23
2002-IV 4764078 82.03 73264.1 29581.7 NA 76.63 3870.08
2003-I 4777050 75.36 75441.3 29205.7 NA 77.11 3637.61
2003-II 4616263 81.45 71542.1 29351.9 NA 75.79 3602.80
2003-III 4655788 80.02 71890.5 28745.4 NA 74.43 3787.39
2003-IV 4994493 83.66 74221.7 31537.5 NA 76.57 4164.20
2004-I 4993891 75.21 76687.7 31243.6 NA 76.42 3841.31
2004-II 4848763 82.05 73508.5 31422.6 NA 77.81 3984.70
2004-III 4842796 81.05 74000.4 30365.0 NA 76.98 4132.04
2004-IV 5200747 85.03 77600.2 33215.9 NA 80.50 4376.58
2005-I 5113301 77.05 79264.0 32736.2 NA 82.86 4137.10
2005-II 5063679 84.79 77149.5 33181.3 NA 84.57 4291.52
2005-III 5066035 82.53 75770.3 33089.5 NA 85.65 4433.68
2005-IV 5433990 87.73 78863.6 34879.1 NA 88.01 4643.55
2006-I 5446096 82.08 83160.0 35036.3 28987.86 91.15 4451.51
2006-II 5374475 85.85 79399.4 34781.2 28667.29 93.25 4617.67
2006-III 5452618 85.77 80781.3 34936.5 29700.87 92.06 4846.02
2006-IV 5918756 92.82 85047.2 37924.4 31481.69 95.92 5080.04
2007-I 5941002 81.93 88341.8 37124.8 30059.68 97.42 4958.99
2007-II 5876425 87.46 85226.5 37514.4 30056.63 99.05 5139.47
2007-III 5895619 88.36 85488.2 37401.8 31256.30 100.00 5446.92
2007-IV 6301998 95.22 89195.0 39466.7 33497.72 103.53 5750.61
2008-I 6353425 86.45 90929.6 39268.3 31814.30 104.43 5572.24
2008-II 6249097 91.57 90145.1 39972.6 32321.11 106.55 5836.87
2008-III 6172702 89.31 88192.3 38699.8 32459.81 99.98 5958.27
2008-IV 6377695 93.15 91738.9 39978.3 32565.29 101.87 6027.46
2009-I 6219211 85.02 90819.8 38320.7 30132.42 101.53 5796.88
2009-II 6095089 89.48 89285.9 38187.2 30322.27 104.42 5880.12
2009-III 6129268 86.97 89414.1 37387.3 31508.30 102.35 5969.67
2009-IV 6489651 91.50 93767.9 40184.1 32944.70 108.45 6038.97
2010-I 6543471 87.43 93561.1 39323.9 31268.78 110.53 6078.01
2010-II 6444314 90.60 92080.5 39666.1 31385.75 113.45 6142.05
2010-III 6485904 88.21 91027.2 38982.1 33011.38 110.71 6193.38
2010-IV 6796036 94.15 96812.0 41855.6 34750.34 116.82 6652.59
2011-I 6830432 90.54 97288.7 41170.6 33039.77 115.44 6705.98
2011-II 6754869 94.93 96227.0 40672.4 33822.61 117.33 6857.67
2011-III 6736463 92.01 96247.7 41104.0 35402.73 113.83 6995.84
2011-IV 7104660 96.66 100318.9 43011.3 36389.13 119.06 7342.42
2012-I 7256417 93.18 101001.4 43235.8 36059.08 119.13 7491.31
2012-II 7035456 97.68 98806.4 42583.3 35399.45 120.16 7544.19
2012-III 7048733 94.65 98662.2 42143.0 36736.70 116.87 7642.55
2012-IV 7424937 99.17 103889.3 44848.1 39466.17 122.14 7952.34
2013-I 7367777 93.62 103960.2 43855.1 37306.03 121.47 7997.02
2013-II 7232407 99.65 103201.3 43944.4 37876.49 125.44 8086.86
2013-III 7278082 98.01 102372.5 43461.8 38999.42 124.19 8269.80
2013-IV 7604910 101.99 106849.2 46373.1 40754.88 130.52 8391.26
2014-I 7695243 97.74 108289.6 45396.4 39364.57 130.81 8348.21
2014-II 7457872 101.65 107649.8 45353.9 39419.67 133.74 8471.89
2014-III 7507164 98.61 106782.8 44544.9 40398.30 132.46 8698.90
2014-IV 7867224 102.00 112165.0 47771.3 43168.73 139.98 8885.00
2015-I 7855850 99.62 113343.7 47000.0 41227.05 138.04 8873.05
2015-II 7803053 102.86 111016.1 46586.2 40584.24 143.60 8948.57
2015-III 7869383 101.85 112035.4 46271.4 42950.22 143.57 9174.19
2015-IV 8114106 105.25 116288.4 50238.8 45370.06 148.97 9380.47
2016-I 8211415 99.90 115243.1 48840.6 42825.43 147.27 9283.80
2016-II 8104163 107.30 115126.3 48401.6 43397.41 155.44 9419.84
2016-III 8128500 104.55 114354.3 47726.9 44466.39 152.70 9574.16
2016-IV 8528662 108.25 120081.8 52527.8 47205.69 157.01 9900.35
2017-I 8529336 103.33 120681.0 51266.4 46064.02 155.86 9883.21
2017-II 8478427 108.32 117991.7 50527.4 45056.54 160.20 9930.62
2017-III 8420388 106.60 117906.1 50161.5 45915.50 157.59 10099.97
2017-IV 8915497 111.20 122542.0 55106.1 49097.55 167.35 10399.02
2018-I 8813605 105.95 123950.2 52737.4 47235.68 166.46 10291.17
2018-II 8823861 110.96 123024.8 52418.5 42777.77 171.90 10225.86
2018-III 8647835 109.65 122027.8 52202.2 43920.98 169.51 10422.31
2018-IV 8956744 113.26 126441.0 57664.9 45938.83 177.88 10859.15
2019-I 9014525 109.05 128558.7 54385.4 42875.96 176.00 10609.18
2019-II 8889155 112.73 127734.5 53272.7 41833.31 178.34 10502.69
2019-III 8867783 112.48 126950.6 53765.8 43228.78 177.85 10714.49
2019-IV 9322563 116.26 132106.5 59102.8 46724.52 188.21 11217.60
2020-I 9162255 108.51 129609.1 53369.5 43942.87 175.98 10663.00
2020-II 8176862 90.18 115922.0 43367.1 39073.34 148.22 6457.81
2020-III 8269014 102.86 125171.4 49493.5 42796.00 165.03 8237.34
2020-IV 8943469 113.41 135445.9 54526.1 45784.13 182.75 9961.64
2021-I 9071116 111.82 135416.2 54495.1 45546.95 181.51 9769.37
2021-II 9020717 116.06 134011.5 54733.4 46088.26 185.94 9039.12
2021-III 9314559 115.93 135457.0 55641.5 47216.99 183.92 10337.66
2021-IV 9887141 120.57 141924.0 61111.8 50445.71 203.09 11590.22
2022-I 9676443 117.26 141826.2 57699.8 47728.86 192.66 11097.20
2022-II 9408896 119.02 140382.2 57463.3 48200.76 195.45 9925.70
2022-III 9565833 118.61 140792.4 57976.9 48830.34 193.14 11317.69
2022-IV 10339772 122.48 146774.7 62205.6 51641.29 209.85 NA
2023-I 10101831 119.20 147507.1 59237.9 49388.19 195.42 NA
2023-II 9968711 124.54 146162.0 59058.0 49915.20 197.41 NA
2023-III 10092491 122.56 146456.1 59835.0 51753.08 198.22 NA
2023-IV 10821098 127.81 149745.1 65646.1 54319.34 218.73 NA
2024-I 10462584 122.28 152204.6 61190.3 51802.20 203.52 NA
2024-II 10493742 127.17 151637.3 61376.7 52123.09 209.32 NA
Fuente: Elaboración propia con datos de Secretaría Ejecutiva del Consejo Monetario Centroamericano en Millones de Moneda Nacional

Costa Rica

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(Costa_Rica))
Costa_Rica_ts <- ts(Data_PIB$Costa_Rica, start = c(1991,1), frequency = 4)


hp_cr <- hpfilter(Costa_Rica_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_cr$trend
cycle <- hp_cr$cycle

# grafico 

plot(Costa_Rica_ts, type = "l", main = "Filtro de Hodrick-Prescott Costa Rica  (trimestre I 1991 - trimestre II 2024)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_cr,ask = FALSE)

El Salvador

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(El_Salvador))
El_Salvador_ts <- ts(Data_PIB$El_Salvador, start = c(1990,1), frequency = 4)


hp_sv <- hpfilter(El_Salvador_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_sv$trend
cycle <- hp_sv$cycle

# gráfico 

plot(El_Salvador_ts, type = "l", main = "Filtro de Hodrick-Prescott El Salvador, (trimestre I 1990 - trimestre II 2024)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_sv,ask = FALSE)

Guatemala

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(Guatemala))
Guatemala_ts <- ts(Data_PIB$Guatemala, start = c(2001,1), frequency = 4)


hp_gt <- hpfilter(Guatemala_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_gt$trend
cycle <- hp_gt$cycle

# grafico 

plot(Guatemala_ts, type = "l", main = "Filtro de Hodrick-Prescott Guatemala, (trimestre I 2001 - trimestre II 2024)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_gt,ask = FALSE)

Honduras

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(Honduras))
Honduras_ts <- ts(Data_PIB$Honduras, start = c(1999,1), frequency = 4)


hp_hn <- hpfilter(Honduras_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_hn$trend
cycle <- hp_hn$cycle

# grafico 

plot(Honduras_ts, type = "l", main = "Filtro de Hodrick-Prescott Honduras, (trimestre I 1999 - trimestre II 2024)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_hn,ask = FALSE)

Nicaragua

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(Nicaragua))
Nicaragua_ts <- ts(Data_PIB$Nicaragua, start = c(2006,1), frequency = 4)


hp_nic <- hpfilter(Nicaragua_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_nic$trend
cycle <- hp_nic$cycle

# grafico 

plot(Nicaragua_ts, type = "l", main = "Filtro de Hodrick-Prescott Nicaragua, (trimestre I 2006 - trimestre II 2024)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_nic,ask = FALSE)

Republica dominicana

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(RD))
RD_ts <- ts(Data_PIB$RD, start = c(1991,1), frequency = 4)


hp_RD <- hpfilter(RD_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_RD$trend
cycle <- hp_RD$cycle

# grafico 

plot(RD_ts, type = "l", main = "Filtro de Hodrick-Prescott República Dominicana, (T I 1991 - T II 2024)", ylab = "PIB", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_RD,ask = FALSE)

Panama

Implementación Personalizada

Data_PIB <- Data_PIB %>% filter(!is.na(Panama))
Panama_ts <- ts(Data_PIB$Panama, start = c(1996,1), frequency = 4)


hp_Panama <- hpfilter(Panama_ts, freq = 1600)

# Extrae la tendencia y el componente cíclico
trend <- hp_Panama$trend
cycle <- hp_Panama$cycle

# grafico 

plot(Panama_ts, type = "l", main = "Filtro de Hodrick-Prescott Panama, (trimestre I 1996 - trimestre III 2022)", ylab = "PIB en Millones", xlab = "Tiempo")
lines(trend, col = "red", lwd = 2 )
legend("topleft", legend = c("PIB Original", "Tendencia (Filtro HP)"), col = c("black", "red"), lty = 1, lwd = 2)

Implementación rápida

plot(hp_Panama,ask = FALSE)