Integrantes del equipo:
library(WDI)
library(wbstats)
library(tidyverse)
gob_data <- wb_data(country = c("MX","EC","Ca"), indicator = "NY.GDP.PCAP.CD", start_date=2013, end_date=2023)
panel <- select(gob_data,country,date,NY.GDP.PCAP.CD)
library(gplots)
library(plm)
eco_data<-wb_data(country = c("AR","US","MX","CN"), indicator = c("NY.GDP.MKTP.KD.ZG","SL.UEM.TOTL.ZS",
"AG.LND.AGRI.ZS", "AG.LND.ARBL.ZS", "EG.ELC.ACCS.ZS", "SP.POP.GROW", "GB.XPD.RSDV.GD.ZS"))
panel <- select(eco_data,country,date,NY.GDP.MKTP.KD.ZG)
panel <-subset(eco_data,date==2000 | date==2010 | date==2015 | date==2020)
panel <- pdata.frame(panel, index=c("country","date"))
plotmeans(panel$NY.GDP.MKTP.KD.ZG ~ panel$country,xlab="País",ylab="GDP",
mean.labels=TRUE, digits=-3,
col="red",connect=TRUE, main="Heterogeneidad entre paises")
plotmeans(panel$NY.GDP.MKTP.KD.ZG ~ panel$date,xlab="Años",ylab="GDP",
mean.labels=TRUE, digits=-3,
col="red", connect=TRUE, main="Heterogeneidad entre años")
Pregunta 1: La línea que une los promedios entre países presenta picos y entre años se mantiene una línea casi horizontal hasta llegar al año 2020, donde presenta picos más marcados.
Pregunta 2: Los intervalos de confianza se encuentran desfasados en ambas gráficas.
Pregunta 3: Sí existe heterogeneidad, lo que significa que hay una variación en los datos. Esto puede ser algo deseable en los datos debido a que esto nos permite encontrar diferencias entre las variables.
pooled<-plm(NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS+
AG.LND.AGRI.ZS+AG.LND.ARBL.ZS+EG.ELC.ACCS.ZS+SP.POP.GROW+GB.XPD.RSDV.GD.ZS , data=panel ,model = "pooling")
summary(pooled)
## Pooling Model
##
## Call:
## plm(formula = NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS +
## AG.LND.ARBL.ZS + EG.ELC.ACCS.ZS + SP.POP.GROW + GB.XPD.RSDV.GD.ZS,
## data = panel, model = "pooling")
##
## Balanced Panel: n = 4, T = 4, N = 16
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -8.1043 -1.9711 1.2967 2.3740 5.8281
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 108.49114 161.77765 0.6706 0.5193
## SL.UEM.TOTL.ZS -0.11244 0.70155 -0.1603 0.8762
## AG.LND.AGRI.ZS 1.07183 0.65102 1.6464 0.1341
## AG.LND.ARBL.ZS 2.14456 1.21025 1.7720 0.1102
## EG.ELC.ACCS.ZS -1.82557 1.44565 -1.2628 0.2384
## SP.POP.GROW -4.69836 4.18512 -1.1226 0.2906
## GB.XPD.RSDV.GD.ZS -1.70636 2.19119 -0.7787 0.4561
##
## Total Sum of Squares: 512.67
## Residual Sum of Squares: 236.86
## R-Squared: 0.53799
## Adj. R-Squared: 0.22998
## F-statistic: 1.74666 on 6 and 9 DF, p-value: 0.21687
within<-plm(NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS+
AG.LND.AGRI.ZS+AG.LND.ARBL.ZS+EG.ELC.ACCS.ZS+SP.POP.GROW+GB.XPD.RSDV.GD.ZS , data=panel ,model = "within")
summary(within)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS +
## AG.LND.ARBL.ZS + EG.ELC.ACCS.ZS + SP.POP.GROW + GB.XPD.RSDV.GD.ZS,
## data = panel, model = "within")
##
## Balanced Panel: n = 4, T = 4, N = 16
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -4.98771 -2.38596 0.41446 1.92653 5.64725
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## SL.UEM.TOTL.ZS -0.60572 0.97119 -0.6237 0.55579
## AG.LND.AGRI.ZS 3.29170 1.43542 2.2932 0.06167 .
## AG.LND.ARBL.ZS 0.47688 2.68288 0.1777 0.86477
## EG.ELC.ACCS.ZS 0.75577 3.26340 0.2316 0.82455
## SP.POP.GROW -3.77042 7.00843 -0.5380 0.60995
## GB.XPD.RSDV.GD.ZS -3.72381 7.02411 -0.5301 0.61505
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 401.22
## Residual Sum of Squares: 144.53
## R-Squared: 0.63977
## Adj. R-Squared: 0.099435
## F-statistic: 1.77603 on 6 and 6 DF, p-value: 0.25126
pFtest(within,pooled)
##
## F test for individual effects
##
## data: NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS + AG.LND.ARBL.ZS + ...
## F = 1.2777, df1 = 3, df2 = 6, p-value = 0.364
## alternative hypothesis: significant effects
walhus<-plm(NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS+
AG.LND.AGRI.ZS+AG.LND.ARBL.ZS+EG.ELC.ACCS.ZS+SP.POP.GROW+GB.XPD.RSDV.GD.ZS , data=panel ,model = "random", random.method = "walhus")
summary(walhus)
## Oneway (individual) effect Random Effect Model
## (Wallace-Hussain's transformation)
##
## Call:
## plm(formula = NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS +
## AG.LND.ARBL.ZS + EG.ELC.ACCS.ZS + SP.POP.GROW + GB.XPD.RSDV.GD.ZS,
## data = panel, model = "random", random.method = "walhus")
##
## Balanced Panel: n = 4, T = 4, N = 16
##
## Effects:
## var std.dev share
## idiosyncratic 19.349 4.399 1
## individual 0.000 0.000 0
## theta: 0
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -8.1043 -1.9711 1.2967 2.3740 5.8281
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 108.49114 161.77765 0.6706 0.50246
## SL.UEM.TOTL.ZS -0.11244 0.70155 -0.1603 0.87267
## AG.LND.AGRI.ZS 1.07183 0.65102 1.6464 0.09968 .
## AG.LND.ARBL.ZS 2.14456 1.21025 1.7720 0.07640 .
## EG.ELC.ACCS.ZS -1.82557 1.44565 -1.2628 0.20666
## SP.POP.GROW -4.69836 4.18512 -1.1226 0.26159
## GB.XPD.RSDV.GD.ZS -1.70636 2.19119 -0.7787 0.43614
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 512.67
## Residual Sum of Squares: 236.86
## R-Squared: 0.53799
## Adj. R-Squared: 0.22998
## Chisq: 10.4799 on 6 DF, p-value: 0.10584
nerlove<-plm(NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS+
AG.LND.AGRI.ZS+AG.LND.ARBL.ZS+EG.ELC.ACCS.ZS+SP.POP.GROW+GB.XPD.RSDV.GD.ZS , data=panel ,model = "random", random.method = "nerlove")
summary(nerlove)
## Oneway (individual) effect Random Effect Model
## (Nerlove's transformation)
##
## Call:
## plm(formula = NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS +
## AG.LND.ARBL.ZS + EG.ELC.ACCS.ZS + SP.POP.GROW + GB.XPD.RSDV.GD.ZS,
## data = panel, model = "random", random.method = "nerlove")
##
## Balanced Panel: n = 4, T = 4, N = 16
##
## Effects:
## var std.dev share
## idiosyncratic 9.033 3.006 0.028
## individual 308.516 17.565 0.972
## theta: 0.9148
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -5.44445 -2.22648 0.45774 2.91280 4.41861
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) -93.54726 235.48687 -0.3973 0.69118
## SL.UEM.TOTL.ZS -0.47168 0.82125 -0.5743 0.56574
## AG.LND.AGRI.ZS 2.77116 1.11836 2.4779 0.01322 *
## AG.LND.ARBL.ZS 1.39124 1.94063 0.7169 0.47343
## EG.ELC.ACCS.ZS -0.50775 2.27171 -0.2235 0.82314
## SP.POP.GROW -4.94041 5.70743 -0.8656 0.38670
## GB.XPD.RSDV.GD.ZS -1.43001 4.94935 -0.2889 0.77264
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 402.03
## Residual Sum of Squares: 162.37
## R-Squared: 0.59612
## Adj. R-Squared: 0.32687
## Chisq: 13.2839 on 6 DF, p-value: 0.038742
phtest(nerlove,within)
##
## Hausman Test
##
## data: NY.GDP.MKTP.KD.ZG ~ SL.UEM.TOTL.ZS + AG.LND.AGRI.ZS + AG.LND.ARBL.ZS + ...
## chisq = 0.42756, df = 6, p-value = 0.9986
## alternative hypothesis: one model is inconsistent
library(WDI)
library(wbstats)
library(tidyverse)
library(gplots)
library(plm)
library(readxl)
library(dplyr)
library(gplots)
PATENT_3 <- read_excel("PATENT 3.xls",sheet = "Sheet1")
PATENT_3 <- na.omit(PATENT_3)
panel<- select(PATENT_3,patentsg,return, year, cusip , employ , rnd, sales, stckpr)
plotmeans(panel$patentsg ~ panel$year,xlab="Años",ylab="Patentes",
mean.labels=TRUE, digits=-3,
col="red",connect=TRUE, main="Heterogeneidad entre patentes")
plotmeans(panel$patentsg ~ panel$cusip,xlab="Empresas",ylab="Patentes",
mean.labels=TRUE, digits=-3,
col="red",connect=TRUE, main="Heterogeneidad entre empresas")
panel2<-pdata.frame(panel, index=c("cusip","year"))
within <- plm(patentsg ~ return + employ + rnd + sales + stckpr, data = panel, index = c("cusip", "year"), model = "within")
walhus <- plm(patentsg ~ return + employ + rnd + sales + stckpr, data = panel, index = c("cusip", "year"), model = "random", random.method = 'walhus')
phtest(walhus, within)
##
## Hausman Test
##
## data: patentsg ~ return + employ + rnd + sales + stckpr
## chisq = 501.39, df = 5, p-value < 2.2e-16
## alternative hypothesis: one model is inconsistent
summary(within)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = patentsg ~ return + employ + rnd + sales + stckpr,
## data = panel, model = "within", index = c("cusip", "year"))
##
## Unbalanced Panel: n = 215, T = 2-10, N = 2083
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -219.22852 -2.15429 -0.32051 1.82530 267.24979
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## return -0.05875796 0.10859324 -0.5411 0.58852
## employ -0.06008489 0.06378744 -0.9420 0.34634
## rnd -0.13925828 0.01277223 -10.9032 < 2.2e-16 ***
## sales -0.00157648 0.00036809 -4.2829 1.938e-05 ***
## stckpr 0.05327363 0.02907453 1.8323 0.06706 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 713530
## Residual Sum of Squares: 587240
## R-Squared: 0.177
## Adj. R-Squared: 0.080254
## F-statistic: 80.1338 on 5 and 1863 DF, p-value: < 2.22e-16
summary(walhus)
## Oneway (individual) effect Random Effect Model
## (Wallace-Hussain's transformation)
##
## Call:
## plm(formula = patentsg ~ return + employ + rnd + sales + stckpr,
## data = panel, model = "random", random.method = "walhus",
## index = c("cusip", "year"))
##
## Unbalanced Panel: n = 215, T = 2-10, N = 2083
##
## Effects:
## var std.dev share
## idiosyncratic 491.88 22.18 0.182
## individual 2206.61 46.97 0.818
## theta:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.6833 0.8523 0.8523 0.8504 0.8523 0.8523
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -145.414 -4.430 -2.204 0.037 0.557 307.273
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 14.02575017 3.21531882 4.3622 1.288e-05 ***
## return -0.12918817 0.12078351 -1.0696 0.2848
## employ 0.86554048 0.04969144 17.4183 < 2.2e-16 ***
## rnd -0.09578384 0.01366226 -7.0108 2.369e-12 ***
## sales -0.00243471 0.00039724 -6.1290 8.843e-10 ***
## stckpr 0.20200524 0.03136593 6.4403 1.193e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 1004200
## Residual Sum of Squares: 828750
## R-Squared: 0.17473
## Adj. R-Squared: 0.17275
## Chisq: 441.974 on 5 DF, p-value: < 2.22e-16