<jupyter_start><jupyter_text>Correlaciones: Vehículos ligeros en México, 2005-2019Datos: Registro administrativo de la industria automotriz de vehículos ligeros, INEGIFrecuencia: MensualPeriodo: 2005 Enero, 2019 OctubreElaboración: Subsecretaría de Industria, Comercio y Competitividad, Secretaría de Economía, con datos del INEGI. <NAME>Actualización: Noviembre 22, 2019<jupyter_code># library 
Packages <- c("tidyverse","lubridate","ggplot2", "dplyr", "seasonal", "ggseas", "ggfortify", "forecast", "mFilter", "plotly", "dynlm", "AER", "MASS", "corrr", "corrplot")
suppressMessages(invisible(lapply(Packages, library, character.only=TRUE)))
#set strings as factors to false 
options(stringsAsFactors=FALSE)
#search()
# raw data 
    rawdata <- read_csv("data/veh_lig.csv", col_types = cols() )
    rawdata <- data.frame(mutate(rawdata, time = make_date(year, mes) ))
# variable selection 
    lmacro <-c("trabajadores" , "masa_salarial" , "ms_wrk" , "tiie" , "tc_fix" , "cetes28" , "inpc" , "pi" , "inpc_auto" , "pi_autos" , "inpc_combusible", "pi_combustible")
    lqv <- c("qv" , "qv_mex" , "qv_imp" , "qv_deu" , "qv_bra" , "qv_can" , "qv_jpn" , "qv_gbr" , "qv_usa" , "qv_ind", "qv_kor" , "qv_tha" , "qv_1" , "qv_2" , "qv_7" )
    lqp <- c("qp" , "qp_1" , "qp_2" , "qp_7")
    lqx <- c("qx" , "qx_deu" , "qx_nafta" , "qx_fca" , "qx_ford" , "qx_gm" , "qx_nsa" , "qx_tyo" , "qx_vw" , "qx_hmc" , "qx_nafta_fca" , "qx_nafta_ford" , "qx_nafta_gm" , "qx_nafta_nsa" , "qx_nafta_tyo" , "qx_nafta_vw" , "qx_nafta_hmc" , "qx_1" , "qx_nafta_1" , "qx_2" , "qx_nafta_2" , "qx_7" , "qx_nafta_7")
# ts data
    wrk <- ts(as_tibble(subset(rawdata, select=c("year", "mes",lmacro,lqv,lqp,lqx))), frequency=12, start=c(2005,1), end=c(2019,10))
    #head(wrk,3)
# lista de variables: seasonal adjustment 
wlist <- lmacro
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_sa") }
lmacro_sa <- wlist

wlist <- lqv
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_sa") }
lqv_sa <- wlist

wlist <- lqp
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_sa") }
lqp_sa <- wlist

wlist <- lqx
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_sa") }
lqx_sa <- wlist
rm(wlist)

# lista de variables: tendencia-ciclo
wlist <- lmacro
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_tr") }
lmacro_tr <- wlist

wlist <- lqv
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_tr") }
lqv_tr <- wlist

wlist <- lqp
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_tr") }
lqp_tr <- wlist

wlist <- lqx
for(i in seq_along(wlist)){ wlist[[i]] <- paste0(wlist[[i]],"_tr") }
lqx_tr <- wlist
rm(wlist)
# for each variable: add to wrk their seasonal adjustment + hp trend
sahp <- function(db, var){
    vsa <- seas(db[,var])
    #vsa$model$arima
    vhp <- hpfilter(vsa$data[,"seasonaladj"])
    vsahp <- ts(subset(mutate(as_tibble(vsa$data), hp=vhp$trend),select=c("seasonaladj","trend", "hp")), frequency=12, start=c(2005,1), end=c(2019,10))
    
    db <- mutate(as_tibble(db), 
            sa = vsahp[,"seasonaladj"], 
            tr= vsahp[,"trend"], 
            hp= vsahp[,"hp"]
                 )
    names(db)[names(db)=="sa"] <- paste0(var,"_sa")
    names(db)[names(db)=="tr"] <- paste0(var,"_tr")
    names(db)[names(db)=="hp"] <- paste0(var,"_hp")
    db <- ts(db, , frequency=12, start=c(2005,1), end=c(2019,10))
    
    rm(vsa, vhp, vsahp)
    return(db)
}<jupyter_output><empty_output><jupyter_text>Base de datos con variables desestacionalizadas, tendencia-ciclo,  wlist <- c(lmacro, lqv, lqp, lqx)suppressMessages(for(i in seq_along(wlist)) {    print(wlist[[i]])    db <- wrk    var <-wlist[[i]]     wrk <- sahp(db,var)})dim(wrk)write_csv(as_tibble(wrk), path="output/autos/wrk_macro.csv")<jupyter_code>wrk <- ts(as_tibble(read_csv("output/autos/wrk_macro.csv", col_types = cols() )), frequency=12, start=c(2005,1), end=c(2019,10))
#dim(wrk)
wrk_sa <- ts(subset(as_tibble(wrk), select=c(lmacro_sa,lmacro_tr,lqv_sa,lqv_tr, lqp_sa,lqp_tr, lqx_sa, lqx_tr)), frequency=12, start=c(2005,1), end=c(2019,10))
lwrk_sa <- names(as_tibble(wrk_sa))
#head(wrk_sa,3)<jupyter_output><empty_output><jupyter_text>Correlaciones de Variables Macro<jupyter_code>#lmacro_sa
corlist <- lmacro_sa[-c(3,4,7,9,11)]
#corlist
cordata <- subset(as_tibble(wrk_sa), select=corlist)
names(cordata) <- c("trabajadores", "Masa salarial", "Tipo de Cambio", "Tasa de interés", "Inflación (INPC)", "Inflación Compra Autos", "Inflación Combustible Autos")
corrplot(cor(cordata), method="number", type="upper")
round(cor(cordata),2)
rm(cordata)<jupyter_output><empty_output><jupyter_text>Correlaciones de las ventas de Vehículos Ligeros: autos nacionales e importados según país de origen<jupyter_code>cordata <-subset(as_tibble(wrk_sa), select=c('qv_sa', 'qv_mex_sa', 'qv_imp_sa', "qv_deu_sa" , "qv_bra_sa" , "qv_can_sa" , "qv_jpn_sa" , "qv_gbr_sa" , "qv_usa_sa" , "qv_ind_sa", "qv_kor_sa" , "qv_tha_sa"))
names(cordata) <- c("Ventas totales", "Ventas autos nacional", "ventas autos importados", "autos de Alemania", "autos de Brasil", "autos de Canadá", "autos de Japón", "autos de Reino Unido", "autos de EEUU", "autos de India", "autos de Corea", "autos de Tailandia")
round(cor(cordata),2)
corrplot(cor(cordata), method="number", type="upper")
rm(cordata)<jupyter_output><empty_output><jupyter_text>Correlaciones de las ventas de Vehículos Ligeros: según tipo de auto<jupyter_code>cordata <-subset(as_tibble(wrk_sa), select=c('qv_sa', 'qv_mex_sa', 'qv_imp_sa', "qv_1_sa" , "qv_2_sa" , "qv_7_sa"))
names(cordata) <- c("Ventas totales", "Ventas autos nacional", "ventas autos importados", "ventas autos compactos", "autos subcompactos", "SUVs")
round(cor(cordata),2)
corrplot(cor(cordata), method="number", type="upper")
rm(cordata)<jupyter_output><empty_output><jupyter_text>Correlaciones de la producción de Vehículos Ligeros<jupyter_code>cordata <- subset(as_tibble(wrk_sa), select=lqp_sa)
colnames(cordata) <- c("Producción Total", "Autos compactos", "Autos subcompactos", "SUV")
round(cor(cordata),2)
corrplot(cor(cordata), method="number", type="upper")
rm(cordata)<jupyter_output><empty_output><jupyter_text>Correlaciones de las exportaciones de Vehículos Ligeros<jupyter_code>cordata <- subset(as_tibble(wrk_sa), select=c('qx_sa', 'qx_nafta_sa', 'qx_1_sa', 'qx_2_sa', 'qx_7_sa'))
colnames(cordata) <- c("Exportación Total de Autos", "Exportación región NAFTA/T-MEC", "Exportación autos compactos", "Exportación autos subcompactos",  "Exportación SUVs")
round(cor(cordata),2)
corrplot(cor(cordata), method="number", type="upper")
rm(cordata)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18650733625775223, 'fraction_numerical': 0.019966722129783693, 'mean_word_length': 6.404255319148936, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '424575', 'license': 'MIT', 'n_tokens_mistral': 3063, 'n_tokens_neox': 2886, 'n_words': 510, 'path': 'jupyter/vehlig_macro_corr.ipynb', 'repo_name': 'PedroJMA/dossier', 'size': '6631'}