Time series analysis is a fundamental statistical technique used to understand and model time-varying data. In essence, it involves the study of sequential observations over a continuous period, such as daily financial data, monthly weather records, or monthly sales of a company. The main goal of time series analysis is to identify patterns, trends, and cycles in data, as well as predict future observations based on past observations. According to David Velázquez (2011), from the National University of Colombia, “time series forecasting is much more related to investment decisions and finances.” This is achieved through the application of various statistical and mathematical models, such as the autoregressive model (AR), the moving average model (MA) and the autoregressive integrated moving average model (ARIMA).
As mentioned, time series analysis is essential in various disciplines, such as economics, meteorology, engineering, epidemiology and many others, since it provides a valuable tool for decision making, planning and prediction in historical data function. Additionally, this technique has become even more relevant in today’s era of big data and predictive analytics.
In an increasingly globalized and competitive business world, organizations are constantly seeking innovative strategies to optimize their operations and stay at the forefront of their respective industries. One of these strategies that has gained prominence in recent years is “Nearshoring”, an outsourcing approach that consists of delegating activities and services to suppliers located in geographically close countries. In this context, Mexico emerges as an attractive destination for “Nearshoring”, thanks to its strategic location, trained human resources and favorable economic conditions.
Mexico has a privileged geographical location, sharing borders with the United States and being part of the North American Free Trade Agreement (NAFTA), today T-MEC, which facilitates access to one of the largest and most dynamic markets. of the world. This geographic proximity not only reduces transportation costs and times, but also facilitates real-time communication and collaboration between parent companies and their nearshoring partners. Additionally, Mexico has established a network of trade agreements that provide tariff advantages and facilitate the flow of goods, providing an attractive platform for outsourcing operations.
The country also has a highly skilled and diversified workforce, ranging from engineers and technology professionals to manufacturing and financial services experts. Labor costs in Mexico are competitive compared to other outsourcing destinations, allowing companies to obtain greater added value at a lower cost. In addition, the continuous growth in education and training has promoted the training of highly qualified professionals, which guarantees the availability of the talent necessary to meet the demands of “Nearshoring”. All of this has meant that in recent years, Mexico has witnessed the accelerated Nearshoring process, where many international companies have decided to invest in our country to open megafactories. Recently, the case of Testa and its gigafactory in the state of Nuevo León stands out. . This phenomenon could bring great benefits to our country due to all the economic loss it entails. According to the Global Business Council (CEG) (2023), nearshoring could generate up to 4 million jobs in Mexican territory by 2030, receiving between 30 and 50 billion dollars annually, in addition, the same study indicates that this phenomenon may be responsible for increasing Mexico’s GDP by up to 2.5% in the next 6 years. Therefore, it is very important to analyze and understand this phenomenon through the statistical analysis of historical data on Foreign Direct Investment and some macroeconomic variables that are closely related to said dependent variable.
The problematic situation that María faces in her project to analyze time series models for nearshoring focuses on the need to forecast foreign investments in Mexico during the quarterly period from 2023 to 2024 and understand the future trends of nearshoring in the country . Its main challenge lies in identifying the factors that can influence both positively and negatively the relocation of foreign investments in Mexico. Therefore, the objective of this analysis is to estimate econometric models that can accurately predict foreign investments in the short term and, at the same time, identify the economic, socioeconomic and business environment variables that play a crucial role in attracting foreign investment. investment flows to Mexico.
### loading libraries
library(foreign)
library(dplyr) # data manipulation
library(forcats) # to work with categorical variables
library(ggplot2) # data visualization
library(readr) # read specific csv files
library(janitor) # data exploration and cleaning
library(Hmisc) # several useful functions for data analysis
library(psych) # functions for multivariate analysis
library(naniar) # summaries and visualization of missing values NA's
library(dlookr) # summaries and visualization of missing values NA's
library(corrplot) # correlation plots
library(jtools) # presentation of regression analysis
library(lmtest) # diagnostic checks - linear regression analysis
library(car) # diagnostic checks - linear regression analysis
library(olsrr) # diagnostic checks - linear regression analysis
library(naniar) # identifying missing values
library(stargazer) # create publication quality tables
library(effects) # displays for linear and other regression models
library(tidyverse) # collection of R packages designed for data science
library(caret) # Classification and Regression Training
library(glmnet) # methods for prediction and plotting, and functions for cross-validation
library(xts)
library(zoo)
library(tseries)
library(stats)
library(forecast)
library(astsa)
library(corrplot)
library(AER)
library(dynlm)
library(vars)
#library(mFilter)
library(TSstudio)
library(tidyverse)
library(sarima)
library(stargazer)
library(dygraphs)
It is important to mention that the database provided has a part of annual data with the independent variables that are not included in the quarterly data of the time series part. These variables are required for the VAR model to serve as explanatory variables. Given that using annual data and converting it to quarterly data would mean omitting their variation over time, it was decided to use the time series database for modeling 1, which will use ARMA and ARIMA models for the forecast of the dependent variable and the first database will be used for modeling the VAR model.
#Import database 1
<- read.csv("/Users/gabrielmedina/Downloads/nearshoring.csv")
data #data
#Import database 2
<- read.csv("/Users/gabrielmedina/Downloads/Series_ied.csv")
data2 #data2
The analysis of descriptive statistics reveals a variety of data in a period spanning from 1997 to 2022. Foreign Direct Investment (FDI) stands out as a dependent variable, with a wide range of values ranging between 210,876 and 754,438 (mx). Other variables, such as daily wage, innovation, insecurity and GDP per capita, also show significant variability. These data provide an overview of the diversity in the key variables, suggesting the need for further analysis and the possibility of building a linear regression model to investigate the relationships between them in the context of Nearshoring.
summary(data)
## periodo IED_Flujos_dolares Exportaciones_dolares Empleo
## Min. :1997 Min. : 8374 Min. : 9088 Min. :95.06
## 1st Qu.:2003 1st Qu.:21367 1st Qu.:13260 1st Qu.:95.89
## Median :2010 Median :27698 Median :21188 Median :96.53
## Mean :2010 Mean :26770 Mean :23601 Mean :96.47
## 3rd Qu.:2016 3rd Qu.:32183 3rd Qu.:31601 3rd Qu.:97.08
## Max. :2022 Max. :48354 Max. :46478 Max. :97.83
## NA's :3
## Educacion Salario_Diario Innovacion Inseguridad_Robo
## Min. :7.200 Min. : 24.30 Min. :11.28 Min. :120.5
## 1st Qu.:7.865 1st Qu.: 41.97 1st Qu.:12.56 1st Qu.:148.3
## Median :8.460 Median : 54.48 Median :13.09 Median :181.8
## Mean :8.423 Mean : 65.16 Mean :13.11 Mean :185.4
## 3rd Qu.:9.000 3rd Qu.: 72.31 3rd Qu.:13.75 3rd Qu.:209.9
## Max. :9.580 Max. :172.87 Max. :15.11 Max. :314.8
## NA's :3 NA's :2
## Inseguridad_Homicidio Tipo_de_Cambio Densidad_Carretera Densidad_Poblacion
## Min. : 8.04 Min. : 8.06 Min. :0.05000 Min. :47.44
## 1st Qu.:10.25 1st Qu.:10.75 1st Qu.:0.06000 1st Qu.:52.77
## Median :16.93 Median :13.02 Median :0.07000 Median :58.09
## Mean :17.29 Mean :13.91 Mean :0.07115 Mean :57.33
## 3rd Qu.:22.43 3rd Qu.:18.49 3rd Qu.:0.08000 3rd Qu.:61.39
## Max. :29.59 Max. :20.66 Max. :0.09000 Max. :65.60
## NA's :1
## CO2_Emisiones PIB_Per_Capita INPC
## Min. :3.590 Min. :126739 Min. : 33.28
## 1st Qu.:3.830 1st Qu.:130964 1st Qu.: 56.15
## Median :3.930 Median :136845 Median : 73.35
## Mean :3.945 Mean :138550 Mean : 75.17
## 3rd Qu.:4.105 3rd Qu.:146148 3rd Qu.: 91.29
## Max. :4.220 Max. :153236 Max. :126.48
## NA's :3
As we could see, there are several records with missing values, removing them would skew our data. Therefore, the mean statistical imputation method will be used to be able to replace the null values.
<- data
datos_imputados <- mean(data$Empleo, na.rm = TRUE) # Calculate the mean without NA
media_empleo <- mean(data$Educacion, na.rm = TRUE) # Calculate the mean without NA
media_educacion <- mean(data$Innovacion, na.rm = TRUE) # Calculate the mean without NA
media_innovacion <- mean(data$Inseguridad_Homicidio, na.rm = TRUE) # Calculate the mean without NA
media_homicidio <- mean(data$CO2_Emisiones, na.rm = TRUE) # Calculate the mean without NA
media_CO2 $Empleo[is.na(datos_imputados$Empleo)] <- media_empleo
datos_imputados$Educacion[is.na(datos_imputados$Educacion)] <- media_educacion
datos_imputados$Innovacion[is.na(datos_imputados$Innovacion)] <- media_innovacion
datos_imputados$Inseguridad_Homicidio[is.na(datos_imputados$Inseguridad_Homicidio)] <- media_homicidio
datos_imputados$CO2_Emisiones[is.na(datos_imputados$CO2_Emisiones)] <- media_CO2 datos_imputados
#Validation
str(datos_imputados)
## 'data.frame': 26 obs. of 15 variables:
## $ periodo : int 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 ...
## $ IED_Flujos_dolares : num 12146 8374 13960 18249 30057 ...
## $ Exportaciones_dolares: num 9088 9875 10990 12483 11300 ...
## $ Empleo : num 96.5 96.5 96.5 97.8 97.4 ...
## $ Educacion : num 7.2 7.31 7.43 7.56 7.68 7.8 7.93 8.04 8.14 8.26 ...
## $ Salario_Diario : num 24.3 31.9 31.9 35.1 37.6 ...
## $ Innovacion : num 11.3 11.4 12.5 13.2 13.5 ...
## $ Inseguridad_Robo : num 267 315 273 217 215 ...
## $ Inseguridad_Homicidio: num 14.6 14.3 12.6 10.9 10.2 ...
## $ Tipo_de_Cambio : num 8.06 9.94 9.52 9.6 9.17 ...
## $ Densidad_Carretera : num 0.05 0.05 0.06 0.06 0.06 0.06 0.06 0.06 0.06 0.06 ...
## $ Densidad_Poblacion : num 47.4 48.8 49.5 50.6 51.3 ...
## $ CO2_Emisiones : num 3.68 3.85 3.69 3.87 3.81 3.82 3.95 3.98 4.1 4.19 ...
## $ PIB_Per_Capita : num 127570 126739 129165 130875 128083 ...
## $ INPC : num 33.3 39.5 44.3 48.3 50.4 ...
=data dataf
To begin, according to the glossary of the database provided, foreign direct investment and exports are in dollars and in nominal values, which is why it is important to transform them into pesos and real values. These real values more accurately reflect the fluctuations in foreign direct investment over the time series, taking into account the inflationary changes that occurred in those specific years. To achieve this conversion, the exchange rate corresponding to the year of each observation was applied and the National Consumer Price Index (INPC) of that same year was considered as an inflation adjustment. This approach allows for a more accurate and realistic representation of FDI over time.
$IED_Flujos = ((dataf$IED_Flujos_dolares * dataf$Tipo_de_Cambio) / dataf$INPC) * 100
dataf$Exportaciones = ((dataf$Exportaciones_dolares * dataf$Tipo_de_Cambio) / dataf$INPC) * 100
dataf dataf
## periodo IED_Flujos_dolares Exportaciones_dolares Empleo Educacion
## 1 1997 12145.60 9087.62 NA 7.20
## 2 1998 8373.50 9875.07 NA 7.31
## 3 1999 13960.32 10990.01 NA 7.43
## 4 2000 18248.69 12482.96 97.83 7.56
## 5 2001 30057.18 11300.44 97.36 7.68
## 6 2002 24099.21 11923.10 97.66 7.80
## 7 2003 18249.97 13156.00 97.06 7.93
## 8 2004 25015.57 13573.13 96.48 8.04
## 9 2005 25795.82 16465.81 97.17 8.14
## 10 2006 21232.54 17485.93 96.53 8.26
## 11 2007 32393.33 19103.85 96.60 8.36
## 12 2008 29502.46 16924.76 95.68 8.46
## 13 2009 17849.95 19702.63 95.20 8.56
## 14 2010 27189.28 22673.14 95.06 8.63
## 15 2011 25632.52 24333.02 95.49 8.75
## 16 2012 21769.32 26297.98 95.53 8.85
## 17 2013 48354.42 27687.57 95.75 8.95
## 18 2014 30351.25 31676.78 96.24 9.05
## 19 2015 35943.75 29959.94 96.04 9.15
## 20 2016 31188.98 31375.06 96.62 9.25
## 21 2017 34017.05 33322.62 96.85 9.35
## 22 2018 34100.43 35341.90 96.64 9.45
## 23 2019 34577.16 36414.73 97.09 9.58
## 24 2020 28205.89 41077.34 96.21 NA
## 25 2021 31553.52 44914.78 96.49 NA
## 26 2022 36215.37 46477.59 97.24 NA
## Salario_Diario Innovacion Inseguridad_Robo Inseguridad_Homicidio
## 1 24.30 11.30 266.51 14.55
## 2 31.91 11.37 314.78 14.32
## 3 31.91 12.46 272.89 12.64
## 4 35.12 13.15 216.98 10.86
## 5 37.57 13.47 214.53 10.25
## 6 39.74 12.80 197.80 9.94
## 7 41.53 11.81 183.22 9.81
## 8 43.30 12.61 146.28 8.92
## 9 45.24 13.41 136.94 9.22
## 10 47.05 14.23 135.59 9.60
## 11 48.88 15.04 145.92 8.04
## 12 50.84 14.82 158.17 12.52
## 13 53.19 12.59 175.77 17.46
## 14 55.77 12.69 201.94 22.43
## 15 58.06 12.10 212.61 23.42
## 16 60.75 13.03 190.28 22.09
## 17 63.12 13.22 185.56 19.74
## 18 65.58 13.65 154.41 16.93
## 19 70.10 15.11 180.44 17.37
## 20 73.04 14.40 160.57 20.31
## 21 88.36 14.05 230.43 26.22
## 22 88.36 13.25 184.25 29.59
## 23 102.68 12.70 173.45 29.21
## 24 123.22 11.28 133.90 28.98
## 25 141.70 NA 127.13 27.89
## 26 172.87 NA 120.49 NA
## Tipo_de_Cambio Densidad_Carretera Densidad_Poblacion CO2_Emisiones
## 1 8.06 0.05 47.44 3.68
## 2 9.94 0.05 48.76 3.85
## 3 9.52 0.06 49.48 3.69
## 4 9.60 0.06 50.58 3.87
## 5 9.17 0.06 51.28 3.81
## 6 10.36 0.06 51.95 3.82
## 7 11.20 0.06 52.61 3.95
## 8 11.22 0.06 53.27 3.98
## 9 10.71 0.06 54.78 4.10
## 10 10.88 0.06 55.44 4.19
## 11 10.90 0.06 56.17 4.22
## 12 13.77 0.07 56.96 4.19
## 13 13.04 0.07 57.73 4.04
## 14 12.38 0.07 58.45 4.11
## 15 13.98 0.07 59.15 4.19
## 16 12.99 0.07 59.85 4.20
## 17 13.07 0.08 59.49 4.06
## 18 14.73 0.08 60.17 3.89
## 19 17.34 0.08 60.86 3.93
## 20 20.66 0.08 61.57 3.89
## 21 19.74 0.09 62.28 3.84
## 22 19.66 0.09 63.11 3.65
## 23 18.87 0.09 63.90 3.59
## 24 19.94 0.09 64.59 NA
## 25 20.52 0.09 65.16 NA
## 26 19.41 0.09 65.60 NA
## PIB_Per_Capita INPC IED_Flujos Exportaciones
## 1 127570.1 33.28 294151.2 220090.8
## 2 126738.8 39.47 210875.6 248690.6
## 3 129164.7 44.34 299734.4 235960.5
## 4 130874.9 48.31 362631.8 248057.2
## 5 128083.4 50.43 546548.4 205482.9
## 6 128205.9 53.31 468332.0 231707.6
## 7 128737.9 55.43 368752.8 265825.7
## 8 132563.5 58.31 481349.2 261173.9
## 9 132941.1 60.25 458544.8 292695.1
## 10 135894.9 62.69 368495.8 303472.5
## 11 137795.7 65.05 542793.7 320110.6
## 12 135176.0 69.30 586217.7 336297.2
## 13 131233.0 71.77 324318.4 357980.1
## 14 134991.7 74.93 449223.7 374607.6
## 15 138891.9 77.79 460653.8 437299.9
## 16 141530.2 80.57 350978.6 423992.5
## 17 144112.0 83.77 754437.5 431988.2
## 18 147277.4 87.19 512758.2 535151.9
## 19 149433.5 89.05 699904.1 583386.1
## 20 152275.4 92.04 700091.6 704268.5
## 21 153235.7 98.27 683318.0 669368.6
## 22 153133.8 99.91 671018.4 695447.7
## 23 150233.1 105.93 615945.4 648679.3
## 24 142609.3 109.27 514711.7 749594.7
## 25 142772.0 117.31 551937.8 785654.5
## 26 146826.7 126.48 555771.9 713259.0
Data2 is cleaned
The variables in database 1 show a series of economic and social characteristics in relation to the period and foreign direct investment (FDI). The dependent variable is “FDI_Flows_dollars”, which represents the flow of foreign direct investment in dollars over the years. The variable “Exports_dollars” indicates exports in dollars, which may have a relationship with FDI, since greater foreign investment can stimulate exports.
In addition, there are other economic and social variables that could influence FDI. For example, “Exchange_Type” represents the exchange rate, which can be an important factor in attracting or repelling foreign investment. “GDP_Per_Capita” reflects gross domestic product per capita, which can be related to a country’s ability to attract investment. “Employment” is also relevant, as an economy with a high level of employment could be more attractive for investment. The variables “Education”, “Daily_Salary”, “Innovation” and others indicate social and economic aspects that can affect the decision to invest in a country.
For this part, data2 will be used
#NAS validation
sum(is.na(data2))
## [1] 0
#Data transformation a data time format for tperiod variable.
$Fecha <- as.Date(paste(data2$year, data2$Trimestre), format = "%Y %B")
data2
<- ts(data2$IED_Flujos, start = c(1999, 1), frequency = 4)
time_serie
print(time_serie)
## Qtr1 Qtr2 Qtr3 Qtr4
## 1999 3596.08 3395.89 3028.45 3939.90
## 2000 4600.64 4857.42 3056.95 5733.68
## 2001 3598.68 5218.83 16314.05 4925.63
## 2002 5067.98 6258.52 6114.34 6658.37
## 2003 3963.69 5547.34 2521.68 6217.27
## 2004 9363.46 4351.50 3284.91 8015.70
## 2005 6761.62 6773.62 5478.92 6781.66
## 2006 7436.81 6634.31 2346.57 4814.85
## 2007 10815.78 6137.64 7628.45 7811.47
## 2008 8546.44 8376.14 5643.68 6936.20
## 2009 6105.30 6094.18 2397.52 3252.95
## 2010 8722.26 9301.62 3932.89 5232.50
## 2011 8431.21 6697.41 4349.89 6154.00
## 2012 7892.69 5622.13 5736.29 2518.21
## 2013 10571.58 21019.14 4178.81 12584.89
## 2014 13828.00 5478.74 3222.08 7822.43
## 2015 12136.33 6656.85 9635.56 7515.02
## 2016 12805.36 6210.62 4317.27 7855.73
## 2017 13779.06 6814.16 6361.22 7062.61
## 2018 14067.52 9577.75 4132.97 6322.19
## 2019 15175.27 6504.62 8217.40 4679.87
## 2020 16807.60 7293.96 1340.58 2763.75
## 2021 16206.05 5883.73 6419.43 3044.31
## 2022 22794.16 8164.27 3479.68 1777.26
# Time series plot 1
plot(time_serie, main = "IED quarter", xlab = "Year quarter", ylab = "IED")
We can see that the graph presents a clear component of seasonality and there may be some stationarity, however, an upward trend is visible throughout the time series, so it is necessary to apply various tests to further understand our series of time.
<-decompose(time_serie)
descomposeplot(descompose)
In the previous graph we can see a slight trend in the entire time series as previously described, this could affect the presence of stationarity. On the other hand, the seasonal component is evident, which increases in some quarters of each period. This can be explained in the context of the dependent variable with seasonalities in the demand for goods and services, economic events such as trade fairs or tax seasons. , or even seasonal patterns in the availability of natural resources. All this means that in some parts of each year FDI increases and decreases periodically.Regarding the residual random component, some noise is seen in the time series, especially in the period 2000-2005, 2013-2015 and 2020 to 2022. This is due to variations in the time series that cannot be explained with seasonality components or trends in the time series. This, in a real context, can be explained with phenomena such as the new change of government in 2000, the constitutional reforms of President Enrique Peña Nieto in 2013 and the COVID-19 pandemic starting in 2023.
# The stationarity of the series is checked with the following ADF test.
adf.test(time_serie)
##
## Augmented Dickey-Fuller Test
##
## data: time_serie
## Dickey-Fuller = -4.1994, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
The result of the Augmented Dickey-Fuller Test (ADF) with a p-value of 0.01 (less than 0.05) indicates that the time series “time_series” is stationary, which means that it does not show trends over time.
acf(time_serie,main="Significant Autocorrelations")
We can observe that the series shows a bit of serial compensation, since
in some periods the autocorrelation function exceeds the lines of
significance, being considered significantly different from 0. There is
a positive compensation.
Para disminuir la autocorrelación serial, se aplicará la transformación por diferencias.
summary(arma<-arma(diff(time_serie)),order=c(1,1))
##
## Call:
## arma(x = diff(time_serie))
##
## Model:
## ARMA(1,1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8047.0 -1977.9 -165.4 1756.3 13992.5
##
## Coefficient(s):
## Estimate Std. Error t value Pr(>|t|)
## ar1 -0.05194 0.10845 -0.479 0.63197
## ma1 -0.97543 0.03501 -27.862 < 2e-16 ***
## intercept 58.96177 19.46823 3.029 0.00246 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Fit:
## sigma^2 estimated as 15563059, Conditional Sum-of-Squares = 1454474503, AIC = 1848.84
plot(arma)
These coefficients indicate a weak negative correlation with the
previous value and a strong negative correlation with the error in the
previous period, respectively. Additionally, an intercept term with an
estimated value of 58.96177 has been included.
The model residuals have an estimated variance (sigma^2) of 15563059 and the fitting results show a very high AIC.
summary(arima<-Arima(diff(log((time_serie))),order=c(1,1,1)))
## Series: diff(log((time_serie)))
## ARIMA(1,1,1)
##
## Coefficients:
## ar1 ma1
## -0.279 -1.0000
## s.e. 0.099 0.0293
##
## sigma^2 = 0.4561: log likelihood = -98.04
## AIC=202.07 AICc=202.34 BIC=209.7
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.02677064 0.6646252 0.5066154 55.71132 193.1466 0.8243796
## ACF1
## Training set -0.1508687
plot(arima)
The autoregressive coefficient (AR1) is -0.279 and the moving average
coefficient (MA1) is -1.0000. These coefficients indicate that the
current value of the log-differentiated time series is negatively
correlated with its previous value and with the error in the previous
period.
The estimated variance of the model (sigma^2) is 0.4561. The log likelihood value is -98.04, and the information criteria, such as the AIC (Akaike Information Criterion), the corrected AIC (AICc) and the BIC (Bayesian Information Criterion), indicate that this model could be appropriate for the time series.
<-arma$residuals
arma_residualsBox.test(arma_residuals,lag=1,type="Ljung-Box")
##
## Box-Ljung test
##
## data: arma_residuals
## X-squared = 0.027764, df = 1, p-value = 0.8677
The p value obtained in the Box-Ljung test (0.8677) is greater than the maximum p value commonly used, which is 0.05. This means that no significant evidence of autocorrelation was found in the residuals, as the p-value is greater than 0.05, supporting the validity of the model in terms of autocorrelation.
#Testing residuals
suppressWarnings({
$residuals <- na.omit(arma$residuals)
armaadf.test(arma$residuals)
})
##
## Augmented Dickey-Fuller Test
##
## data: arma$residuals
## Dickey-Fuller = -4.2629, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
The p value of 0.01, less than the threshold of 0.05, indicates strong evidence against the null hypothesis of non-stationarity. This means that the residuals are unlikely to be non-stationary.
suppressWarnings({
$fitted.values <- na.omit(arma$fitted.values)
armaadf.test(arma$fitted.values)
})
##
## Augmented Dickey-Fuller Test
##
## data: arma$fitted.values
## Dickey-Fuller = -4.0962, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
Compared to the commonly used critical significance value of 0.05 (or 0.5 in decimal terms), the p-value (0.01) is significantly lower, indicating that there is strong evidence against the null hypothesis of non-stationarity in the fitted values. Consequently, the hypothesis that the fitted values are stationary is accepted.
hist(arma$residuals)
Normality is seen in the residuals.
<-arima$residuals
arima_residualsBox.test(arima_residuals,lag=1,type="Ljung-Box")
##
## Box-Ljung test
##
## data: arima_residuals
## X-squared = 2.2313, df = 1, p-value = 0.1352
The p value obtained in the Box-Ljung test (0.1352) is greater than the maximum p value commonly used, which is 0.05. This means that no significant evidence of autocorrelation was found in the residuals, as the p-value is greater than 0.05, supporting the validity of the model in terms of autocorrelation.
#Testing residuals
suppressWarnings({
$residuals <- na.omit(arima$residuals)
arimaadf.test(arima$residuals)
})
##
## Augmented Dickey-Fuller Test
##
## data: arima$residuals
## Dickey-Fuller = -5.5467, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
The p value of 0.01, less than the threshold of 0.05, indicates strong evidence against the null hypothesis of non-stationarity. This means that the residuals are unlikely to be non-stationary.
hist(arima$residuals)
Normality is seen in the residuals.
Since both models meet the diagnostic tests, the ARIMA model 2 is chosen since it has a very low AIC value.
suppressWarnings({
<-exp(arima$fitted) # The variables are transformed back to the originals (if log is applied, the exponential must be applied (it is the opposite))
arima_restauracion=c(arima_restauracion) #reverting "log" operation using "exp"
vector2 <-c(time_serie) #Converting into a vector.
original2 = vector2+original2 #reverting "diff" operation summing the original values to the differences.
restauracion2 <- ts(restauracion2, start = 1, end = length(restauracion2), frequency = 4) #Make time series
ts2 })
# Forecast (ARMA)
<-forecast(ts2,h=5)
arima_forecast arima_forecast
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 96 Q2 7100.194 2642.222 11558.167 282.3144 13918.07
## 96 Q3 5612.732 2088.687 9136.777 223.1705 11002.29
## 96 Q4 5774.173 2148.765 9399.581 229.5894 11318.76
## 97 Q1 10120.921 3766.336 16475.506 402.4214 19839.42
## 97 Q2 7104.122 2643.391 11564.852 282.0227 13926.22
plot(arima_forecast)
autoplot(arima_forecast)
<- ts(dataf$periodo, frequency = 1, start = c(1997))
periodo_ts
<- ts(dataf$IED_Flujos, start = c(1997), end = c(2022), frequency = 1)
IED_Flujos ts_plot(IED_Flujos)
<- ts(dataf$Empleo, start = c(1997), end = c(2022), frequency = 1)
Empleo ts_plot(Empleo)
<- ts(dataf$Educacion, start = c(1997), end = c(2022), frequency = 1)
Educacion ts_plot(Educacion)
<- ts(dataf$Salario_Diario, start = c(1997), end = c(2022), frequency = 1)
Salario_Diario ts_plot(Salario_Diario)
<- ts(dataf$Innovacion, start = c(1997), end = c(2022), frequency = 1)
Innovacion ts_plot(Innovacion)
<- ts(dataf$Inseguridad_Robo, start = c(1997), end = c(2022), frequency = 1)
Inseguridad_Robo ts_plot(Inseguridad_Robo)
<- ts(dataf$Inseguridad_Homicidio, start = c(1997), end = c(2022), frequency = 1)
Inseguridad_Homicidio ts_plot(Inseguridad_Homicidio)
<- ts(dataf$Tipo_de_Cambio, start = c(1997), end = c(2022), frequency = 1)
Tipo_de_Cambio ts_plot(Tipo_de_Cambio)
<- ts(dataf$Densidad_Carretera, start = c(1997), end = c(2022), frequency = 1)
Densidad_Carretera ts_plot(Densidad_Carretera)
<- ts(dataf$Densidad_Poblacion, start = c(1997), end = c(2022), frequency = 1)
Densidad_Poblacion ts_plot(Densidad_Poblacion)
<- ts(dataf$CO2_Emisiones, start = c(1997), end = c(2022), frequency = 1)
CO2_Emisiones ts_plot(CO2_Emisiones)
<- ts(dataf$PIB_Per_Capita, start = c(1997), end = c(2022), frequency = 1)
PIB_Per_Capita ts_plot(PIB_Per_Capita)
<- ts(dataf$Exportaciones, start = c(1997), end = c(2022), frequency = 1)
Exportaciones ts_plot(Exportaciones)
<- ts(dataf$INPC, start = c(1997), end = c(2022), frequency = 1)
INPC ts_plot(INPC)
Education: As seen in the time series, it is related to the dependent variable FDI, since both show an upward trend throughout the time series. This makes sense because in a real context, foreign direct investment (FDI) is accompanied by better education indices
Daily_Salary: The time series shows that the daily salary is equally positive with the dependent variable, since in the long term, both show a positive trend. This makes sense in a real context, the arrival of Foreign Investment causes salaries to rise.
Innovation: The time series suggests a positive relationship between innovation and FDI, since both tend to increase over time in a similar way. This is consistent with the idea that foreign companies seek environments conducive to research and development, and tend to invest in countries with an innovative environment.
Insecurity_Robbery: The time series shows a possible negative relationship between insecurity due to theft and FDI, since as FDI increases, insecurity due to theft tends to decrease. In a real-world context, this makes sense, as security is a major concern for investors, and a decrease in insecurity can make a country more attractive for FDI.
Exchange_Rate: The time series suggests a complex relationship between the exchange rate and FDI. Changes in the exchange rate can affect the profitability of foreign investments, but they can also create uncertainty. In a real-world context, exchange rate volatility and its impact on FDI may depend on broader economic and political factors.
Road_Density: The time series indicates a possible positive relationship between road density and FDI, as both tend to increase over time. This makes sense in a real context, as a developed transportation infrastructure can facilitate logistics and trade, which attracts investors.
Population_Density: The time series shows a possible positive relationship between population density and FDI. Countries with densely populated markets can attract foreign investment due to the potential for sales and growth in those markets.
CO2_Emissions: The time series does not show a clear relationship between CO2 emissions and FDI. This could be because foreign companies consider multiple environmental and regulatory factors when making investment decisions.
GDP_Per_Capita: The time series suggests a possible positive relationship between GDP per capita and FDI. Countries with a higher GDP per capita tend to attract foreign investment due to a larger market and consumers with greater purchasing power.
INPC (National Consumer Price Index): The time series shows a slight positive relationship, something completely logical because a moderate increase in the country’s inflation is a sign of a healthy economy that is growing and that is attractive for nearshoring.
Exports: A positive relationship is seen since a country that is attractive for nearshoring tends to increase its exports due to the productive capacity it has and everything it exports to international companies.
This analysis allows us to understand which variables appear to have an influence on the dependent variable throughout the time series.
Due to their relationships with the dependent variable, exports, exchange rate, GDP and INPC will be chosen as explanatory variables of a VAR model.
adf.test(Exportaciones)
##
## Augmented Dickey-Fuller Test
##
## data: Exportaciones
## Dickey-Fuller = -2.2975, Lag order = 2, p-value = 0.4591
## alternative hypothesis: stationary
adf.test(Tipo_de_Cambio)
##
## Augmented Dickey-Fuller Test
##
## data: Tipo_de_Cambio
## Dickey-Fuller = -2.386, Lag order = 2, p-value = 0.4254
## alternative hypothesis: stationary
adf.test(PIB_Per_Capita)
##
## Augmented Dickey-Fuller Test
##
## data: PIB_Per_Capita
## Dickey-Fuller = -2.5796, Lag order = 2, p-value = 0.3516
## alternative hypothesis: stationary
adf.test(INPC)
##
## Augmented Dickey-Fuller Test
##
## data: INPC
## Dickey-Fuller = 2.4665, Lag order = 2, p-value = 0.99
## alternative hypothesis: stationary
adf.test(IED_Flujos)
##
## Augmented Dickey-Fuller Test
##
## data: IED_Flujos
## Dickey-Fuller = -2.0122, Lag order = 2, p-value = 0.5677
## alternative hypothesis: stationary
Since the P value is greater in all cases than the p value of 0.05, there is not enough evidence to reject the null hypothesis of nonstationarity, so all time series are nonstationary.
<-cbind(diff(log(IED_Flujos)), diff(log(Exportaciones)),diff(log(Tipo_de_Cambio)),diff(log(PIB_Per_Capita)), diff(log(INPC)))
var_tscolnames(var_ts)<-cbind("IED","Exports","CHange rate","GDP","INPC")
head(var_ts)
## Time Series:
## Start = 1998
## End = 2003
## Frequency = 1
## IED Exports CHange rate GDP INPC
## 1998 -0.3328258 0.12216954 0.20965346 -0.0065384499 0.17058427
## 1999 0.3516286 -0.05254521 -0.04317217 0.0189605305 0.11634631
## 2000 0.1904912 0.04999471 0.00836825 0.0131535699 0.08575137
## 2001 0.4102348 -0.18829632 -0.04582581 -0.0215602892 0.04294766
## 2002 -0.1544453 0.12011329 0.12201495 0.0009557949 0.05553769
## 2003 -0.2390511 0.13736474 0.07796154 0.0041412226 0.03899703
# Convierte tus datos en una serie temporal
<- ts(var_ts, frequency = 1, start = c(1997))
var_ts
# Realiza la selección de rezagos
<- VARselect(var_ts)
lag_selection
# Imprime los resultados
$selection lag_selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 3 3 3 2
$criteria lag_selection
## 1 2 3 4 5 6 7 8 9 10
## AIC(n) -2.996594e+01 NaN -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
## HQ(n) -2.998103e+01 NaN -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
## SC(n) -2.854984e+01 NaN -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
## FPE(n) 1.226483e-13 -2.753251e-27 0 0 0 0 0 0 0 0
var_ts
## Time Series:
## Start = 1997
## End = 2021
## Frequency = 1
## IED Exports CHange rate GDP INPC
## 1997 -0.3328258167 0.12216954 0.209653464 -0.0065384499 0.17058427
## 1998 0.3516285761 -0.05254521 -0.043172172 0.0189605305 0.11634631
## 1999 0.1904911522 0.04999471 0.008368250 0.0131535699 0.08575137
## 2000 0.4102348012 -0.18829632 -0.045825812 -0.0215602892 0.04294766
## 2001 -0.1544452519 0.12011329 0.122014951 0.0009557949 0.05553769
## 2002 -0.2390511148 0.13736474 0.077961541 0.0041412226 0.03899703
## 2003 0.2664664748 -0.01765435 0.001784122 0.0292833678 0.05065264
## 2004 -0.0485349505 0.11394502 -0.046520016 0.0028441706 0.03272897
## 2005 -0.2186285687 0.03615943 0.015748357 0.0219753239 0.03969937
## 2006 0.3872999150 0.05337562 0.001836548 0.0138908716 0.03695426
## 2007 0.0769619346 0.04932858 0.233729524 -0.0191945887 0.06328870
## 2008 -0.5919653541 0.06248208 -0.054470756 -0.0296037143 0.03502166
## 2009 0.3257949987 0.04540176 -0.051939289 0.0282390803 0.04308778
## 2010 0.0251260056 0.15474024 0.121545470 0.0284824237 0.03745854
## 2011 -0.2719216084 -0.03090354 -0.073447906 0.0188174065 0.03511348
## 2012 0.7652471159 0.01868257 0.006139697 0.0180776544 0.03894858
## 2013 -0.3861679261 0.21415235 0.119566703 0.0217274493 0.04001470
## 2014 0.3111388902 0.08629861 0.163129741 0.0145329883 0.02110836
## 2015 0.0002678477 0.18831039 0.175183492 0.0188395803 0.03302526
## 2016 -0.0242509147 -0.05082482 -0.045552430 0.0062867311 0.06549553
## 2017 -0.0181637830 0.03822088 -0.004060919 -0.0006652097 0.01655099
## 2018 -0.0856381189 -0.06961734 -0.041012755 -0.0191243567 0.05850872
## 2019 -0.1795515069 0.14459429 0.055154405 -0.0520788845 0.03104338
## 2020 0.0698284662 0.04698442 0.028672256 0.0011395983 0.07099812
## 2021 0.0069226501 -0.09667247 -0.055611623 0.0280041053 0.07526419
<-VAR(var_ts,p=1)
var_modelosummary(var_modelo)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: IED, Exports, CHange.rate, GDP, INPC
## Deterministic variables: const
## Sample size: 24
## Log Likelihood: 204.237
## Roots of the characteristic polynomial:
## 0.4672 0.4063 0.4063 0.2734 0.1337
## Call:
## VAR(y = var_ts, p = 1)
##
##
## Estimation results for equation IED:
## ====================================
## IED = IED.l1 + Exports.l1 + CHange.rate.l1 + GDP.l1 + INPC.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## IED.l1 -0.59904 0.20371 -2.941 0.00874 **
## Exports.l1 0.17941 0.87417 0.205 0.83969
## CHange.rate.l1 -1.38743 0.77644 -1.787 0.09080 .
## GDP.l1 5.12986 2.72816 1.880 0.07635 .
## INPC.l1 2.38646 1.64194 1.453 0.16331
## const -0.04874 0.10846 -0.449 0.65850
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.2375 on 18 degrees of freedom
## Multiple R-Squared: 0.5062, Adjusted R-squared: 0.369
## F-statistic: 3.69 on 5 and 18 DF, p-value: 0.01788
##
##
## Estimation results for equation Exports:
## ========================================
## Exports = IED.l1 + Exports.l1 + CHange.rate.l1 + GDP.l1 + INPC.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## IED.l1 0.06679 0.08047 0.830 0.4174
## Exports.l1 -0.34871 0.34530 -1.010 0.3259
## CHange.rate.l1 0.22065 0.30669 0.719 0.4811
## GDP.l1 -0.15513 1.07762 -0.144 0.8871
## INPC.l1 -1.04610 0.64856 -1.613 0.1241
## const 0.10769 0.04284 2.514 0.0217 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.09379 on 18 degrees of freedom
## Multiple R-Squared: 0.2422, Adjusted R-squared: 0.03175
## F-statistic: 1.151 on 5 and 18 DF, p-value: 0.3705
##
##
## Estimation results for equation CHange.rate:
## ============================================
## CHange.rate = IED.l1 + Exports.l1 + CHange.rate.l1 + GDP.l1 + INPC.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## IED.l1 0.12230 0.07352 1.664 0.114
## Exports.l1 0.12502 0.31547 0.396 0.697
## CHange.rate.l1 -0.06550 0.28020 -0.234 0.818
## GDP.l1 -0.19695 0.98455 -0.200 0.844
## INPC.l1 -0.61899 0.59255 -1.045 0.310
## const 0.05402 0.03914 1.380 0.184
##
##
## Residual standard error: 0.08569 on 18 degrees of freedom
## Multiple R-Squared: 0.2296, Adjusted R-squared: 0.01566
## F-statistic: 1.073 on 5 and 18 DF, p-value: 0.4077
##
##
## Estimation results for equation GDP:
## ====================================
## GDP = IED.l1 + Exports.l1 + CHange.rate.l1 + GDP.l1 + INPC.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## IED.l1 -0.003598 0.017827 -0.202 0.842
## Exports.l1 0.110684 0.076499 1.447 0.165
## CHange.rate.l1 -0.077042 0.067946 -1.134 0.272
## GDP.l1 0.261750 0.238741 1.096 0.287
## INPC.l1 0.065769 0.143686 0.458 0.653
## const -0.001324 0.009491 -0.140 0.891
##
##
## Residual standard error: 0.02078 on 18 degrees of freedom
## Multiple R-Squared: 0.2328, Adjusted R-squared: 0.01972
## F-statistic: 1.093 on 5 and 18 DF, p-value: 0.3981
##
##
## Estimation results for equation INPC:
## =====================================
## INPC = IED.l1 + Exports.l1 + CHange.rate.l1 + GDP.l1 + INPC.l1 + const
##
## Estimate Std. Error t value Pr(>|t|)
## IED.l1 0.021521 0.015130 1.422 0.17201
## Exports.l1 0.103612 0.064928 1.596 0.12794
## CHange.rate.l1 -0.042051 0.057669 -0.729 0.47527
## GDP.l1 -0.404239 0.202632 -1.995 0.06142 .
## INPC.l1 0.467131 0.121954 3.830 0.00123 **
## const 0.021477 0.008056 2.666 0.01575 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.01764 on 18 degrees of freedom
## Multiple R-Squared: 0.5108, Adjusted R-squared: 0.375
## F-statistic: 3.76 on 5 and 18 DF, p-value: 0.0166
##
##
##
## Covariance matrix of residuals:
## IED Exports CHange.rate GDP INPC
## IED 0.0563852 -0.0044155 5.779e-03 8.444e-04 0.0017165
## Exports -0.0044155 0.0087974 4.803e-03 4.653e-04 -0.0005481
## CHange.rate 0.0057786 0.0048033 7.343e-03 -2.770e-07 -0.0001313
## GDP 0.0008444 0.0004653 -2.770e-07 4.318e-04 0.0001003
## INPC 0.0017165 -0.0005481 -1.313e-04 1.003e-04 0.0003111
##
## Correlation matrix of residuals:
## IED Exports CHange.rate GDP INPC
## IED 1.0000 -0.1983 0.2839843 0.1711215 0.40987
## Exports -0.1983 1.0000 0.5976060 0.2387203 -0.33132
## CHange.rate 0.2840 0.5976 1.0000000 -0.0001555 -0.08686
## GDP 0.1711 0.2387 -0.0001555 1.0000000 0.27357
## INPC 0.4099 -0.3313 -0.0868572 0.2735736 1.00000
<-data.frame(residuals(var_modelo))
var_residualsadf.test(var_residuals$IED)
##
## Augmented Dickey-Fuller Test
##
## data: var_residuals$IED
## Dickey-Fuller = -2.4594, Lag order = 2, p-value = 0.3974
## alternative hypothesis: stationary
<-data.frame(residuals(var_modelo))
var_residualsadf.test(var_residuals$IED)
##
## Augmented Dickey-Fuller Test
##
## data: var_residuals$IED
## Dickey-Fuller = -2.4594, Lag order = 2, p-value = 0.3974
## alternative hypothesis: stationary
The p-value obtained in the Augmented Dickey-Fuller Test for the residual series is 0.3974, which indicates that we do not have enough evidence to reject the null hypothesis that the time series is not stationary, in contrast to used significance level of 0.05.
Box.test(var_residuals$IED,lag=2,type="Ljung-Box")
##
## Box-Ljung test
##
## data: var_residuals$IED
## X-squared = 1.9948, df = 2, p-value = 0.3688
The p-value obtained in the Box-Ljung test for the series of residuals is 0.3746, which suggests that we do not have enough evidence to reject the null hypothesis that the residuals do not have significant autocorrelation in the first 2 lags, since the p-value is greater than the conventional significance level of 0.05. There is no autocorrelation.
The estimated coefficient for the relationship between FDI in the current period and its value in the previous period (FDI.l1) is -0.59904, and is found to be highly significant with a p value equal to 0.00874. This implies that there is a strong negative relationship between foreign direct investment in the present and its level in the past. In other words, a decline in foreign direct investment in one period tends to be associated with an even larger decline in the following period, and vice versa. This finding is crucial and suggests the existence of inertia effects in FDI.
On the other hand, when examining the other endogenous variables, it is observed that Exports does not show a significant relationship with its previous value, while CHange.rate, which represents the exchange rate, exhibits a negative relationship with its previous value, although with a marginal significance level. Furthermore, GDP, which measures the Gross Domestic Product, presents a positive but not significant relationship with its value in the previous period. Finally, INPC, the National Consumer Price Index, does not show a significant relationship with its previous value.
In summary, the analysis of the FDI variable indicates that changes in foreign direct investment are strongly influenced by its own past behavior, which suggests the existence of an inertia dynamic in this variable.
# Granger causality testing each variable against all the others.
# There could be a unidirectional, bidirectional, or no causality relationships between variables.
<-causality(var_modelo,cause="IED")
granger_ granger_
## $Granger
##
## Granger causality H0: IED do not Granger-cause Exports CHange.rate GDP
## INPC
##
## data: VAR object var_modelo
## F-Test = 1.5522, df1 = 4, df2 = 90, p-value = 0.194
##
##
## $Instant
##
## H0: No instantaneous causality between: IED and Exports CHange.rate GDP
## INPC
##
## data: VAR object var_modelo
## Chi-squared = 7.1644, df = 4, p-value = 0.1275
The Granger causality test, having a p value greater than 0.05 and not being able to reject the null hypothesis, suggests that the variable “FDI” (Foreign Direct Investment) does not have a significant causal relationship with any of the other variables included in the VAR model, which implies that none of these variables can effectively predict changes in “FDI”.
# forecasting
<-predict(var_modelo,n.ahead=5,ci=0.95) ### forecast for the next 12 months
forecast_2fanchart(forecast_2,names="IED",main="IED",xlab="Time Period",ylab="IED")
forecast_2
## $IED
## fcst lower upper CI
## [1,] 0.33019639 -0.1352084 0.7956012 0.4654048
## [2,] -0.11697735 -0.7549566 0.5210019 0.6379793
## [3,] 0.08101437 -0.5849769 0.7470057 0.6659913
## [4,] 0.02925057 -0.6392504 0.6977515 0.6685009
## [5,] 0.02707027 -0.6415849 0.6957254 0.6686551
##
## $Exports
## fcst lower upper CI
## [1,] 0.04651332 -0.1373209 0.2303475 0.1838342
## [2,] 0.07204198 -0.1234657 0.2675496 0.1955076
## [3,] 0.03879860 -0.1623257 0.2399229 0.2011243
## [4,] 0.05559769 -0.1460767 0.2572721 0.2016744
## [5,] 0.05140726 -0.1503453 0.2531598 0.2017526
##
## $CHange.rate
## fcst lower upper CI
## [1,] -0.005684022 -0.17364048 0.1622724 0.1679565
## [2,] 0.076308430 -0.09856353 0.2511804 0.1748720
## [3,] 0.011771510 -0.17166335 0.1952064 0.1834349
## [4,] 0.039794698 -0.14516449 0.2247539 0.1849592
## [5,] 0.033096710 -0.15201686 0.2182103 0.1851136
##
## $GDP
## fcst lower upper CI
## [1,] 0.004515092 -0.03621241 0.04524260 0.04072750
## [2,] 0.006740711 -0.03968149 0.05316291 0.04642220
## [3,] 0.006209081 -0.04025079 0.05266896 0.04645987
## [4,] 0.006264122 -0.04021762 0.05274587 0.04648175
## [5,] 0.006231192 -0.04025090 0.05271329 0.04648210
##
## $INPC
## fcst lower upper CI
## [1,] 0.03778561 0.003218110 0.07235311 0.03456750
## [2,] 0.04946690 0.009969620 0.08896418 0.03949728
## [3,] 0.04359742 0.002300980 0.08489385 0.04129644
## [4,] 0.04460095 0.003060193 0.08614170 0.04154076
## [5,] 0.04449565 0.002859088 0.08613220 0.04163656
It is necessary to bring the data back to the original scales to be able to interpret them in a simple way, which is why it is necessary to reverse the transformations made of differentiation and logarithm.
#Transform the scales, reverse the transformations made
$fcst$IED <- exp(forecast_2$fcst$IED)
forecast_2
$fcst$IED[1] = forecast_2$fcst$IED[1] + tail(dataf$IED_Flujos, 1)
forecast_2$fcst$IED[2] = forecast_2$fcst$IED[2] + tail(dataf$IED_Flujos, 1)
forecast_2$fcst$IED[3] = forecast_2$fcst$IED[3] + tail(dataf$IED_Flujos, 2)
forecast_2$fcst$IED[4] = forecast_2$fcst$IED[4] + tail(dataf$IED_Flujos, 3)
forecast_2$fcst$IED[5] = forecast_2$fcst$IED[5] + tail(dataf$IED_Flujos, 4) forecast_2
$fcst$IED forecast_2
## fcst lower upper CI
## [1,] 555773.3 0.8735339 2.215773 1.592659
## [2,] 555772.8 0.4700310 1.683714 1.892652
## [3,] 551938.9 0.5571187 2.110671 1.946419
## [4,] 514712.7 0.5276878 2.009230 1.951310
## [5,] 615946.5 0.5264574 2.005163 1.951611
Forecast:
Periodo 1: 555,773.3 Periodo 2: 555,772.8 Periodo 3: 551,938.9 Periodo 4: 514,712.7 Periodo 5: 615,946.5
Foreign direct investment (FDI) forecasts for the next five periods offer some interesting insights. In the first period, FDI is expected to reach around 555,773.3, indicating some stability in foreign investments. However, in the second period the forecast is very similar, which suggests a continuity in this trend.
In the third period, a slight decrease in FDI is observed, standing at 551,938.9. This decrease could indicate a possible slowdown in the inflow of foreign investment. However, the situation changes significantly in the fourth period, where an FDI of 514,712.7 is expected, indicating a substantial drop in foreign investments. This could be a sign of uncertainty or negative factors affecting the investment.
In the fifth period, a notable increase in FDI is observed, reaching 615,946.5. Although still lower than the initial values, this increase could indicate a possible recovery or a positive change in the conditions for foreign investment.
All this forecasting with the previous models and the relationships of the endogenous variables is very important for making strategic decisions, since being able to forecast values as complex as Foreign Direct Investment allows us to anticipate certain circumstances for many companies and thus be better prepared for the phenomenon of nearshoring and being able to use it for the growth of many companies and our society. This will help Maria in her analysis of nearshoring for the company where she works.
In summary, the phenomenon of Nearshoring is presented as a fascinating and highly dynamic field of study. As evidenced in our time series analysis, the historical evolution of this practice is not linear and is subject to significant fluctuations. These oscillations are due to a wide range of variables, both national and international, including economic, political and social aspects.
In the economic sphere, Nearshoring is influenced by factors such as labor costs, exchange rates, and import and export tariffs. These elements are constantly changing and influenced by global market conditions and government policies (Doh, 2005). Furthermore, political conditions, such as government stability and diplomatic relations, can play a crucial role in the attractiveness of a country as a nearshoring destination (Jahns, Hartmann, & Bals, 2006).
From a social perspective, Nearshoring is also affected by the organizational culture, skills and education of the workforce in the destination country, which can vary significantly from one country to another (Kedia & Lahiri, 2007).
Since Nearshoring is a phenomenon very sensitive to a multiplicity of factors, it is extremely challenging to develop robust predictive models. This is especially true in the context of Mexico, a country that is emerging as a major player in the field of Nearshoring (Manning, Massini, & Lewin, 2008).
Finally, considering the emergence of new technologies such as artificial intelligence and automation, the future of Nearshoring is destined to transform in ways that are still difficult to anticipate. Therefore, it will be crucial to continue researching and analyzing this phenomenon from a multidisciplinary perspective, paying special attention to how Mexico will position itself in this changing global scenario.
Saucedo, D. (2023). Mexico and its attractiveness for nearshoring. CIC. https://cic.itesm.mx/Paginas/Pagina-DocumentoCic.aspx?id=1860
Velazqued, D. (2011). ANÁLISIS Y PREDICCIÓN DE SERIES DE TIEMPO EN MERCADOS DE ENERGÍA USANDO EL LENGUAJE R. Scielo. http://www.scielo.org.co/scielo.php?script=sci_arttext&pid=S0012-73532011000100030
Cardona, S. (2023). Nearshoring en México: una oportunidad histórica para la economía del futuro. Forbes México. forbes.com.mx/nearshoring-en-mexico-una-oportunidad-historica-para-la-economia-del-futuro/
Doh, J. P. (2005). Offshore Outsourcing: Implications for International Business and Strategic Management Theory and Practice. Journal of Management Studies, 42(3), 695-704.
Jahns, C., Hartmann, E., & Bals, L. (2006). Offshoring: Dimensions and Diffusion of a New Business Concept. Journal of Purchasing & Supply Management, 12(4), 218-231.
Kedia, B. L., & Lahiri, S. (2007). International Outsourcing of Services: A Partnership Model. Journal of International Management, 13(1), 22-37.