Análisis de la MIP en R

FUNCIONES

#Matriz de coeficientes tecnicos
mip_coeficientes_tecnicos<-function(matriz_consumo_intermedio,
                                    vector_demanda_final){
  filas_ci<-nrow(matriz_consumo_intermedio)
  columnas_ci<-ncol(matriz_consumo_intermedio)
  filas_x<-nrow(vector_demanda_final)
  if(filas_ci!=columnas_ci){
    stop("Ingrese una matriz de Consumo Intermedio, Cuadrada",call. = FALSE)
  }
  if(filas_ci!=filas_x){
    stop("Vector de demanda final incompatible (diferente dimensión)",call. = FALSE)
  }
  v<-solve(diag(as.vector(vector_demanda_final)))
  A<-matriz_consumo_intermedio%*%v
  list(A=A,V=v)
}
#matriz tecnológica

mip_matriz_tecnologica<-function(matriz_coeficientes_tecnicos){
  filas_A<-nrow(matriz_coeficientes_tecnicos)
  columnas_A<-ncol(matriz_coeficientes_tecnicos)
  if(filas_A!=columnas_A){
    stop("Ingrese una matriz de coef. técnicos cuadrada",call. = FALSE)
  }
  tipo_matriz<-typeof(matriz_coeficientes_tecnicos)
  if(tipo_matriz!="double"){
    stop("La matriz ingresada no es numerica",call. = FALSE)
  }
  T<-diag(1,filas_A)-matriz_coeficientes_tecnicos
  T
}
mip_matriz_leontief<-function(matriz_tecnologica){
  L<-solve(matriz_tecnologica)
  L
}
mip_multiplicadores_produccion_mp<-function(matriz_leontief){
  mp<-rowSums(matriz_leontief)
  mp
}
mip_multiplicadores_expansion_demanda_me<-function(matriz_leontief){
  me<-colSums(matriz_leontief)
  me
}
mip_encadenamiento_pd<-function(matriz_leontief){
  mp<-mip_multiplicadores_produccion_mp(matriz_leontief)
  mp/mean(mp)
}
mip_encadenamiento_sd<-function(matriz_leontief){
  me<-mip_multiplicadores_expansion_demanda_me(matriz_leontief)
  me/mean(me)
}
mip_tabla_rasmussen<-function(matriz_leontief){
library(dplyr)
pd<-mip_encadenamiento_pd(matriz_leontief)
sd<-mip_encadenamiento_sd(matriz_leontief)
rasmussen<-data.frame(pd=pd,sd=sd)
rasmussen_clasificado<-rasmussen %>% 
  mutate(clasificacion=case_when(pd>1 & sd>1 ~ "Sector Clave",
                                           pd<1 & sd>1 ~"Sector Estrategico",
                                           pd>1 & sd<1 ~"Sector Impulsor",
                                           pd<1 & sd<1 ~"Sector Isla",
                                           TRUE ~ "No clasificado")) %>% mutate(sector=row_number()) %>% select(sector,pd,sd,clasificacion)
rasmussen_clasificado
}

IMPORTACIÓN DE DATOS

options(scipen = 9999)
library(readxl)
library(dplyr)
library(kableExtra)

# Datos 1990

# Consumo Intermedio
library(readxl)
mip1990_ci <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 1990", range = "i14:bb59", 
    col_names = FALSE)
names(mip1990_ci)<-as.character(1:46)

# Demanda final
mip1990_h <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 1990", range = "bd14:be59", 
    col_names = FALSE)
names(mip1990_h)<-as.character(1:46)

# Vector de producción
mip1990_x <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 1990", range = "bi14:bi59", 
    col_names = FALSE)
names(mip1990_x)<-as.character("X")

library(dplyr)
servicios_row<-colSums(mip1990_ci[41:46,])
temporal_1990<-rbind(mip1990_ci[1:40,],servicios_row)
servicios_col<-rowSums(temporal_1990[,41:46])
mip1990_ci_corregida<-cbind(temporal_1990[,1:40], servicios_col)
names(mip1990_ci_corregida)<-as.character(1:41)
X<-rbind(mip1990_x[1:40,],colSums(mip1990_x[41:46,]))

A<-mip_coeficientes_tecnicos(as.matrix(mip1990_ci_corregida),as.matrix(X))[[1]]
matriz_T<-mip_matriz_tecnologica(matriz_coeficientes_tecnicos = A)
L_1990<-mip_matriz_leontief(matriz_tecnologica = matriz_T)
tabla<-mip_tabla_rasmussen(L_1990) %>% print() 
##    sector        pd         sd      clasificacion
## 1       1 0.4738099  0.5377737        Sector Isla
## 2       2 0.5103989  0.5431585        Sector Isla
## 3       3 0.7498101  0.5405244        Sector Isla
## 4       4 0.6474832  0.6718479        Sector Isla
## 5       5 0.5953563  0.4818147        Sector Isla
## 6       6 0.9345096  0.6191023        Sector Isla
## 7       7 0.4796003  0.7576287        Sector Isla
## 8       8 0.5339693  0.4411965        Sector Isla
## 9       9 0.4640698  0.5928952        Sector Isla
## 10     10 1.5729999  0.4487713    Sector Impulsor
## 11     11 0.5242181  0.7859308        Sector Isla
## 12     12 0.4854652  0.7662982        Sector Isla
## 13     13 0.4311308  0.4538262        Sector Isla
## 14     14 0.6823240  0.7710486        Sector Isla
## 15     15 0.5118341  0.7885595        Sector Isla
## 16     16 0.9530260  0.6654498        Sector Isla
## 17     17 0.5370545  0.5852182        Sector Isla
## 18     18 0.4352191  0.5933068        Sector Isla
## 19     19 0.8263179  0.6451216        Sector Isla
## 20     20 0.4414599  0.7037213        Sector Isla
## 21     21 0.5096526  0.6763795        Sector Isla
## 22     22 0.4912877  0.5833802        Sector Isla
## 23     23 1.1553830  0.7134494    Sector Impulsor
## 24     24 1.1735183  0.6203589    Sector Impulsor
## 25     25 1.3499915  0.5688198    Sector Impulsor
## 26     26 2.9928433  0.6035863    Sector Impulsor
## 27     27 1.1154436  0.5977987    Sector Impulsor
## 28     28 0.6880895  0.6253106        Sector Isla
## 29     29 0.9416781  1.0140442 Sector Estrategico
## 30     30 0.6406108  0.5567087        Sector Isla
## 31     31 0.8853062  0.4752828        Sector Isla
## 32     32 0.9364251  0.6219254        Sector Isla
## 33     33 0.5045891  0.5964451        Sector Isla
## 34     34 0.5309331  0.7827303        Sector Isla
## 35     35 0.4573997 16.0412883 Sector Estrategico
## 36     36 0.5535413  0.7010228        Sector Isla
## 37     37 5.9198052  0.6502997    Sector Impulsor
## 38     38 0.9694733  0.5390206        Sector Isla
## 39     39 1.5926642  0.5798107    Sector Impulsor
## 40     40 3.2276126  0.5013313    Sector Impulsor
## 41     41 1.5736950  0.5578123    Sector Impulsor
# Datos 2006
options(scipen = 9999)
library(readxl)
library(dplyr)

#Consumo Intermedio
mip2006_ci <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 2006", range = "i15:bb60", 
    col_names = FALSE)
names(mip2006_ci)<-as.character(1:46)

#Demanda Final
mip2006_h <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 2006", range = "bd15:be60", 
    col_names = FALSE)
names(mip2006_h)<-as.character(1:2)

#Vector de producción
mip2006_X <- read_excel("C:/Users/Guardado/Documents/métodos clases/Anexo_Resolución_32_MATRIZ_INSUMO_PRODUCTO_A_PRECIOS_CORRIENTES_EN_DOLARES_1990-2006.xls", 
    sheet = "MIP 2006", range = "bi15:bi60", 
    col_names = FALSE)
names(mip2006_X)<-c("X")

library(dplyr)
servicios_row<-colSums(mip2006_ci[41:46,])
temporal<-rbind(mip2006_ci[1:40,],servicios_row)
servicios_col<-rowSums(temporal[,41:46])
mip2006_ci_corregida<-cbind(temporal[,1:40],servicios_col)
names(mip2006_ci_corregida)<-as.character(1:41)
X<-rbind(mip2006_X[1:40,],colSums(mip2006_X[41:46,]))

A<-mip_coeficientes_tecnicos(as.matrix(mip2006_ci_corregida),as.matrix(X))[[1]]
matriz_T<-mip_matriz_tecnologica(matriz_coeficientes_tecnicos = A)
L_2006<-mip_matriz_leontief(matriz_tecnologica = matriz_T)
tabla<-mip_tabla_rasmussen(L_2006) %>% print()
##    sector        pd         sd      clasificacion
## 1       1 0.5266371  0.6742102        Sector Isla
## 2       2 0.5468883  0.5299542        Sector Isla
## 3       3 0.7658552  0.6415055        Sector Isla
## 4       4 0.6759963  0.9598921        Sector Isla
## 5       5 0.6467097  0.5630764        Sector Isla
## 6       6 0.8433116  0.7275592        Sector Isla
## 7       7 0.5510189  0.8757175        Sector Isla
## 8       8 0.6216461  0.5334481        Sector Isla
## 9       9 0.7062793  0.7790059        Sector Isla
## 10     10 1.3339695  0.5564918    Sector Impulsor
## 11     11 0.5974393  0.7277986        Sector Isla
## 12     12 0.5599095  0.7645337        Sector Isla
## 13     13 0.5205150  0.5406925        Sector Isla
## 14     14 0.7042717  0.7928421        Sector Isla
## 15     15 0.5476486  1.0085354 Sector Estrategico
## 16     16 0.9963777  0.6984426        Sector Isla
## 17     17 0.5891340  0.6633745        Sector Isla
## 18     18 0.5197275  0.5194535        Sector Isla
## 19     19 0.7641142  0.6759362        Sector Isla
## 20     20 0.5289720  0.7124806        Sector Isla
## 21     21 0.5869791  0.7247208        Sector Isla
## 22     22 0.5751913  0.6113676        Sector Isla
## 23     23 1.0484997  0.7445995    Sector Impulsor
## 24     24 0.9808336  0.7083989        Sector Isla
## 25     25 1.1170017  0.6300139    Sector Impulsor
## 26     26 3.2965709  0.6444126    Sector Impulsor
## 27     27 0.8121867  0.6631067        Sector Isla
## 28     28 0.7841251  0.7772573        Sector Isla
## 29     29 0.9306187  1.0340246 Sector Estrategico
## 30     30 0.6495298  0.5760867        Sector Isla
## 31     31 0.7959562  0.5654301        Sector Isla
## 32     32 1.4531322  0.8251255    Sector Impulsor
## 33     33 0.5619995  1.1035588 Sector Estrategico
## 34     34 0.6165996  0.8700713        Sector Isla
## 35     35 0.5516892 12.3434144 Sector Estrategico
## 36     36 0.6218298  0.6749219        Sector Isla
## 37     37 5.3517201  0.7258272    Sector Impulsor
## 38     38 0.8262533  0.8751212        Sector Isla
## 39     39 0.9175119  0.6423195        Sector Isla
## 40     40 3.3777885  0.6086018    Sector Impulsor
## 41     41 1.5975616  0.7066691    Sector Impulsor

EJERCICIO 1

Realice el cálculo de lo siguiente (de ser necesario haga las agregaciones de servicios propuestas en la clase):

LITERAL A

Multiplicadores Expansión de la demanda (me) para la MIP 1990 y para la MIP 2006.

library(kableExtra)
library(dplyr)
# Multiplicador expansión de la demanda 1990
me_1990 <- round(colSums(L_1990),2)

# Multiplicador expansión de la demanda 2006
me_2006 <- round(colSums(L_2006),2)

tabla_unida_expansion <- cbind(1:41,me_1990, me_2006) 
 tabla_unida_expansion %>% head(41) %>% 
  kable(caption = " Multiplicadores Expansión de la demanda (me) para la MIP 1990 y 2006",
        align="c") %>% 
  add_footnote(label = "Elaboración propia con base de datos del BCR", 
               notation="symbol") %>% kable_styling()
Multiplicadores Expansión de la demanda (me) para la MIP 1990 y 2006
me_1990 me_2006
1 1.26 1.30
2 1.27 1.02
3 1.26 1.23
4 1.57 1.85
5 1.12 1.08
6 1.45 1.40
7 1.77 1.69
8 1.03 1.03
9 1.38 1.50
10 1.05 1.07
11 1.83 1.40
12 1.79 1.47
13 1.06 1.04
14 1.80 1.53
15 1.84 1.94
16 1.55 1.34
17 1.37 1.28
18 1.38 1.00
19 1.51 1.30
20 1.64 1.37
21 1.58 1.40
22 1.36 1.18
23 1.67 1.43
24 1.45 1.36
25 1.33 1.21
26 1.41 1.24
27 1.40 1.28
28 1.46 1.50
29 2.37 1.99
30 1.30 1.11
31 1.11 1.09
32 1.45 1.59
33 1.39 2.12
34 1.83 1.67
35 37.44 23.76
36 1.64 1.30
37 1.52 1.40
38 1.26 1.68
39 1.35 1.24
40 1.17 1.17
41 1.30 1.36
* Elaboración propia con base de datos del BCR

LITERAL B.

Multiplicadores de la producción (mp) para la MIP 1990 y para la MIP 2006

library(kableExtra)
# Multiplicadores de la producción 1990
mp_1990 <- round(rowSums(L_1990),2)

# Multiplicadores de la producción 2006
mp_2006 <- round(rowSums(L_2006),2)

tabla_unida_produccion <- cbind(1:41,mp_1990, mp_2006) 
 tabla_unida_produccion %>% head(41) %>% 
  kable(caption = " Multiplicadores de la producción (mp) para la MIP 1990 y 2006",
        align="c") %>% 
  add_footnote(label = "Elaboración propia con base de datos del BCR", 
               notation="symbol") %>% kable_styling()
Multiplicadores de la producción (mp) para la MIP 1990 y 2006
mp_1990 mp_2006
1 1.11 1.01
2 1.19 1.05
3 1.75 1.47
4 1.51 1.30
5 1.39 1.24
6 2.18 1.62
7 1.12 1.06
8 1.25 1.20
9 1.08 1.36
10 3.67 2.57
11 1.22 1.15
12 1.13 1.08
13 1.01 1.00
14 1.59 1.36
15 1.19 1.05
16 2.22 1.92
17 1.25 1.13
18 1.02 1.00
19 1.93 1.47
20 1.03 1.02
21 1.19 1.13
22 1.15 1.11
23 2.70 2.02
24 2.74 1.89
25 3.15 2.15
26 6.99 6.35
27 2.60 1.56
28 1.61 1.51
29 2.20 1.79
30 1.50 1.25
31 2.07 1.53
32 2.19 2.80
33 1.18 1.08
34 1.24 1.19
35 1.07 1.06
36 1.29 1.20
37 13.82 10.30
38 2.26 1.59
39 3.72 1.77
40 7.53 6.50
41 3.67 3.08
* Elaboración propia con base de datos del BCR

LITERAL C.

Tasa de cambio para ambos multiplicadores (por ejemplo, para me: me2006/me1990-1)

library(kableExtra)
# Tasas de cambio 
tasa_me <- round(((me_2006/me_1990)-1),2)

tasa_mp <- round(((mp_2006/mp_1990)-1),2)

tabla_unida_tasas <- cbind(1:41,tasa_me, tasa_mp) 
 tabla_unida_tasas %>% head(41) %>% 
  kable(caption = "Tasa de cambio para ambos multiplicadores 1990 y 2006",
        align="c") %>% 
  add_footnote(label = "Elaboración propia con base de datos del BCR", 
               notation="symbol") %>% kable_styling()
Tasa de cambio para ambos multiplicadores 1990 y 2006
tasa_me tasa_mp
1 0.03 -0.09
2 -0.20 -0.12
3 -0.02 -0.16
4 0.18 -0.14
5 -0.04 -0.11
6 -0.03 -0.26
7 -0.05 -0.05
8 0.00 -0.04
9 0.09 0.26
10 0.02 -0.30
11 -0.23 -0.06
12 -0.18 -0.04
13 -0.02 -0.01
14 -0.15 -0.14
15 0.05 -0.12
16 -0.14 -0.14
17 -0.07 -0.10
18 -0.28 -0.02
19 -0.14 -0.24
20 -0.16 -0.01
21 -0.11 -0.05
22 -0.13 -0.03
23 -0.14 -0.25
24 -0.06 -0.31
25 -0.09 -0.32
26 -0.12 -0.09
27 -0.09 -0.40
28 0.03 -0.06
29 -0.16 -0.19
30 -0.15 -0.17
31 -0.02 -0.26
32 0.10 0.28
33 0.53 -0.08
34 -0.09 -0.04
35 -0.37 -0.01
36 -0.21 -0.07
37 -0.08 -0.25
38 0.33 -0.30
39 -0.08 -0.52
40 0.00 -0.14
41 0.05 -0.16
* Elaboración propia con base de datos del BCR

LITERAL D

Presente los resultados en una tabla que incluya los nombres para todos los sectores.

library(dplyr)
library(kableExtra)

tabla <- data.frame(me_1990=me_1990,me_2006=me_2006, mp_1990=mp_1990, mp_2006=mp_2006) %>% 
  mutate(dif_me=round((me_2006/me_1990-1)*100,2),
         dif_mp=round((mp_2006/mp_1990-1)*100,2)) %>%
  mutate(sector=row_number()) %>% 
         select(sector, everything())
tabla %>% 
  kable(aption="Tabla de los multiplicadores MIP 1990 y 2006",
        align = "c",
        digits = 2) %>% 
  kable_material(html_font = "sans-serif") %>% 
  kable_styling(bootstrap_options = c("striped", "hover"))
sector me_1990 me_2006 mp_1990 mp_2006 dif_me dif_mp
1 1.26 1.30 1.11 1.01 3.17 -9.01
2 1.27 1.02 1.19 1.05 -19.69 -11.76
3 1.26 1.23 1.75 1.47 -2.38 -16.00
4 1.57 1.85 1.51 1.30 17.83 -13.91
5 1.12 1.08 1.39 1.24 -3.57 -10.79
6 1.45 1.40 2.18 1.62 -3.45 -25.69
7 1.77 1.69 1.12 1.06 -4.52 -5.36
8 1.03 1.03 1.25 1.20 0.00 -4.00
9 1.38 1.50 1.08 1.36 8.70 25.93
10 1.05 1.07 3.67 2.57 1.90 -29.97
11 1.83 1.40 1.22 1.15 -23.50 -5.74
12 1.79 1.47 1.13 1.08 -17.88 -4.42
13 1.06 1.04 1.01 1.00 -1.89 -0.99
14 1.80 1.53 1.59 1.36 -15.00 -14.47
15 1.84 1.94 1.19 1.05 5.43 -11.76
16 1.55 1.34 2.22 1.92 -13.55 -13.51
17 1.37 1.28 1.25 1.13 -6.57 -9.60
18 1.38 1.00 1.02 1.00 -27.54 -1.96
19 1.51 1.30 1.93 1.47 -13.91 -23.83
20 1.64 1.37 1.03 1.02 -16.46 -0.97
21 1.58 1.40 1.19 1.13 -11.39 -5.04
22 1.36 1.18 1.15 1.11 -13.24 -3.48
23 1.67 1.43 2.70 2.02 -14.37 -25.19
24 1.45 1.36 2.74 1.89 -6.21 -31.02
25 1.33 1.21 3.15 2.15 -9.02 -31.75
26 1.41 1.24 6.99 6.35 -12.06 -9.16
27 1.40 1.28 2.60 1.56 -8.57 -40.00
28 1.46 1.50 1.61 1.51 2.74 -6.21
29 2.37 1.99 2.20 1.79 -16.03 -18.64
30 1.30 1.11 1.50 1.25 -14.62 -16.67
31 1.11 1.09 2.07 1.53 -1.80 -26.09
32 1.45 1.59 2.19 2.80 9.66 27.85
33 1.39 2.12 1.18 1.08 52.52 -8.47
34 1.83 1.67 1.24 1.19 -8.74 -4.03
35 37.44 23.76 1.07 1.06 -36.54 -0.93
36 1.64 1.30 1.29 1.20 -20.73 -6.98
37 1.52 1.40 13.82 10.30 -7.89 -25.47
38 1.26 1.68 2.26 1.59 33.33 -29.65
39 1.35 1.24 3.72 1.77 -8.15 -52.42
40 1.17 1.17 7.53 6.50 0.00 -13.68
41 1.30 1.36 3.67 3.08 4.62 -16.08

EJERCICIO 2

Realice el análisis de Rasmussen para para las MIP 1990 y 2006.

Análisis de Rasmussen para MIP 1990.

library(dplyr)
library(kableExtra)

rasmussen_1990<-mip_tabla_rasmussen(L_1990) 

summary_rasmussen_1990 <- rasmussen_1990 %>% 
  group_by(clasificacion) %>% summarise(total=n()) %>% mutate(porcentaje=round(prop.table(total)*100,2))

summary_rasmussen_1990 %>% 
  kable(aption="Análisis de Rasmussen para MIP 1990",
        align = "c",
        digits = 2) %>% 
  kable_material(html_font = "sans-serif") %>% 
  kable_styling(bootstrap_options = c("striped", "hover"))
clasificacion total porcentaje
Sector Estrategico 2 4.88
Sector Impulsor 10 24.39
Sector Isla 29 70.73

Análisis de Rasmussen para MIP 2006.

library(dplyr)
library(kableExtra)

rasmussen_2006<-mip_tabla_rasmussen(L_2006) 

summary_rasmussen_2006 <- rasmussen_2006 %>% 
  group_by(clasificacion) %>% summarise(total=n()) %>% mutate(porcentaje=round(prop.table(total)*100,2))
  
summary_rasmussen_2006 %>% 
  kable(aption="Análisis de Rasmussen para MIP 2006",
        align = "c",
        digits = 2) %>% 
  kable_material(html_font = "sans-serif") %>% 
  kable_styling(bootstrap_options = c("striped", "hover"))
clasificacion total porcentaje
Sector Estrategico 4 9.76
Sector Impulsor 8 19.51
Sector Isla 29 70.73

EJERCICIO 3

Presente una tabla comparativa entre los resultados porcentuales por tipo de sector entre 1990 y 2006, incluya una columna que muestre la variación porcentual por tipo de sector.

tabla_comparativa<-left_join(summary_rasmussen_1990, summary_rasmussen_2006, by="clasificacion", suffix=c("_1990","_2006"))

tabla_comparativa %>% 
  mutate(dif_variacion_porcentual= round((porcentaje_2006/porcentaje_1990-1)*100,2)) %>% 
  kable(aption="Tabla comparativa",
        align = "c",
        digits = 2) %>% 
  kable_material(html_font = "sans-serif") %>% 
  kable_styling(bootstrap_options = c("striped", "hover"))
clasificacion total_1990 porcentaje_1990 total_2006 porcentaje_2006 dif_variacion_porcentual
Sector Estrategico 2 4.88 4 9.76 100.00
Sector Impulsor 10 24.39 8 19.51 -20.01
Sector Isla 29 70.73 29 70.73 0.00