#install.packages("readxl")
library(readxl)
#install.packages("plm")
library(plm)
#install.packages("gplots")
library(gplots)
library(tidyverse)
library(plm)
library(gplots)
#install.packages("WDI")
library(WDI)
#install.packages("wbstats")
library(wbstats)
#¿Qué nivel de ventas estimaría el modelo si las empresas obtuvieran todas las patentes que solicitaron?
df1 <- read.csv("/Users/carlalievanoespinosa/Desktop/business analytics/8vo semestre/df1.csv")
df1 <- pdata.frame(df1, index = c("cusip", "year"))
#Prueba de heterogeneidad
plotmeans(sales ~ patentsg, data = df1)
## Warning in qt((1 + p)/2, ns - 1): NaNs produced
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
# OPCIÓN 1 - MODELO DE REGRESIÓN AGRUPADA (POOLED)
pooled <- plm(sales ~ patentsg,
data = df1,
model = "pooling")
summary(pooled)
## Pooling Model
##
## Call:
## plm(formula = sales ~ patentsg, data = df1, model = "pooling")
##
## Unbalanced Panel: n = 226, T = 9-10, N = 2257
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -16270.2 -562.7 -488.0 -265.7 40900.9
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 521.29460 68.93369 7.5623 5.729e-14 ***
## patentsg 25.70451 0.82306 31.2305 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 3.1e+10
## Residual Sum of Squares: 2.164e+10
## R-Squared: 0.30193
## Adj. R-Squared: 0.30162
## F-statistic: 975.345 on 1 and 2255 DF, p-value: < 2.22e-16
# OPCIÓN 2 - MODELO DE EFECTOS FIJOS (WITHIN)
within <- plm(sales ~ patentsg,
data = df1,
model = "within")
summary(within)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = sales ~ patentsg, data = df1, model = "within")
##
## Unbalanced Panel: n = 226, T = 9-10, N = 2257
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -16152.9468 -73.4763 -8.4409 58.4344 20901.6815
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## patentsg -26.2818 1.6203 -16.22 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 4308200000
## Residual Sum of Squares: 3813900000
## R-Squared: 0.11474
## Adj. R-Squared: 0.016178
## F-statistic: 263.099 on 1 and 2030 DF, p-value: < 2.22e-16
# PRUEBA F
# INTERPRETACIÓN:
# Si p-value < 0.05 -> NO usar POOLED -> usar EFECTOS FIJOS
# Si p-value > 0.05 -> usar POOLED
pFtest(within, pooled)
##
## F test for individual effects
##
## data: sales ~ patentsg
## F = 42.17, df1 = 225, df2 = 2030, p-value < 2.2e-16
## alternative hypothesis: significant effects
# OPCIÓN 3 - MODELO DE EFECTOS ALEATORIOS (RANDOM)
random <- plm(sales ~ patentsg,
data = df1,
model = "random")
summary(random)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = sales ~ patentsg, data = df1, model = "random")
##
## Unbalanced Panel: n = 226, T = 9-10, N = 2257
##
## Effects:
## var std.dev share
## idiosyncratic 1878776 1371 0.215
## individual 6870102 2621 0.785
## theta:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.8283 0.8368 0.8368 0.8367 0.8368 0.8368
##
## Residuals:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -1.29e+04 -2.43e+02 -2.17e+02 1.32e-01 -1.14e+02 2.50e+04
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 1435.9200 194.9184 7.3668 1.748e-13 ***
## patentsg -8.0209 1.4298 -5.6098 2.025e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 5018700000
## Residual Sum of Squares: 4949700000
## R-Squared: 0.013745
## Adj. R-Squared: 0.013307
## Chisq: 31.4704 on 1 DF, p-value: 2.025e-08
# PRUEBA DE HAUSMAN
# INTERPRETACIÓN:
# Si p-value < 0.05 -> usar EFECTOS FIJOS
# Si p-value > 0.05 -> usar EFECTOS ALEATORIOS
phtest(random, within)
##
## Hausman Test
##
## data: sales ~ patentsg
## chisq = 573.88, df = 1, p-value < 2.2e-16
## alternative hypothesis: one model is inconsistent
#Como el p-value de la prueba de Hausman es menor a 0.05, el modelo de Efectos Fijos es más adecuado que el modelo de Efectos Aleatorios.
# PRONÓSTICO 2022
# ESCENARIO: todas las patentes solicitadas son concedidas
df1_pronostico <- subset(
df1,
year == 2021,
select = c("cusip", "patents")
)
# El pronóstico será para 2022
df1_pronostico$year <- 2022
# Suponemos que todas las patentes solicitadas son concedidas
df1_pronostico$patentsg <- df1_pronostico$patents
# Convertir a datos panel
df1_pronostico <- pdata.frame(
df1_pronostico,
index = c("cusip", "year")
)
# Obtener la pendiente del modelo de efectos fijos
pendiente <- coef(within)["patentsg"]
# Obtener los efectos fijos de cada empresa
efectos <- fixef(within)
# Pronóstico de ventas para 2022
df1_pronostico$sales_pronostico <-
efectos[as.character(df1_pronostico$cusip)] +
pendiente * df1_pronostico$patentsg
# Ver resultados
df1_pronostico
## cusip patents year patentsg sales_pronostico
## 800-2022 800 5 2022 5 1660.685634
## 4626-2022 4626 0 2022 0 384.265351
## 4671-2022 4671 0 2022 0 66.894517
## 7500-2022 7500 0 2022 0 47.125439
## 7603-2022 7603 0 2022 0 101.684539
## 20753-2022 20753 1 2022 1 42.481798
## 21367-2022 21367 0 2022 0 56.309978
## 23519-2022 23519 1 2022 1 652.642434
## 29069-2022 29069 1 2022 1 17.743640
## 38213-2022 38213 0 2022 0 123.191776
## 54303-2022 54303 0 2022 0 1844.655373
## 67131-2022 67131 0 2022 0 235.645395
## 67383-2022 67383 0 2022 0 299.252631
## 74077-2022 74077 1 2022 1 6798.849451
## 77491-2022 77491 0 2022 0 113.756360
## 87509-2022 87509 7 2022 7 6292.362170
## 87779-2022 87779 3 2022 3 457.153399
## 105655-2022 105655 0 2022 0 47.184539
## 118745-2022 118745 1 2022 1 516.055373
## 125761-2022 125761 0 2022 0 231.278070
## 126149-2022 126149 1 2022 1 3491.507784
## 134429-2022 134429 1 2022 1 1930.142653
## 147195-2022 147195 0 2022 0 166.027193
## 149123-2022 149123 14 2022 14 12182.810625
## 158663-2022 158663 0 2022 0 722.137171
## 165339-2022 165339 0 2022 0 897.238158
## 171196-2022 171196 7 2022 7 12897.967652
## 172172-2022 172172 1 2022 1 1315.931249
## 189873-2022 189873 0 2022 0 173.669079
## 200291-2022 200291 0 2022 0 199.873574
## 202363-2022 202363 0 2022 0 233.832675
## 212363-2022 212363 3 2022 3 2094.265131
## 212813-2022 212813 0 2022 0 245.547149
## 229669-2022 229669 0 2022 0 262.865351
## 235773-2022 235773 0 2022 0 524.781798
## 235811-2022 235811 0 2022 0 2408.924999
## 244199-2022 244199 10 2022 10 5112.341554
## 252741-2022 252741 15 2022 15 2363.626753
## 266867-2022 266867 1 2022 1 110.548136
## 268039-2022 268039 2 2022 2 254.821710
## 277461-2022 277461 97 2022 97 12439.008104
## 278058-2022 278058 14 2022 14 4560.370062
## 286065-2022 286065 0 2022 0 115.073574
## 296659-2022 296659 1 2022 1 195.655373
## 296695-2022 296695 1 2022 1 74.159101
## 303711-2022 303711 1 2022 1 615.927193
## 316549-2022 316549 1 2022 1 446.063596
## 345370-2022 345370 16 2022 16 35889.007888
## 345838-2022 345838 1 2022 1 -12.325439
## 350244-2022 350244 5 2022 5 1660.610525
## 351604-2022 351604 2 2022 2 553.741666
## 361428-2022 361428 9 2022 9 2240.602629
## 361556-2022 361556 0 2022 0 122.379057
## 361606-2022 361606 0 2022 0 228.042653
## 362360-2022 362360 1 2022 1 25.584539
## 368298-2022 368298 0 2022 0 186.260855
## 368514-2022 368514 0 2022 0 45.353618
## 369032-2022 369032 0 2022 0 94.069079
## 369154-2022 369154 0 2022 0 212.324452
## 369550-2022 369550 6 2022 6 4229.157235
## 369604-2022 369604 168 2022 168 36012.958740
## 369856-2022 369856 11 2022 11 5979.767433
## 370622-2022 370622 0 2022 0 515.475329
## 370838-2022 370838 1 2022 1 2231.523572
## 372298-2022 372298 0 2022 0 28.469079
## 375046-2022 375046 0 2022 0 243.104496
## 375766-2022 375766 3 2022 3 2273.914034
## 377352-2022 377352 0 2022 0 293.018969
## 383492-2022 383492 9 2022 9 3216.747804
## 383550-2022 383550 0 2022 0 180.325439
## 383883-2022 383883 18 2022 18 6404.327408
## 384109-2022 384109 0 2022 0 229.165351
## 390568-2022 390568 1 2022 1 122.635417
## 402784-2022 402784 0 2022 0 231.711732
## 404245-2022 404245 0 2022 0 212.365351
## 413342-2022 413342 0 2022 0 624.113487
## 413875-2022 413875 1 2022 1 1867.807345
## 415864-2022 415864 2 2022 2 821.368092
## 421596-2022 421596 1 2022 1 208.555373
## 422191-2022 422191 0 2022 0 34.769079
## 423002-2022 423002 0 2022 0 37.412719
## 423236-2022 423236 0 2022 0 186.304496
## 428399-2022 428399 0 2022 0 105.291776
## 428875-2022 428875 0 2022 0 41.640899
## 429812-2022 429812 0 2022 0 151.242653
## 439272-2022 439272 4 2022 4 641.040899
## 449290-2022 449290 0 2022 0 216.883552
## 449680-2022 449680 1 2022 1 29.777778
## 451542-2022 451542 0 2022 0 340.128180
## 451650-2022 451650 0 2022 0 356.295285
## 456866-2022 456866 7 2022 7 2935.822038
## 457186-2022 457186 0 2022 0 210.472710
## 457776-2022 457776 0 2022 0 42.084539
## 459101-2022 459101 0 2022 0 170.648136
## 459200-2022 459200 51 2022 51 29825.100199
## 459506-2022 459506 58 2022 58 283.102741
## 459578-2022 459578 14 2022 14 6991.219077
## 459884-2022 459884 2 2022 2 1897.650438
## 460043-2022 460043 0 2022 0 888.940899
## 461135-2022 461135 0 2022 0 99.650877
## 462218-2022 462218 0 2022 0 139.483552
## 465632-2022 465632 0 2022 0 979.762170
## 479169-2022 479169 0 2022 0 75.950877
## 481070-2022 481070 0 2022 0 283.224452
## 481088-2022 481088 0 2022 0 209.540899
## 481196-2022 481196 4 2022 4 761.968092
## 486872-2022 486872 0 2022 0 134.519956
## 487836-2022 487836 0 2022 0 1496.809978
## 489170-2022 489170 1 2022 1 607.352412
## 493503-2022 493503 0 2022 0 128.019956
## 494368-2022 494368 13 2022 13 2308.310525
## 495620-2022 495620 0 2022 0 136.460855
## 501026-2022 501026 0 2022 0 131.612719
## 501206-2022 501206 0 2022 0 156.891776
## 503624-2022 503624 0 2022 0 42.684539
## 505336-2022 505336 0 2022 0 147.125439
## 513696-2022 513696 0 2022 0 320.365351
## 513847-2022 513847 0 2022 0 224.053618
## 524660-2022 524660 0 2022 0 259.783552
## 530000-2022 530000 2 2022 2 1513.555920
## 538021-2022 538021 7 2022 7 4974.496160
## 539821-2022 539821 3 2022 3 4468.179385
## 540137-2022 540137 1 2022 1 211.127193
## 540210-2022 540210 0 2022 0 47.197259
## 541381-2022 541381 1 2022 1 68.535417
## 543213-2022 543213 1 2022 1 251.030921
## 551120-2022 551120 0 2022 0 68.522697
## 551137-2022 551137 0 2022 0 35.525439
## 552618-2022 552618 0 2022 0 232.014474
## 562706-2022 562706 0 2022 0 56.722697
## 574055-2022 574055 0 2022 0 583.010745
## 574599-2022 574599 0 2022 0 660.700767
## 575379-2022 575379 0 2022 0 497.701754
## 576680-2022 576680 0 2022 0 40.212719
## 580033-2022 580033 0 2022 0 2054.363596
## 580169-2022 580169 5 2022 5 5328.389143
## 580628-2022 580628 6 2022 6 1840.127740
## 585055-2022 585055 6 2022 6 507.966118
## 589331-2022 589331 39 2022 39 5373.586397
## 597715-2022 597715 4 2022 4 1109.974122
## 601073-2022 601073 1 2022 1 163.691776
## 608030-2022 608030 0 2022 0 678.748136
## 608183-2022 608183 0 2022 0 292.642653
## 620076-2022 620076 24 2022 24 6128.870497
## 629853-2022 629853 8 2022 8 1345.347476
## 637742-2022 637742 1 2022 1 352.299013
## 670148-2022 670148 0 2022 0 151.512719
## 670250-2022 670250 0 2022 0 33.684539
## 680665-2022 680665 28 2022 28 3407.471269
## 690207-2022 690207 1 2022 1 218.619956
## 690734-2022 690734 40 2022 40 2451.877411
## 690768-2022 690768 20 2022 20 5788.378613
## 704562-2022 704562 3 2022 3 559.116228
## 707389-2022 707389 0 2022 0 26.484539
## 717081-2022 717081 41 2022 41 3324.344515
## 718320-2022 718320 0 2022 0 245.353618
## 724479-2022 724479 17 2022 17 1909.265458
## 727346-2022 727346 0 2022 0 83.725439
## 727491-2022 727491 0 2022 0 110.735417
## 736245-2022 736245 0 2022 0 522.791776
## 737407-2022 737407 0 2022 0 80.089035
## 739732-2022 739732 0 2022 0 119.766338
## 739868-2022 739868 0 2022 0 43.612719
## 740512-2022 740512 0 2022 0 244.653618
## 746252-2022 746252 2 2022 2 589.929934
## 746299-2022 746299 0 2022 0 115.335417
## 749720-2022 749720 2 2022 2 7.671820
## 749738-2022 749738 0 2022 0 228.614474
## 750633-2022 750633 1 2022 1 7.387281
## 754688-2022 754688 0 2022 0 108.950877
## 754713-2022 754713 0 2022 0 75.507237
## 755111-2022 755111 2 2022 2 5447.822693
## 756040-2022 756040 0 2022 0 27.884539
## 758114-2022 758114 0 2022 0 40.928180
## 760354-2022 760354 0 2022 0 284.279057
## 760881-2022 760881 0 2022 0 362.183552
## 760898-2022 760898 0 2022 0 25.140899
## 761406-2022 761406 0 2022 0 612.725439
## 766481-2022 766481 0 2022 0 401.958114
## 767329-2022 767329 0 2022 0 8.456360
## 768024-2022 768024 0 2022 0 146.476316
## 770196-2022 770196 0 2022 0 180.732675
## 770519-2022 770519 5 2022 5 1825.995173
## 770553-2022 770553 1 2022 1 675.715241
## 775133-2022 775133 1 2022 1 128.904496
## 775371-2022 775371 7 2022 7 3055.682234
## 776338-2022 776338 0 2022 0 180.604496
## 776678-2022 776678 0 2022 0 488.790814
## 776755-2022 776755 1 2022 1 696.190569
## 784015-2022 784015 12 2022 12 2386.170174
## 784626-2022 784626 0 2022 0 401.357127
## 794099-2022 794099 0 2022 0 181.242653
## 799850-2022 799850 1 2022 1 831.519516
## 809367-2022 809367 6 2022 6 472.635417
## 809877-2022 809877 4 2022 4 1982.813267
## 810640-2022 810640 0 2022 0 998.168859
## 817698-2022 817698 0 2022 0 58.835417
## 817732-2022 817732 0 2022 0 18.384539
## 820208-2022 820208 1 2022 1 79.909978
## 822440-2022 822440 0 2022 0 69.366338
## 826520-2022 826520 0 2022 0 93.476316
## 828675-2022 828675 1 2022 1 185.055373
## 831865-2022 831865 1 2022 1 829.831688
## 832110-2022 832110 3 2022 3 909.372368
## 832248-2022 832248 0 2022 0 179.112719
## 832377-2022 832377 18 2022 18 2791.913155
## 833034-2022 833034 0 2022 0 307.363596
## 847235-2022 847235 1 2022 1 105.138158
## 847567-2022 847567 0 2022 0 146.301754
## 847660-2022 847660 0 2022 0 34.281798
## 848355-2022 848355 24 2022 24 7478.779928
## 853683-2022 853683 27 2022 27 25477.425982
## 853700-2022 853700 48 2022 48 16697.430917
## 853734-2022 853734 0 2022 0 5285.152631
## 853836-2022 853836 1 2022 1 284.737171
## 853887-2022 853887 0 2022 0 266.304496
## 857721-2022 857721 33 2022 33 3389.424667
## 859264-2022 859264 35 2022 35 1721.435964
## 866645-2022 866645 3 2022 3 621.074342
## 866762-2022 866762 0 2022 0 8840.972256
## 870326-2022 870326 0 2022 0 25.300000
## 871140-2022 871140 6 2022 6 1108.420503
## 871565-2022 871565 0 2022 0 58.684539
## 871616-2022 871616 11 2022 11 1590.300875
## 878308-2022 878308 0 2022 0 27.756360
## 878555-2022 878555 0 2022 0 37.769079
#CONCLUSIÓN: las patentes concedidas (patentsg) tienen una relación negativa y estadísticamente significativa con las ventas. El coeficiente de −26.28 indica que, dentro de una misma empresa, una patente concedida adicional se asocia en promedio con una disminución de aproximadamente 26.28 millones de dólares en ventas.
#Si tuvieras que invertir en alguna sub - categoría, ¿en cuál lo harías? Justifica ampliamente tu respuesta.
df2 <- read.csv("/Users/carlalievanoespinosa/Desktop/business analytics/8vo semestre/df2.csv")
df2 <- read.csv(
"/Users/carlalievanoespinosa/Desktop/business analytics/8vo semestre/df2.csv",
skip = 1,
check.names = FALSE,
na.strings = c("-", "")
)
# Subcategorías
categorias <- c(
"Bath and Shower",
"Deodorants",
"Depilatories",
"Fragrances",
"Hair Care",
"Men's Grooming",
"Skin Care",
"Sun Care"
)
# Pasar de formato ancho a formato largo
df2_long <- df2 %>%
select(Category, all_of(as.character(2011:2025))) %>%
pivot_longer(
cols = all_of(as.character(2011:2025)),
names_to = "year",
values_to = "market_size"
) %>%
mutate(
year = as.integer(year),
market_size = parse_number(as.character(market_size))
)
totales <- df2_long %>%
filter(Category == "Beauty and Personal Care") %>%
select(year, total_market = market_size)
# Calcular participación de mercado
df2_model <- df2_long %>%
filter(Category %in% categorias) %>%
left_join(totales, by = "year") %>%
mutate(
market_share = (market_size / total_market) * 100,
trend = year - 2011,
category = factor(Category)
) %>%
arrange(category, year)
# Revisar
head(df2_model)
## # A tibble: 6 × 7
## Category year market_size total_market market_share trend category
## <chr> <int> <dbl> <dbl> <dbl> <dbl> <fct>
## 1 Bath and Shower 2011 8410. 126329. 6.66 0 Bath and Sh…
## 2 Bath and Shower 2012 9085 136020. 6.68 1 Bath and Sh…
## 3 Bath and Shower 2013 9711. 142539. 6.81 2 Bath and Sh…
## 4 Bath and Shower 2014 10227. 149165. 6.86 3 Bath and Sh…
## 5 Bath and Shower 2015 10815. 157656. 6.86 4 Bath and Sh…
## 6 Bath and Shower 2016 11482. 170488. 6.73 5 Bath and Sh…
# Panel
df2_panel <- pdata.frame(
as.data.frame(df2_model),
index = c("category", "year")
)
# Revisar estructura del panel
pdim(df2_panel)
## Balanced Panel: n = 8, T = 15, N = 120
# Comprobar si es balanceado
is.pbalanced(df2_panel)
## [1] TRUE
# PRUEBA DE HETEROGENEIDAD
par(mar = c(8, 4, 3, 1))
plotmeans(
market_share ~ category,
data = df2_model,
las = 2,
xlab = "",
ylab = "Participación de mercado (%)"
)
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, li, x, pmax(y - gap, li), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
## 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, 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), 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
## Warning in arrows(x, ui, x, pmin(y + gap, ui), col = barcol, lwd = lwd, :
## zero-length arrow is of indeterminate angle and so skipped
# OPCIÓN 1 - MODELO DE REGRESIÓN AGRUPADA (POOLED)
pooled <- plm(
market_share ~ trend,
data = df2_panel,
model = "pooling"
)
summary(pooled)
## Pooling Model
##
## Call:
## plm(formula = market_share ~ trend, data = df2_panel, model = "pooling")
##
## Balanced Panel: n = 8, T = 15, N = 120
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -10.616051 -5.734911 -0.098855 6.435351 12.001541
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 10.488539 1.292050 8.1177 5.16e-13 ***
## trend 0.051766 0.157070 0.3296 0.7423
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 6527
## Residual Sum of Squares: 6521
## R-Squared: 0.00091964
## Adj. R-Squared: -0.0075471
## F-statistic: 0.108618 on 1 and 118 DF, p-value: 0.74231
# OPCIÓN 2 - MODELO DE EFECTOS FIJOS (WITHIN)
within <- plm(
market_share ~ trend,
data = df2_panel,
model = "within",
effect = "individual"
)
summary(within)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = market_share ~ trend, data = df2_panel, effect = "individual",
## model = "within")
##
## Balanced Panel: n = 8, T = 15, N = 120
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -1.8250909 -0.3761985 -0.0040966 0.2783801 2.6852699
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## trend 0.051766 0.016069 3.2215 0.001674 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 70.204
## Residual Sum of Squares: 64.202
## R-Squared: 0.085501
## Adj. R-Squared: 0.019591
## F-statistic: 10.3779 on 1 and 111 DF, p-value: 0.0016738
# PRUEBA F
prueba_f <- pFtest(within, pooled)
prueba_f
##
## F test for individual effects
##
## data: market_share ~ trend
## F = 1594.8, df1 = 7, df2 = 111, p-value < 2.2e-16
## alternative hypothesis: significant effects
# OPCIÓN 3 - MODELO DE EFECTOS ALEATORIOS (RANDOM)
random <- plm(
market_share ~ trend,
data = df2_panel,
model = "random",
effect = "individual"
)
summary(random)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = market_share ~ trend, data = df2_panel, effect = "individual",
## model = "random")
##
## Balanced Panel: n = 8, T = 15, N = 120
##
## Effects:
## var std.dev share
## idiosyncratic 0.5784 0.7605 0.009
## individual 61.4547 7.8393 0.991
## theta: 0.975
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -1.72003 -0.46571 -0.12213 0.22992 2.79033
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 10.488539 2.774764 3.7800 0.0001568 ***
## trend 0.051766 0.016069 3.2215 0.0012753 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 74.253
## Residual Sum of Squares: 68.25
## R-Squared: 0.080839
## Adj. R-Squared: 0.073049
## Chisq: 10.3779 on 1 DF, p-value: 0.0012753
# PRUEBA DE HAUSMAN
prueba_hausman <- phtest(within, random)
prueba_hausman
##
## Hausman Test
##
## data: market_share ~ trend
## chisq = 1.1842e-15, df = 1, p-value = 1
## alternative hypothesis: one model is inconsistent
if(prueba_f$p.value >= 0.05){
modelo_final <- "pooled"
} else {
if(prueba_hausman$p.value < 0.05){
modelo_final <- "within"
} else {
modelo_final <- "random"
}
}
modelo_final
## [1] "random"
# CONCLUSIÓN:
# De acuerdo con la prueba de Hausman, el p-value es mayor a 0.05. Por lo tanto, el modelo de Efectos Aleatorios es más adecuado
# que el modelo de Efectos Fijos.
# Se utilizará el modelo Random para realizar la predicción de la participación de mercado de cada subcategoría para 2026.
# Coeficientes del modelo Random
beta0 <- coef(random)["(Intercept)"]
beta1 <- coef(random)["trend"]
beta0
## (Intercept)
## 10.48854
beta1
## trend
## 0.0517657
# Calcular la parte común estimada por el modelo
df2_model <- df2_model %>%
mutate(
pred_parte_comun = beta0 + beta1 * trend,
diferencia = market_share - pred_parte_comun
)
# Extraer los efectos aleatorios estimados por el modelo
efectos_random <- ranef(random)
efectos_random
## Bath and Shower Deodorants Depilatories Fragrances Hair Care
## -3.988697 -3.273814 -10.150282 4.193032 7.908366
## Men's Grooming Skin Care Sun Care
## 4.908848 10.099658 -9.697110
# Crear datos para 2026
nuevo_2026 <- data.frame(
category = names(efectos_random),
year = 2026,
trend = 15
)
# Coeficientes
beta0 <- coef(random)["(Intercept)"]
beta1 <- coef(random)["trend"]
# Incorporar los efectos aleatorios
nuevo_2026$efecto_random <- as.numeric(efectos_random)
# Predicción 2026
nuevo_2026$market_share_2026 <-
beta0 +
beta1 * nuevo_2026$trend +
nuevo_2026$efecto_random
nuevo_2026
## category year trend efecto_random market_share_2026
## 1 Bath and Shower 2026 15 -3.988697 7.276328
## 2 Deodorants 2026 15 -3.273814 7.991210
## 3 Depilatories 2026 15 -10.150282 1.114743
## 4 Fragrances 2026 15 4.193032 15.458056
## 5 Hair Care 2026 15 7.908366 19.173390
## 6 Men's Grooming 2026 15 4.908848 16.173872
## 7 Skin Care 2026 15 10.099658 21.364682
## 8 Sun Care 2026 15 -9.697110 1.567914
actual_2025 <- df2_model %>%
filter(year == 2025) %>%
select(
category,
market_share_2025 = market_share
)
resultado_final <- nuevo_2026 %>%
select(
category,
market_share_2026
) %>%
left_join(actual_2025, by = "category") %>%
mutate(
cambio_pp = market_share_2026 - market_share_2025
) %>%
arrange(desc(market_share_2026))
resultado_final
## category market_share_2026 market_share_2025 cambio_pp
## 1 Skin Care 21.364682 22.9054931 -1.5408111
## 2 Hair Care 19.173390 17.9499600 1.2234302
## 3 Men's Grooming 16.173872 15.7874748 0.3863973
## 4 Fragrances 15.458056 18.0941915 -2.6361351
## 5 Deodorants 7.991210 6.9593731 1.0318371
## 6 Bath and Shower 7.276328 6.8055431 0.4707847
## 7 Sun Care 1.567914 1.3796231 0.1882909
## 8 Depilatories 1.114743 0.5972074 0.5175352
#CONCLUSIÓN: Con base en los resultados del modelo de efectos aleatorios, Hair Care representa la alternativa de inversión más atractiva entre las subcategorías analizadas de Beauty & Personal Care para 2026. #Para 2026, Hair Care presenta una participación de mercado estimada de 19.17%, lo que la posiciona como la segunda subcategoría con mayor participación proyectada, únicamente por debajo de Skin Care, con 21.36%. Esto indica que Hair Care ya cuenta con una presencia importante dentro del mercado total de Beauty & Personal Care, por lo que una inversión en esta categoría no dependería del crecimiento de un segmento pequeño o poco consolidado, sino de una categoría que actualmente representa una proporción significativa del mercado. #Además, Hair Care presenta el mayor incremento absoluto esperado en participación de mercado entre las principales subcategorías, pasando de aproximadamente 17.95% en 2025 a 19.17% en 2026. Esto representa un crecimiento de alrededor de 1.22 puntos porcentuales.
# obtener esperanza de vida de varios países
life_expectancy_data <- wb_data(country = c("MX", "US", "CA"),
indicator = "SP.DYN.LE00.IN",
start_date = 1950,end_date = 2025)
# Preparar datos
life_data <- life_expectancy_data %>%
transmute(
country = country,
year = as.integer(date),
life_expectancy = SP.DYN.LE00.IN
) %>%
filter(!is.na(life_expectancy)) %>%
mutate(
trend = year - min(year)
) %>%
arrange(country, year)
head(life_data)
## # A tibble: 6 × 4
## country year life_expectancy trend
## <chr> <int> <dbl> <int>
## 1 Canada 1960 71.1 0
## 2 Canada 1961 71.3 1
## 3 Canada 1962 71.4 2
## 4 Canada 1963 71.4 3
## 5 Canada 1964 71.8 4
## 6 Canada 1965 71.9 5
life_panel <- pdata.frame(
life_data,
index = c("country", "year")
)
pdim(life_panel)
## Balanced Panel: n = 3, T = 65, N = 195
is.pbalanced(life_panel)
## [1] TRUE
plotmeans(
life_expectancy ~ country,
data = life_data,
xlab = "País",
ylab = "Esperanza de vida"
)
ggplot(
life_data,
aes(
x = year,
y = life_expectancy,
color = country
)
) +
geom_line(linewidth = 1) +
labs(
title = "Evolución de la esperanza de vida",
x = "Año",
y = "Esperanza de vida",
color = "País"
) +
theme_minimal()
#Opción 1 - Efectos agrupados
pooled_life <- plm(
life_expectancy ~ trend,
data = life_panel,
model = "pooling"
)
summary(pooled_life)
## Pooling Model
##
## Call:
## plm(formula = life_expectancy ~ trend, data = life_panel, model = "pooling")
##
## Balanced Panel: n = 3, T = 65, N = 195
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -12.5473 -3.4926 1.8974 3.9455 5.0129
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## (Intercept) 66.120307 0.656051 100.785 < 2.2e-16 ***
## trend 0.223581 0.017686 12.642 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 7575
## Residual Sum of Squares: 4143.7
## R-Squared: 0.45297
## Adj. R-Squared: 0.45013
## F-statistic: 159.814 on 1 and 193 DF, p-value: < 2.22e-16
#Opción 2 - Efectos fijos
fixed_life <- plm(
life_expectancy ~ trend,
data = life_panel,
model = "within",
effect = "individual"
)
summary(fixed_life)
## Oneway (individual) effect Within Model
##
## Call:
## plm(formula = life_expectancy ~ trend, data = life_panel, effect = "individual",
## model = "within")
##
## Balanced Panel: n = 3, T = 65, N = 195
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -6.79967 -0.48439 0.29545 1.11777 3.37249
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## trend 0.2235814 0.0076021 29.41 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 4188.9
## Residual Sum of Squares: 757.67
## R-Squared: 0.81912
## Adj. R-Squared: 0.81628
## F-statistic: 864.969 on 1 and 191 DF, p-value: < 2.22e-16
prueba_f_life <- pFtest(
fixed_life,
pooled_life
)
prueba_f_life
##
## F test for individual effects
##
## data: life_expectancy ~ trend
## F = 426.79, df1 = 2, df2 = 191, p-value < 2.2e-16
## alternative hypothesis: significant effects
#Opción 3 - Efectos aleatorios
random_life <- plm(
life_expectancy ~ trend,
data = life_panel,
model = "random",
effect = "individual"
)
summary(random_life)
## Oneway (individual) effect Random Effect Model
## (Swamy-Arora's transformation)
##
## Call:
## plm(formula = life_expectancy ~ trend, data = life_panel, effect = "individual",
## model = "random")
##
## Balanced Panel: n = 3, T = 65, N = 195
##
## Effects:
## var std.dev share
## idiosyncratic 3.967 1.992 0.132
## individual 25.986 5.098 0.868
## theta: 0.9516
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -7.07789 -0.44781 0.37419 1.19318 3.09427
##
## Coefficients:
## Estimate Std. Error z-value Pr(>|z|)
## (Intercept) 66.1203066 2.9565836 22.364 < 2.2e-16 ***
## trend 0.2235814 0.0076021 29.410 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 4196.8
## Residual Sum of Squares: 765.61
## R-Squared: 0.81757
## Adj. R-Squared: 0.81663
## Chisq: 864.969 on 1 DF, p-value: < 2.22e-16
prueba_hausman_life <- phtest(
fixed_life,
random_life
)
prueba_hausman_life
##
## Hausman Test
##
## data: life_expectancy ~ trend
## chisq = 8.1205e-15, df = 1, p-value = 1
## alternative hypothesis: one model is inconsistent
# Extraer efectos aleatorios por país
efectos_life <- ranef(random_life)
efectos_life
## Canada Mexico United States
## 3.991447 -5.734168 1.742721
# Coeficientes del modelo Random
beta0 <- coef(random_life)["(Intercept)"]
beta1 <- coef(random_life)["trend"]
beta0
## (Intercept)
## 66.12031
beta1
## trend
## 0.2235814
# Año inicial de la base
anio_inicial <- min(life_data$year)
# Crear base para predicción 2026
nuevo_2026_life <- data.frame(
country = names(efectos_life),
year = 2026,
trend = 2026 - anio_inicial,
efecto_random = as.numeric(efectos_life)
)
nuevo_2026_life
## country year trend efecto_random
## 1 Canada 2026 66 3.991447
## 2 Mexico 2026 66 -5.734168
## 3 United States 2026 66 1.742721
# Predicción de esperanza de vida para 2026
nuevo_2026_life <- nuevo_2026_life %>%
mutate(
life_expectancy_2026 =
beta0 +
beta1 * trend +
efecto_random
)
nuevo_2026_life
## country year trend efecto_random life_expectancy_2026
## 1 Canada 2026 66 3.991447 84.86813
## 2 Mexico 2026 66 -5.734168 75.14251
## 3 United States 2026 66 1.742721 82.61940
resultado_2026_life <- nuevo_2026_life %>%
select(
country,
life_expectancy_2026
) %>%
arrange(desc(life_expectancy_2026))
resultado_2026_life
## country life_expectancy_2026
## 1 Canada 84.86813
## 2 United States 82.61940
## 3 Mexico 75.14251
max(life_data$year)
## [1] 2024
ultimo_anio <- max(life_data$year)
actual_life <- life_data %>%
filter(year == ultimo_anio) %>%
select(
country,
life_expectancy_actual = life_expectancy
)
resultado_final_life <- resultado_2026_life %>%
left_join(
actual_life,
by = "country"
) %>%
mutate(
cambio = life_expectancy_2026 -
life_expectancy_actual
) %>%
arrange(desc(life_expectancy_2026))
resultado_final_life
## country life_expectancy_2026 life_expectancy_actual cambio
## 1 Canada 84.86813 82.10805 2.7600790
## 2 United States 82.61940 78.89024 3.7291577
## 3 Mexico 75.14251 75.26400 -0.1214876
#COCLUSIÓN: De acuerdo con el modelo de efectos aleatorios, Canadá presenta la mayor esperanza de vida estimada para 2026, con aproximadamente 84.87 años, seguido por Estados Unidos con 82.62 años y México con 75.14 años. Los resultados muestran que las diferencias estructurales entre los países se mantendrían, con una brecha proyectada de aproximadamente 9.73 años entre Canadá y México y de 7.48 años entre Estados Unidos y México.
file <- "Actividad_1_patentes.Rmd"
x <- readLines(
file,
encoding = "UTF-8",
warn = FALSE
)