Working on updates
This commit is contained in:
parent
35d54d0a2b
commit
35dff87e88
61
Tapestry.r
61
Tapestry.r
@ -2,14 +2,14 @@ library(tidyverse)
|
||||
library(readxl)
|
||||
|
||||
|
||||
|
||||
GET_MULTIPLIERS <- function(ROOT_FOLDER="States/",YEAR=2024,VERSION='1.5.6'){
|
||||
SUB_FOLDER <- list.files(FOLDER)
|
||||
GET_MULTIPLIERS <- function(ROOT_FOLDER="States/",YEAR=2024){
|
||||
ROOT_FOLDER="States/";YEAR=2024
|
||||
SUB_FOLDER <- list.files(ROOT_FOLDER)
|
||||
ENTRIES <- (strsplit(SUB_FOLDER,paste0("_",YEAR)) %>% unlist)
|
||||
REGIONS <- ENTRIES[seq(1,length(ENTRIES),by=2)]
|
||||
ALL_FILES <- list.files(paste0(ROOT_FOLDER,SUB_FOLDER),full.names=TRUE)
|
||||
LEONTIEF <- ALL_FILES[grep("leontief",ALL_FILES)]
|
||||
for(CURRENT in 1:length(REGIONS)){
|
||||
for(CURRENT in 1:length(LEONTIEF)){
|
||||
REGION <- REGIONS[CURRENT]
|
||||
FILE <- LEONTIEF[CURRENT]
|
||||
TYPE1 <- read_xlsx(FILE,'I-Ainv_type1')
|
||||
@ -28,14 +28,59 @@ if(CURRENT==1){RES <- CRES}else{RES <- rbind(RES,CRES)}
|
||||
return(RES %>% as_tibble)
|
||||
}
|
||||
ALL <- GET_MULTIPLIERS()
|
||||
ggplot(ALL,aes(x=Region,y=Total,color=Region)) + geom_boxplot()+theme(legend.position = "none")
|
||||
STATE_BIND <- cbind(state.name,state.abb) %>% as.tibble %>%rename(Region=state.name,State=state.abb)
|
||||
ALL$Region <- gsub("_"," ",ALL$Region)
|
||||
ALL <- ALL %>% inner_join(STATE_BIND)
|
||||
STATE_BIND <- cbind(state.name,state.abb) %>% as_tibble %>% rename(Region=state.name,State=state.abb)
|
||||
ALL <- STATE_BIND %>% inner_join(ALL)
|
||||
STATE_BIND <- ALL %>% group_by(State) %>% summarize(Total=median(Total)) %>% mutate(Rank=rank(-Total))
|
||||
ORD <- STATE_BIND %>% arrange(Rank) %>% pull(State)
|
||||
ALL$State <- factor(ALL$State,level=ORD)
|
||||
ALL_ORIG <- ALL
|
||||
ALL <- ALL %>% filter(Total<5)
|
||||
ggplot(ALL,aes(x=State,y=Total,color=State)) + geom_boxplot()+theme(legend.position = "none")
|
||||
REST <- ALL %>% filter(State!='WY')
|
||||
WY <- ALL %>% filter(State=='WY')
|
||||
ggplot(ALL,aes(x=State,y=Total)) + geom_jitter(width = 0.5,size=0.1,aes(color=State)) + geom_boxplot(fill=NA,outlier.shape=NA)+theme(legend.position = "none",aes(color=State) )
|
||||
+theme_bw()
|
||||
##############Import analsysi
|
||||
GET_IMPORT <- function(ROOT_FOLDER="States/",YEAR=2024){
|
||||
#ROOT_FOLDER="States/";YEAR=2024
|
||||
SUB_FOLDER <- list.files(ROOT_FOLDER)
|
||||
ENTRIES <- (strsplit(SUB_FOLDER,paste0("_",YEAR)) %>% unlist)
|
||||
REGIONS <- ENTRIES[seq(1,length(ENTRIES),by=2)]
|
||||
ALL_FILES <- list.files(paste0(ROOT_FOLDER,SUB_FOLDER),full.names=TRUE)
|
||||
IXC <- ALL_FILES[grep("ixc",ALL_FILES)]
|
||||
IXC <- IXC[grep("csv",IXC)]
|
||||
for(CURRENT in 1:length(IXC)){
|
||||
# CURRENT=51
|
||||
REGION <- REGIONS[CURRENT]
|
||||
FILE <- read_csv(IXC[CURRENT])
|
||||
NAMES <- strsplit(t(FILE[1:nrow(FILE),1]),"_") %>% unlist
|
||||
NAICS <- c(NAMES[seq(1,1952,by=2)],NAMES[1953:1966])
|
||||
Industry_Name <-c( NAMES[seq(2,1952,by=2)],NAMES[1953:1966])
|
||||
|
||||
|
||||
LIST <- c("ROW","RUSA","FED")
|
||||
IMPORT <- FILE %>% select(LIST) %>% as.matrix %>% t %>%rowSums()
|
||||
LOCAL <- FILE %>% select(-c(1,LIST)) %>% as.matrix %>% t %>% rowSums()
|
||||
NAICS
|
||||
cbind(NAICS,Industry_Name,IMPORT,LOCAL) %>% as_tibble %>% mutate(Import=as.numeric(IMPORT),Local_Purchase=as.numeric(LOCAL),Total=Import+Local_Purchase) %>% select(-IMPORT,-LOCAL) %>% tail
|
||||
|
||||
|
||||
|
||||
CRES <- cbind(REGION,IMPORT,LOCAL)
|
||||
if(CURRENT==1){RES <- CRES}else{RES <- rbind(RES,CRES)}
|
||||
}
|
||||
return(RES %>% as_tibble %>% mutate(IMPORT_PERCENT=as.numeric(IMPORT_PERCENT)))
|
||||
}
|
||||
IMPORT <- GET_IMPORT()
|
||||
IMPORT
|
||||
IMPORT <- IMPORT %>% mutate(IMPORT_PERCENT=as.numeric(IMPORT_PERCENT),RANK=rank(-IMPORT_PERCENT)) %>% arrange(RANK)
|
||||
|
||||
IMPORT %>% print(n=30)
|
||||
IXC <- read_csv("States/Wyoming_2024_SAM_v1.5.6/Wyoming_Update_ixi_502_2024.csv")
|
||||
IXC <- read_csv("States/North_Dakota_2024_SAM_v1.5.6/North_Dakota_ixi_502_2024.csv")
|
||||
|
||||
LIST <- c("ROW","RUSA","FED")
|
||||
EXPORT <- sum(IXC %>% select(LIST) )
|
||||
LOCAL <- sum(IXC %>% select(-c(1,LIST)) )
|
||||
EXPORT/LOCAL
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user