Skip to content

Commit

Permalink
This IE feed works fine for 005 aggregation. Must check 049.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanspeter85 committed Mar 3, 2020
1 parent 8dc5c70 commit ad170c5
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 67 deletions.
Binary file modified ConcordanceLibrary/EOL/EOL_RegionConcordance.xlsx
Binary file not shown.
98 changes: 49 additions & 49 deletions ConcordanceLibrary/EXIOBASE/Source2Root_Region_EXIOBASE.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ IEDataProcessing_PIOLab_WasteMFAIOExtension <- function(year,path)
# Load BACI trade flows
BACI <- read.csv(paste0(path$IE_Processed,"/BACI/BACI_",year,".csv"))

Flat_trade <- BACI %>% filter(Product == 8) %>% select(From,To,Quantity)
Long_trade <- BACI %>% filter(Product == 9) %>% select(From,To,Quantity)
Flat_trade <- BACI %>% filter(Product == base$product$Code[base$product$Name == "Flat rolled products"]) %>%
select(From,To,Quantity)

Long_trade <- BACI %>% filter(Product == base$product$Code[base$product$Name == "Long rolled products"]) %>%
select(From,To,Quantity)

# Estimate the net-use of products in countries
Flat_import <- Flat_trade %>% group_by(To) %>% summarise(Quantity = sum(Quantity))
Expand Down
3 changes: 3 additions & 0 deletions Rscripts/IEfeeds_code/IE_subroutines/IEFeed_PIOLab_EOL.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ IEFeed_PIOLab_EOL <- function(year,path)
path_set <- paste0(path$IE_Processed,"/EOL")
if(!dir.exists(path_set)) dir.create(path_set)

# Remove NaN (Bermudas & Kosovo for until we have a new root classification)
data_clean <- data_clean[!is.na(data_clean$base),]

write.csv(data_clean,
file = paste0(path_set,"/EOL_",year,".csv"),
row.names = FALSE)
Expand Down
8 changes: 4 additions & 4 deletions Rscripts/IEfeeds_code/IE_subroutines/IEFeed_PIOLab_WSA.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ IEFeed_PIOLab_WSA <- function(year,path)
# Load function to align data with root classification
source(paste0(path$Subroutines,"/Read_ProductionWSA.R"))

# Load region aggregator and look up base table codes
source(paste0(path$Subroutines,"/Root2Base_RegionAggregator.R"))
reg_agg <- Root2Base_RegionAggregator(RegionAggregator)

# Loop over selected items
for(i in 1:length(items))
{
Expand All @@ -25,10 +29,6 @@ IEFeed_PIOLab_WSA <- function(year,path)
# Read values and align with root classification
data_clean <- Read_ProductionWSA(path,year,item_page,yb,concord)

# Load region aggregator and look up base table codes
source(paste0(path$Subroutines,"/Root2Base_RegionAggregator.R"))
reg_agg <- Root2Base_RegionAggregator(RegionAggregator)

data_clean <- left_join(data_clean,reg_agg,by = c("Code" = "root"),copy = FALSE) %>% select(base,Quantity)
data_clean <- data_clean %>% group_by(base) %>% summarise(Quantity = sum(Quantity))

Expand Down
2 changes: 1 addition & 1 deletion Rscripts/IEfeeds_code/Ind20Pro22v1_InitialEstimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ if(file.exists(path$mother))
write.table(ALANG,file = filename,row.names = FALSE, quote = F,sep = "\t")
}

print(paste0("End of ",IEdatafeed_name," InitialEstimate."))
print(paste0("End of ",IEdatafeed_name," InitialEstimate."))
3 changes: 2 additions & 1 deletion Rscripts/Subroutines/Read_ProductionWSA.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Read_ProductionWSA <- function(path,year,item_page,yb,concord)
select(-countries,-index)
colnames(data_clean)[2] <- "Quantity"
# Look up root classification code and filter specific year
data_clean <- left_join(data_clean,root$region,by = c("ISO3digitCode"),copy = FALSE) %>% select(Code,Quantity)
data_clean <- left_join(data_clean,root$region,by = c("ISO3digitCode" = "RootCountryAbbreviation"),copy = FALSE) %>%
select(Code,Quantity)
# Translate quantities into metric tons
data_clean$Quantity <- data_clean$Quantity * 1000

Expand Down
41 changes: 31 additions & 10 deletions Rscripts/datafeeds_code/datafeed_PIOLab_IRPextraction.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ source(paste0(path$Subroutines,"/SE_LogRegression.R"))
RSE <- filter(read.xlsx(path$RSE_settings),Item == datafeed_name)
data <- SE_LogRegression(data,RSE$Minimum,RSE$Maximum)

# Create identity matrix to be used as concordance when doing t command
Concord <- diag(length(root$region$Code))

# Create empty ALANG table with header
source(paste0(path$Subroutines,"/makeALANGheadline.R"))
# Extend table with additional columns
Expand All @@ -32,31 +35,49 @@ for(i in 1:nrow(data))
reg_num <- data$Code[i]
reg_name <- as.character(root$region$Name[reg_num])
reg_num <- as.character(reg_num)

# Read extraction value
value <- as.character(data$Quantity[i])
value <- paste0("[",data$Quantity[i],";","NaN","]")
# Set SE
SE <- as.character(data$SE[i])
SE <- paste0("[",as.character(data$SE[i]),";","NaN","]")

# Add command for domestic Use table
ALANG <- add_row(ALANG,'1' = paste0("DataFeed IRP Extraction ",reg_name),
Value = value,'Row parent' = reg_num,'Column parent' = reg_num,S.E. = SE)
}

# Add NaN to all other regions
for(i in setdiff(root$region$Code,data$Code))
{
# Get root_code of region
reg_num <- root$region$Code[i]
reg_name <- as.character(root$region$Name[reg_num])
reg_num <- as.character(reg_num)

# Read extraction value
value <- SE <- paste0("[NaN;NaN]")

# Add command for domestic Use table
ALANG <- add_row(ALANG,'1' = paste0("DataFeed IRP Extraction ",reg_name),
Value = value,'Row parent' = reg_num,'Column parent' = reg_num,S.E. = SE)
}

# Add other variables

# Create product concordance
Concord <- matrix(0,nrow = 1, ncol = length(root$product$Code))
Concord[1,1:5] <- 1
# Create industry concordance
max_ind <- length(root$industry$Code)
Concord <- matrix(0,nrow = 2, ncol = max_ind)
Concord[1,1:4] <- 1
Concord[2,5:max_ind] <- 1

# Write to folder
Concord_path <- paste0(path$Concordance,"/IRPextraction_concordance.csv")
Concord_path <- paste0(path$Concordance,"/IRPextraction_Sec_Concordance.csv")
write.table(Concord,file = Concord_path,row.names = FALSE,col.names = FALSE,sep = ",")

# Create extension conocrdane

ALANG$`Row child` <- "3"
ALANG$`Row grandchild` <- "1"
ALANG$`Column child` <- "1"
ALANG$`Column grandchild` <- "1:e t2 CONCPATH/IRPextraction_concordance.csv"
ALANG$`Column grandchild` <- "1:e t1 CONCPATH/IRPextraction_Sec_Concordance.csv"
ALANG$`#` <- as.character(1:nrow(ALANG))
ALANG$Incl <- "Y"
ALANG$Parts <- "1"
Expand All @@ -72,4 +93,4 @@ ALANG$Coef1 <- "1"
source(paste0(path$root,"Rscripts/datafeeds_code/datafeed_subroutines/WriteALANG2Folder.R"))

print(paste0("datafeed_PIOLab_",datafeed_name," finished."))

0 comments on commit ad170c5

Please sign in to comment.