#install.packages("shiny")
library(shiny)
#install.packages("WDI")
library(WDI)
#install.packages("wbstats")
library(wbstats)
#install.packages("tidyverse")
library(ggplot2)
#install.packages("plm")
library(plm)
#install.packages("gplots")
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
PIB_MEX <- wb_data(country = "MX", indicator = "NY.GDP.PCAP.CD",
start_date = 1900, end_date = 2025)
summary(PIB_MEX)
## iso2c iso3c country date
## Length:64 Length:64 Length:64 Min. :1960
## Class :character Class :character Class :character 1st Qu.:1976
## Mode :character Mode :character Mode :character Median :1992
## Mean :1992
## 3rd Qu.:2007
## Max. :2023
## NY.GDP.PCAP.CD unit obs_status footnote
## Min. : 355.1 Length:64 Length:64 Length:64
## 1st Qu.: 1427.8 Class :character Class :character Class :character
## Median : 4006.5 Mode :character Mode :character Mode :character
## Mean : 5097.1
## 3rd Qu.: 8905.4
## Max. :13790.0
## last_updated
## Min. :2025-01-28
## 1st Qu.:2025-01-28
## Median :2025-01-28
## Mean :2025-01-28
## 3rd Qu.:2025-01-28
## Max. :2025-01-28
ggplot(PIB_MEX, aes(x = date, y = NY.GDP.PCAP.CD)) +
geom_point() +
geom_line() +
labs(title="PIB per capita en méxico (Current USD)", x="Año",
y ="Valor")
PIB_PANEL <- wb_data(country = c("MX","US","CA" ), indicator = "NY.GDP.PCAP.CD",
start_date = 1900, end_date = 2025)
summary(PIB_PANEL)
## iso2c iso3c country date
## Length:192 Length:192 Length:192 Min. :1960
## Class :character Class :character Class :character 1st Qu.:1976
## Mode :character Mode :character Mode :character Median :1992
## Mean :1992
## 3rd Qu.:2007
## Max. :2023
## NY.GDP.PCAP.CD unit obs_status footnote
## Min. : 355.1 Length:192 Length:192 Length:192
## 1st Qu.: 4059.2 Class :character Class :character Class :character
## Median :10544.4 Mode :character Mode :character Mode :character
## Mean :19152.2
## 3rd Qu.:29010.1
## Max. :82769.4
## last_updated
## Min. :2025-01-28
## 1st Qu.:2025-01-28
## Median :2025-01-28
## Mean :2025-01-28
## 3rd Qu.:2025-01-28
## Max. :2025-01-28
ggplot(PIB_PANEL, aes(x = date, y = NY.GDP.PCAP.CD, color = iso3c)) +
geom_point() +
geom_line() +
labs(title="PIB per capita en Norteamerica (Current USD)", x="Año",
y ="Valor")
MEGAPIB <- wb_data(country = c("MX","US","CA" ), indicator = c("NY.GDP.PCAP.CD","SP.DYN.LE00.IN"),
start_date = 1900, end_date = 2025)
summary(MEGAPIB)
## iso2c iso3c country date
## Length:192 Length:192 Length:192 Min. :1960
## Class :character Class :character Class :character 1st Qu.:1976
## Mode :character Mode :character Mode :character Median :1992
## Mean :1992
## 3rd Qu.:2007
## Max. :2023
##
## NY.GDP.PCAP.CD SP.DYN.LE00.IN
## Min. : 355.1 Min. :55.02
## 1st Qu.: 4059.2 1st Qu.:71.11
## Median :10544.4 Median :74.36
## Mean :19152.2 Mean :73.41
## 3rd Qu.:29010.1 3rd Qu.:77.49
## Max. :82769.4 Max. :82.22
## NA's :3
# Heterogeneidad
# Variación entre individuos
plotmeans(NY.GDP.PCAP.CD ~ country,main = "Heterogeneidad entre países", data = MEGAPIB)
## Warning in arrows(x, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## Warning in arrows(x, ui, x, pmin(y + gap, ui), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
# Interpretacion
# Alta Heterogeneidad: Si los puntos (medias) estan muy separados entre países
# Baja Heterogeneidad: Si los puntos (medias) estan cerca uno de otros
# En este caso, EUA y Canadá tienen un PIB per capita mayor que Mexico, mostrando alta heterogeneidad entre países
datos_panel<- pdata.frame(PIB_PANEL, index = c("country", "date"))
modeloefcfijos <- plm( NY.GDP.PCAP.CD ~ date, data=datos_panel , model = "within")
summary(modeloefcfijos)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = NY.GDP.PCAP.CD ~ date, data = datos_panel, model = "within")
##
## Balanced Panel: n = 3, T = 64, N = 192
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -22869.42 -3713.59 -740.79 4417.57 22788.54
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## date1961 19.689 7891.777 0.0025 0.9980133
## date1962 93.003 7891.777 0.0118 0.9906159
## date1963 182.117 7891.777 0.0231 0.9816255
## date1964 329.256 7891.777 0.0417 0.9667868
## date1965 493.812 7891.777 0.0626 0.9502057
## date1966 705.548 7891.777 0.0894 0.9289037
## date1967 836.074 7891.777 0.1059 0.9157965
## date1968 1051.287 7891.777 0.1332 0.8942375
## date1969 1278.661 7891.777 0.1620 0.8715461
## date1970 1483.079 7891.777 0.1879 0.8512361
## date1971 1757.600 7891.777 0.2227 0.8241196
## date1972 2139.145 7891.777 0.2711 0.7867884
## date1973 2652.616 7891.777 0.3361 0.7373364
## date1974 3306.205 7891.777 0.4189 0.6759711
## date1975 3736.686 7891.777 0.4735 0.6366822
## date1976 4425.604 7891.777 0.5608 0.5759388
## date1977 4698.806 7891.777 0.5954 0.5526405
## date1978 5234.634 7891.777 0.6633 0.5083487
## date1979 6060.354 7891.777 0.7679 0.4439640
## date1980 7072.576 7891.777 0.8962 0.3718573
## date1981 8188.133 7891.777 1.0376 0.3014655
## date1982 7987.390 7891.777 1.0121 0.3134224
## date1983 8523.654 7891.777 1.0801 0.2821751
## date1984 9312.706 7891.777 1.1801 0.2402027
## date1985 9796.257 7891.777 1.2413 0.2167918
## date1986 9909.818 7891.777 1.2557 0.2115431
## date1987 10895.002 7891.777 1.3806 0.1698612
## date1988 12362.836 7891.777 1.5665 0.1197288
## date1989 13585.668 7891.777 1.7215 0.0876150 .
## date1990 14316.347 7891.777 1.8141 0.0720442 .
## date1991 14759.335 7891.777 1.8702 0.0637741 .
## date1992 14990.000 7891.777 1.8994 0.0597918 .
## date1993 15667.517 7891.777 1.9853 0.0492832 *
## date1994 16091.651 7891.777 2.0390 0.0435376 *
## date1995 15978.167 7891.777 2.0247 0.0450159 *
## date1996 16773.055 7891.777 2.1254 0.0355067 *
## date1997 17769.387 7891.777 2.2516 0.0260772 *
## date1998 18030.354 7891.777 2.2847 0.0240026 *
## date1999 19236.904 7891.777 2.4376 0.0161811 *
## date2000 20835.037 7891.777 2.6401 0.0093360 **
## date2001 21096.198 7891.777 2.6732 0.0085083 **
## date2002 21538.969 7891.777 2.7293 0.0072554 **
## date2003 23202.118 7891.777 2.9400 0.0039054 **
## date2004 25366.654 7891.777 3.2143 0.0016609 **
## date2005 27852.977 7891.777 3.5294 0.0005823 ***
## date2006 30232.924 7891.777 3.8309 0.0002003 ***
## date2007 32408.252 7891.777 4.1066 7.172e-05 ***
## date2008 33394.731 7891.777 4.2316 4.431e-05 ***
## date2009 30291.171 7891.777 3.8383 0.0001950 ***
## date2010 33440.081 7891.777 4.2373 4.333e-05 ***
## date2011 35778.148 7891.777 4.5336 1.331e-05 ***
## date2012 36526.334 7891.777 4.6284 9.027e-06 ***
## date2013 37214.927 7891.777 4.7157 6.286e-06 ***
## date2014 37345.549 7891.777 4.7322 5.866e-06 ***
## date2015 35011.917 7891.777 4.4365 1.971e-05 ***
## date2016 34666.237 7891.777 4.3927 2.348e-05 ***
## date2017 36493.760 7891.777 4.6243 9.182e-06 ***
## date2018 38068.376 7891.777 4.8238 3.990e-06 ***
## date2019 38902.406 7891.777 4.9295 2.543e-06 ***
## date2020 37056.865 7891.777 4.6956 6.833e-06 ***
## date2021 42836.438 7891.777 5.4280 2.815e-07 ***
## date2022 46436.696 7891.777 5.8842 3.387e-08 ***
## date2023 48123.578 7891.777 6.0979 1.218e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 5.061e+10
## Residual Sum of Squares: 1.1771e+10
## R-Squared: 0.76742
## Adj. R-Squared: 0.64743
## F-statistic: 6.59909 on 63 and 126 DF, p-value: < 2.22e-16
modeloefcaleatorios <- plm( NY.GDP.PCAP.CD ~ date, data=datos_panel , model = "random")
summary(modeloefcaleatorios)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = NY.GDP.PCAP.CD ~ date, data = datos_panel, model = "random")
##
## Balanced Panel: n = 3, T = 64, N = 192
##
## Effects:
## var std.dev share
## idiosyncratic 93420218 9665 0.375
## individual 155441504 12468 0.625
## theta: 0.9035
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -24225.08 -3320.91 -892.17 5059.72 23751.53
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 1873.296 9107.904 0.2057 0.8370424
## date1961 19.689 7891.777 0.0025 0.9980093
## date1962 93.003 7891.777 0.0118 0.9905973
## date1963 182.117 7891.777 0.0231 0.9815890
## date1964 329.256 7891.777 0.0417 0.9667208
## date1965 493.812 7891.777 0.0626 0.9501065
## date1966 705.548 7891.777 0.0894 0.9287617
## date1967 836.074 7891.777 0.1059 0.9156280
## date1968 1051.287 7891.777 0.1332 0.8940250
## date1969 1278.661 7891.777 0.1620 0.8712866
## date1970 1483.079 7891.777 0.1879 0.8509338
## date1971 1757.600 7891.777 0.2227 0.8237590
## date1972 2139.145 7891.777 0.2711 0.7863449
## date1973 2652.616 7891.777 0.3361 0.7367774
## date1974 3306.205 7891.777 0.4189 0.6752578
## date1975 3736.686 7891.777 0.4735 0.6358628
## date1976 4425.604 7891.777 0.5608 0.5749430
## date1977 4698.806 7891.777 0.5954 0.5515726
## date1978 5234.634 7891.777 0.6633 0.5071370
## date1979 6060.354 7891.777 0.7679 0.4425272
## date1980 7072.576 7891.777 0.8962 0.3701483
## date1981 8188.133 7891.777 1.0376 0.2994785
## date1982 7987.390 7891.777 1.0121 0.3114828
## date1983 8523.654 7891.777 1.0801 0.2801120
## date1984 9312.706 7891.777 1.1801 0.2379796
## date1985 9796.257 7891.777 1.2413 0.2144858
## date1986 9909.818 7891.777 1.2557 0.2092195
## date1987 10895.002 7891.777 1.3806 0.1674170
## date1988 12362.836 7891.777 1.5665 0.1172207
## date1989 13585.668 7891.777 1.7215 0.0851607 .
## date1990 14316.347 7891.777 1.8141 0.0696648 .
## date1991 14759.335 7891.777 1.8702 0.0614537 .
## date1992 14990.000 7891.777 1.8994 0.0575059 .
## date1993 15667.517 7891.777 1.9853 0.0471115 *
## date1994 16091.651 7891.777 2.0390 0.0414460 *
## date1995 15978.167 7891.777 2.0247 0.0429023 *
## date1996 16773.055 7891.777 2.1254 0.0335546 *
## date1997 17769.387 7891.777 2.2516 0.0243455 *
## date1998 18030.354 7891.777 2.2847 0.0223303 *
## date1999 19236.904 7891.777 2.4376 0.0147856 *
## date2000 20835.037 7891.777 2.6401 0.0082883 **
## date2001 21096.198 7891.777 2.6732 0.0075134 **
## date2002 21538.969 7891.777 2.7293 0.0063470 **
## date2003 23202.118 7891.777 2.9400 0.0032817 **
## date2004 25366.654 7891.777 3.2143 0.0013076 **
## date2005 27852.977 7891.777 3.5294 0.0004166 ***
## date2006 30232.924 7891.777 3.8309 0.0001277 ***
## date2007 32408.252 7891.777 4.1066 4.016e-05 ***
## date2008 33394.731 7891.777 4.2316 2.320e-05 ***
## date2009 30291.171 7891.777 3.8383 0.0001239 ***
## date2010 33440.081 7891.777 4.2373 2.262e-05 ***
## date2011 35778.148 7891.777 4.5336 5.799e-06 ***
## date2012 36526.334 7891.777 4.6284 3.685e-06 ***
## date2013 37214.927 7891.777 4.7157 2.409e-06 ***
## date2014 37345.549 7891.777 4.7322 2.221e-06 ***
## date2015 35011.917 7891.777 4.4365 9.143e-06 ***
## date2016 34666.237 7891.777 4.3927 1.119e-05 ***
## date2017 36493.760 7891.777 4.6243 3.759e-06 ***
## date2018 38068.376 7891.777 4.8238 1.408e-06 ***
## date2019 38902.406 7891.777 4.9295 8.245e-07 ***
## date2020 37056.865 7891.777 4.6956 2.658e-06 ***
## date2021 42836.438 7891.777 5.4280 5.699e-08 ***
## date2022 46436.696 7891.777 5.8842 4.000e-09 ***
## date2023 48123.578 7891.777 6.0979 1.074e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 5.0797e+10
## Residual Sum of Squares: 1.1958e+10
## R-Squared: 0.76459
## Adj. R-Squared: 0.64873
## Chisq: 415.742 on 63 DF, p-value: < 2.22e-16
phtest(modeloefcfijos, modeloefcaleatorios)
##
## Hausman Test
##
## data: NY.GDP.PCAP.CD ~ date
## chisq = 3.8736e-13, df = 63, p-value = 1
## alternative hypothesis: one model is inconsistent
(“https://hi9302-nahomi0yolanda-miguel0pulido.shinyapps.io/MODULO1/”)
#install.packages("WDI")
library(WDI)
#install.packages("wbstats")
library(wbstats)
#install.packages("tidyverse")
library(ggplot2)
#install.packages("plm")
library(plm)
#install.packages("readxl")
library(readxl)
#install.packages("lmtest")
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
#file.choose()
patentes <- read_excel("/Users/nahomi/Desktop/GENERACIÓN DE ESCENARIOS /MODULO1/PATENT 3.xls")
summary(patentes)
## cusip merger employ return
## Min. : 800 Min. :0.0000 Min. : 0.085 Min. :-73.022
## 1st Qu.:368514 1st Qu.:0.0000 1st Qu.: 1.227 1st Qu.: 5.128
## Median :501116 Median :0.0000 Median : 3.842 Median : 7.585
## Mean :514536 Mean :0.0177 Mean : 18.826 Mean : 8.003
## 3rd Qu.:754688 3rd Qu.:0.0000 3rd Qu.: 15.442 3rd Qu.: 10.501
## Max. :878555 Max. :1.0000 Max. :506.531 Max. : 48.675
## NA's :21 NA's :8
## patents patentsg stckpr rnd
## Min. : 0.0 Min. : 0.00 Min. : 0.1875 Min. : 0.0000
## 1st Qu.: 1.0 1st Qu.: 1.00 1st Qu.: 7.6250 1st Qu.: 0.6847
## Median : 3.0 Median : 4.00 Median : 16.5000 Median : 2.1456
## Mean : 22.9 Mean : 27.14 Mean : 22.6270 Mean : 29.3398
## 3rd Qu.: 15.0 3rd Qu.: 19.00 3rd Qu.: 29.2500 3rd Qu.: 11.9168
## Max. :906.0 Max. :1063.00 Max. :402.0000 Max. :1719.3535
## NA's :2
## rndeflt rndstck sales sic
## Min. : 0.0000 Min. : 0.125 Min. : 1.22 Min. :2000
## 1st Qu.: 0.4788 1st Qu.: 5.152 1st Qu.: 52.99 1st Qu.:2890
## Median : 1.4764 Median : 13.353 Median : 174.06 Median :3531
## Mean : 19.7238 Mean : 163.823 Mean : 1219.60 Mean :3333
## 3rd Qu.: 8.7527 3rd Qu.: 74.563 3rd Qu.: 728.96 3rd Qu.:3661
## Max. :1000.7876 Max. :9755.352 Max. :44224.00 Max. :9997
## NA's :157 NA's :3
## year
## Min. :2012
## 1st Qu.:2014
## Median :2016
## Mean :2016
## 3rd Qu.:2019
## Max. :2021
##
sum(is.na(patentes))
## [1] 191
sapply(patentes, function(x) sum(is.na(x))) #NA's por variable
## cusip merger employ return patents patentsg stckpr rnd
## 0 0 21 8 0 0 2 0
## rndeflt rndstck sales sic year
## 0 157 3 0 0
patentes1<- na.omit(patentes)
panel_patentes<- pdata.frame(patentes1, index = c("cusip", "year"))
#Modelo de efectos fijos
modeloefcfijospatentes <- plm( patents ~ year + employ + rnd + sales, data=panel_patentes , model = "within")
summary(modeloefcfijospatentes)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = patents ~ year + employ + rnd + sales, data = panel_patentes,
## model = "within")
##
## Unbalanced Panel: n = 215, T = 2-10, N = 2083
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -489.4890 -3.3728 -1.2357 2.1915 173.8734
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## year2013 7.0273e-01 2.0384e+00 0.3448 0.73032
## year2014 2.1730e+00 2.0365e+00 1.0670 0.28610
## year2015 3.3180e+00 2.0398e+00 1.6267 0.10397
## year2016 2.3211e+00 2.0433e+00 1.1359 0.25613
## year2017 3.4606e+00 2.0574e+00 1.6820 0.09273 .
## year2018 3.4205e+00 2.0669e+00 1.6549 0.09812 .
## year2019 4.1048e+00 2.0761e+00 1.9771 0.04817 *
## year2020 1.0469e-01 2.0873e+00 0.0502 0.96000
## year2021 -1.3158e+01 2.1088e+00 -6.2393 5.430e-10 ***
## employ 8.6377e-02 7.3322e-02 1.1780 0.23893
## rnd -1.8803e-01 1.4374e-02 -13.0818 < 2.2e-16 ***
## sales -2.7831e-03 4.2984e-04 -6.4748 1.212e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1090400
## Residual Sum of Squares: 772430
## R-Squared: 0.29162
## Adj. R-Squared: 0.20537
## F-statistic: 63.6733 on 12 and 1856 DF, p-value: < 2.22e-16
#Modelo de efectos aleatorios
modeloefcaleatoriospatentes <- plm(patents ~ employ + rnd + sales,
data = panel_patentes,
model = "random")
summary(modeloefcaleatoriospatentes)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = patents ~ employ + rnd + sales, data = panel_patentes,
## model = "random")
##
## Unbalanced Panel: n = 215, T = 2-10, N = 2083
##
## Effects:
## var std.dev share
## idiosyncratic 439.02 20.95 0.185
## individual 1935.07 43.99 0.815
## theta:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.6808 0.8511 0.8511 0.8491 0.8511 0.8511
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -436.65 -3.75 -2.40 0.04 0.13 207.39
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 14.76023715 3.35560217 4.3987 1.089e-05 ***
## employ 0.99144826 0.05486048 18.0722 < 2.2e-16 ***
## rnd -0.16626525 0.01494057 -11.1284 < 2.2e-16 ***
## sales -0.00383260 0.00044067 -8.6971 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1308300
## Residual Sum of Squares: 1025300
## R-Squared: 0.21629
## Adj. R-Squared: 0.21516
## Chisq: 575.067 on 3 DF, p-value: < 2.22e-16
#Prueba de hausman
phtest(modeloefcfijospatentes, modeloefcaleatoriospatentes)
##
## Hausman Test
##
## data: patents ~ year + employ + rnd + sales
## chisq = 213.3, df = 3, p-value < 2.2e-16
## alternative hypothesis: one model is inconsistent
# Pruebas de Heterocedasticidad para el modelo de efectos fijos
bptest(modeloefcfijospatentes)
##
## studentized Breusch-Pagan test
##
## data: modeloefcfijospatentes
## BP = 1472.4, df = 12, p-value < 2.2e-16
# Como el p-value <0.05, hay heterocedasticidad en los residuos (problema detectado)
# Pruebas de Heterocedasticidad para el modelo de efectos aleatorios
bptest(modeloefcaleatoriospatentes)
##
## studentized Breusch-Pagan test
##
## data: modeloefcaleatoriospatentes
## BP = 1468.8, df = 3, p-value < 2.2e-16
# Como el p-value <0.05, hay heterocedasticidad en los residuos (problema detectado)
# Prueba de autocorrelacion serial para el modelo de efectos fijos
pwartest(modeloefcfijospatentes)
##
## Wooldridge's test for serial correlation in FE panels
##
## data: modeloefcfijospatentes
## F = 93.757, df1 = 1, df2 = 1866, p-value < 2.2e-16
## alternative hypothesis: serial correlation
# Como el p-value es < 0.05, hay autocorrelación serial en errores
# Prueba de autocorrelacion serial para el modelo de efectos aleatorios
pbnftest(modeloefcaleatoriospatentes)
##
## modified Bhargava/Franzini/Narendranathan Panel Durbin-Watson Test
##
## data: patents ~ employ + rnd + sales
## DW = 0.86292
## alternative hypothesis: serial correlation in idiosyncratic errors
# Como el valor es <1.5 hay autocorrelacion positiva significativa
# Correcion del modelo con errores estandar robustos
coef_corregidos <- coeftest(modeloefcfijospatentes, vcov = vcovHC(modeloefcfijospatentes, type = "HC0"))
solo_coef <- coef_corregidos[,1]
datos_de_prueba <- data.frame(merger=0, employ=10, return=6,
patentsg = 24, stckpr = 48, rnd = 3, rndeflt = 3, rndstck = 16, sales = 344)
length(datos_de_prueba)
## [1] 9
print(datos_de_prueba)
## merger employ return patentsg stckpr rnd rndeflt rndstck sales
## 1 0 10 6 24 48 3 3 16 344
length(solo_coef)
## [1] 12
print(solo_coef)
## year2013 year2014 year2015 year2016 year2017
## 0.702733876 2.172965024 3.318045807 2.321062844 3.460617110
## year2018 year2019 year2020 year2021 employ
## 3.420536926 4.104813691 0.104687590 -13.157718147 0.086376625
## rnd sales
## -0.188032644 -0.002783103
prediccion <- sum(solo_coef*c(datos_de_prueba$merger,datos_de_prueba$employ, datos_de_prueba$return, datos_de_prueba$patentsg, datos_de_prueba$stckpr, datos_de_prueba$rnd, datos_de_prueba$rndeflt, datos_de_prueba$rndstck, datos_de_prueba$sales))
prediccion
## [1] -4240.448