Para este trabajo tomaremos datos desde 1990 hasta 2021, la idea es probar si el crecimiento económico génera que haya más igualdad.
Cargamos el documento
#install.packages("readxl")#
#install.packages("tidyverse")#
#install.packages("tseries")
#install.packages("car")
#install.packages("timsac")
# Instalar el paquete "urca" (solo si aún no está instalado)
#install.packages("urca")
#install.packages("readxl")
# Cargar el paquete "urca"
library(readxl)
library(urca)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(lubridate)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(foreign)
library(timsac)
data <- read_excel("C:\\Users\\david\\Desktop\\UNAL\\Octavo Semestre\\Eco II\\ginipib.xlsx")
Ahora, vamos a ajustar la variable tiempo
data$Año <- NULL
# Cambiar los nombres de las columnas en un marco de datos data
colnames(data) <- c("gini", "pib")
gini.ts = ts(data$gini, start = 1990, frequency = 1)
pib.ts = ts(data$pib, start = 1990, frequency = 1)
data$Año <- NULL
class(data$pib)
## [1] "numeric"
class(data$gini)
## [1] "numeric"
#Convierto PIB a variable en Log
data <- data %>%
mutate(lpib = log(pib.ts))
#hagamos lo mismo para lpib
lpib.ts = ts(data$lpib, start = 1990, frequency = 1)
plot(lpib.ts, main="Tendencia")
#Agrupemos ambos en un solo dataframe
datos=cbind(lpib.ts,gini.ts)
datos
## Time Series:
## Start = 1990
## End = 2021
## Frequency = 1
## lpib.ts gini.ts
## 1990 25.51482 0.523
## 1991 25.53464 0.513
## 1992 25.57429 0.515
## 1993 25.62674 0.538
## 1994 25.68326 0.541
## 1995 25.73398 0.562
## 1996 25.75433 0.569
## 1997 25.78806 0.567
## 1998 25.79374 0.538
## 1999 25.75079 0.569
## 2000 25.77962 0.569
## 2001 25.79626 0.587
## 2002 25.82099 0.587
## 2003 25.85942 0.575
## 2004 25.91138 0.560
## 2005 25.95854 0.536
## 2006 26.02355 0.550
## 2007 26.08876 0.539
## 2008 26.12106 0.553
## 2009 26.13240 0.543
## 2010 26.17636 0.546
## 2011 26.24353 0.535
## 2012 26.28191 0.526
## 2013 26.33198 0.526
## 2014 26.37599 0.526
## 2015 26.40512 0.510
## 2016 26.42578 0.506
## 2017 26.43928 0.497
## 2018 26.46460 0.504
## 2019 26.49597 0.513
## 2020 26.42068 0.535
## 2021 26.52519 0.515
siguiente, vamos a ver el autocorrelograma
autocorrelograma_pib <- acf(data$pib)
autocorrelograma_lpib <- acf(data$lpib)
autocorrelograma_gini <- acf(data$gini)
Pasamos al autocorrelograma parcial
autocorrelograma_parcial_pib <- pacf(data$pib)
autocorrelograma_parcial_lpib <- pacf(data$lpib)
autocorrelograma_parcial_gini <- pacf(data$gini)
plot(gini.ts)
plot(pib.ts)
Ahora, miremos estadística describtiva
summary(data)
## gini pib lpib
## Min. :0.4970 Min. :1.205e+11 Min. :25.51
## 1st Qu.:0.5210 1st Qu.:1.560e+11 1st Qu.:25.77
## Median :0.5380 Median :1.941e+11 Median :25.99
## Mean :0.5398 Mean :2.112e+11 Mean :26.03
## 3rd Qu.:0.5605 3rd Qu.:2.759e+11 3rd Qu.:26.34
## Max. :0.5870 Max. :3.309e+11 Max. :26.53
str(data)
## tibble [32 × 3] (S3: tbl_df/tbl/data.frame)
## $ gini: num [1:32] 0.523 0.513 0.515 0.538 0.541 0.562 0.569 0.567 0.538 0.569 ...
## $ pib : num [1:32] 1.20e+11 1.23e+11 1.28e+11 1.35e+11 1.43e+11 ...
## $ lpib: Time-Series [1:32] from 1990 to 2021: 25.5 25.5 25.6 25.6 25.7 ...
summary(gini.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.4970 0.5210 0.5380 0.5398 0.5605 0.5870
summary(pib.ts)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.205e+11 1.560e+11 1.941e+11 2.112e+11 2.759e+11 3.309e+11
Analizado lo anterior, comenzaremos por una prueba de estacionariedad para ambas variables, para ellos nos remitimos a un Test Dickey-Fuller aumentado
dfu_gini <- ur.df(gini.ts, type = "trend", lags = 1)
print(summary(dfu_gini))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.028021 -0.007229 -0.000387 0.007365 0.024475
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1796294 0.0665947 2.697 0.0121 *
## z.lag.1 -0.3074726 0.1179579 -2.607 0.0149 *
## tt -0.0007969 0.0003225 -2.471 0.0204 *
## z.diff.lag -0.0516674 0.1791724 -0.288 0.7754
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01332 on 26 degrees of freedom
## Multiple R-squared: 0.267, Adjusted R-squared: 0.1825
## F-statistic: 3.157 on 3 and 26 DF, p-value: 0.04157
##
##
## Value of test-statistic is: -2.6066 2.9041 4.3548
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -4.15 -3.50 -3.18
## phi2 7.02 5.13 4.31
## phi3 9.31 6.73 5.61
Ahora, hacemos lo mismo para el PIB
dfu_pib <- ur.df(pib.ts, type = "trend", lags = 1)
print(summary(dfu_gini))
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.028021 -0.007229 -0.000387 0.007365 0.024475
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.1796294 0.0665947 2.697 0.0121 *
## z.lag.1 -0.3074726 0.1179579 -2.607 0.0149 *
## tt -0.0007969 0.0003225 -2.471 0.0204 *
## z.diff.lag -0.0516674 0.1791724 -0.288 0.7754
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01332 on 26 degrees of freedom
## Multiple R-squared: 0.267, Adjusted R-squared: 0.1825
## F-statistic: 3.157 on 3 and 26 DF, p-value: 0.04157
##
##
## Value of test-statistic is: -2.6066 2.9041 4.3548
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -4.15 -3.50 -3.18
## phi2 7.02 5.13 4.31
## phi3 9.31 6.73 5.61
Miremos que tal se comportan los residuos, una forma de observar estacionariedad
modelo_ver_estacionariedad=lm(gini.ts ~ pib.ts)
summary(modelo_ver_estacionariedad)
##
## Call:
## lm(formula = gini.ts ~ pib.ts)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.045585 -0.012977 0.001351 0.014131 0.037097
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.848e-01 1.201e-02 48.705 < 2e-16 ***
## pib.ts -2.131e-13 5.423e-14 -3.929 0.000464 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.02042 on 30 degrees of freedom
## Multiple R-squared: 0.3397, Adjusted R-squared: 0.3177
## F-statistic: 15.44 on 1 and 30 DF, p-value: 0.0004642
residuales_mv=modelo_ver_estacionariedad$residuals
summary(residuales_mv)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.045585 -0.012977 0.001351 0.000000 0.014131 0.037097
residualPlot(modelo_ver_estacionariedad)
y=ur.df(residuales_mv)
summary(y)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.023150 -0.005587 0.002027 0.010266 0.025479
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -0.35349 0.12359 -2.860 0.00792 **
## z.diff.lag 0.01541 0.17335 0.089 0.92981
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01254 on 28 degrees of freedom
## Multiple R-squared: 0.2384, Adjusted R-squared: 0.184
## F-statistic: 4.382 on 2 and 28 DF, p-value: 0.0221
##
##
## Value of test-statistic is: -2.8601
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.62 -1.95 -1.61
En definitiva ambas series de tiempo son estacionarias, lo cual es un buen sintoma para seguir con el proceso, no se pierde información veamos la cointegración
X=ur.df(residuales_mv, type="trend", selectlags = "AIC" )
summary(X)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.0277274 -0.0065285 0.0008746 0.0075240 0.0211262
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0066706 0.0050023 1.333 0.1939
## z.lag.1 -0.3444974 0.1244848 -2.767 0.0103 *
## tt -0.0002838 0.0002675 -1.061 0.2985
## z.diff.lag -0.0228160 0.1760920 -0.130 0.8979
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01257 on 26 degrees of freedom
## Multiple R-squared: 0.28, Adjusted R-squared: 0.1969
## F-statistic: 3.37 on 3 and 26 DF, p-value: 0.0336
##
##
## Value of test-statistic is: -2.7674 3.3277 4.6949
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -4.15 -3.50 -3.18
## phi2 7.02 5.13 4.31
## phi3 9.31 6.73 5.61
X2=ur.df(residuales_mv, type="drift", selectlags = "AIC" )
summary(X2)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.0250825 -0.0075625 0.0000228 0.0085729 0.0230146
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0019652 0.0023182 0.848 0.40405
## z.lag.1 -0.3564103 0.1242647 -2.868 0.00792 **
## z.diff.lag -0.0006034 0.1752481 -0.003 0.99728
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0126 on 27 degrees of freedom
## Multiple R-squared: 0.2488, Adjusted R-squared: 0.1932
## F-statistic: 4.472 on 2 and 27 DF, p-value: 0.02102
##
##
## Value of test-statistic is: -2.8682 4.4084
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.58 -2.93 -2.60
## phi1 7.06 4.86 3.94
X3=ur.df(residuales_mv, type="none", selectlags = "AIC" )
summary(X3)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.023150 -0.005587 0.002027 0.010266 0.025479
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -0.35349 0.12359 -2.860 0.00792 **
## z.diff.lag 0.01541 0.17335 0.089 0.92981
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01254 on 28 degrees of freedom
## Multiple R-squared: 0.2384, Adjusted R-squared: 0.184
## F-statistic: 4.382 on 2 and 28 DF, p-value: 0.0221
##
##
## Value of test-statistic is: -2.8601
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.62 -1.95 -1.61