library(tidyverse)
library("RColorBrewer")
library("knitr")
library("kableExtra")


##########Save all raw data categories
DATA_PATH <- "./Raw_Output/"
if(!file.exists("./Results")){dir.create("./Results")}
source("Scripts/Data_Proc_Script.r")
EVENT_DATA <- GET_EVENT_DATA(2025:2031)
  EVENT_DATA <- EVENT_DATA %>% mutate(VA=OPI+TOPI+EMP_COM+PROP_INC)
  write_csv(EVENT_DATA,"./Results/Yearly_Detailed_Event_Data.csv")
DATA <- GET_SUMMARY_DATA()
  DATA[,c(-2:-6,-8:-10)] <- round(DATA[,c(-2:-6,-8:-10)])
  DATA[,c(3:6,8:10)] <- round(DATA[,c(3:6,8:10)],2)
  DATA[2,3:6] <- NA
  DATA <- DATA  %>% mutate(VA=OPI+TOPI+EMP_COM+PROP_INC)
 DATA <- DATA %>% filter(!is.na(MAJOR_EVENT)) %>% ungroup
  write_csv(DATA,"./Results/Yearly_Event_Summary.csv")
DATA_ORIG <- DATA

DETAILED_DATA <- GET_DETAIL_ECON_DATA()
write_csv(DETAILED_DATA,"./Results/Detailed_Economic_Indicators.csv")

SUMMARY_BY_YEAR <- round(GET_TOTAL_SUMMARY())
write_csv(SUMMARY_BY_YEAR,"./Results/Yearly_State_Totals.csv")
DATA <- DATA_ORIG
#Advanced Summary Tables
EMP_OUTPUTS_CONSTRUCTION <- DETAILED_DATA %>% filter(YEAR<=2029) %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(Employment))
TOP_20 <- EMP_OUTPUTS_CONSTRUCTION[1:20,] 
OTHERS <- EMP_OUTPUTS_CONSTRUCTION[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(EMP_OUTPUTS_CONSTRUCTION[-1-20,-1] ))
EMP_OUTPUTS_CONSTRUCTION <-rbind(TOP_20,OTHERS)
EMP_OUTPUTS_CONSTRUCTION[,-1] <- round(EMP_OUTPUTS_CONSTRUCTION[,-1])
write_csv(EMP_OUTPUTS_CONSTRUCTION,"./Results/Top_20_Employmnet_During_Development.csv")

VA_OUTPUTS_Induced_CONSTRUCTION <- DETAILED_DATA %>% filter(YEAR<=2029,IMPACT_TYPE=="Induced") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Induced_CONSTRUCTION[1:5,] 
OTHERS <- VA_OUTPUTS_Induced_CONSTRUCTION[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Induced_CONSTRUCTION[-1-5,-1] ))
VA_OUTPUTS_Induced_CONSTRUCTION <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Induced_CONSTRUCTION[,-1] <- round(VA_OUTPUTS_Induced_CONSTRUCTION[,-1])
write_csv(VA_OUTPUTS_Induced_CONSTRUCTION,"./Results/Top_5_VA_Induced_Development.csv")


VA_OUTPUTS_Indirect_CONSTRUCTION <- DETAILED_DATA %>% filter(YEAR<=2029,IMPACT_TYPE=="Indirect") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Indirect_CONSTRUCTION[1:5,] 
OTHERS <- VA_OUTPUTS_Indirect_CONSTRUCTION[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Indirect_CONSTRUCTION[-1-5,-1] ))
VA_OUTPUTS_Indirect_CONSTRUCTION <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Indirect_CONSTRUCTION[,-1] <- round(VA_OUTPUTS_Indirect_CONSTRUCTION[,-1])
write_csv(VA_OUTPUTS_Indirect_CONSTRUCTION,"./Results/Top_5_VA_Indirect_Development.csv")

VA_OUTPUTS_Direct_CONSTRUCTION <- DETAILED_DATA %>% filter(YEAR<=2029,IMPACT_TYPE=="Direct") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Direct_CONSTRUCTION[1:5,] 
OTHERS <- VA_OUTPUTS_Direct_CONSTRUCTION[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Direct_CONSTRUCTION[-1-5,-1] ))
VA_OUTPUTS_Direct_CONSTRUCTION <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Direct_CONSTRUCTION[,-1] <- round(VA_OUTPUTS_Direct_CONSTRUCTION[,-1])
write_csv(VA_OUTPUTS_Direct_CONSTRUCTION,"./Results/Top_5_VA_Development.csv")

write_csv(cbind(VA_OUTPUTS_Direct_CONSTRUCTION,VA_OUTPUTS_Indirect_CONSTRUCTION,VA_OUTPUTS_Induced_CONSTRUCTION),"./Results/Top5_Construction.csv")

VA_OUTPUTS_Induced_OP <- DETAILED_DATA %>% filter(YEAR==2029,IMPACT_TYPE=="Induced") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Induced_OP[1:5,] 
OTHERS <- VA_OUTPUTS_Induced_OP[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Induced_OP[-1-5,-1] ))
VA_OUTPUTS_Induced_OP <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Induced_OP[,-1] <- round(VA_OUTPUTS_Induced_OP[,-1])
write_csv(VA_OUTPUTS_Induced_OP,"./Results/Top_5_VA_Induced_Op.csv")

VA_OUTPUTS_Indirect_OP <- DETAILED_DATA %>% filter(YEAR==2029,IMPACT_TYPE=="Indirect") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Indirect_OP[1:5,] 
OTHERS <- VA_OUTPUTS_Indirect_OP[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Indirect_OP[-1-5,-1] ))
VA_OUTPUTS_Indirect_OP <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Indirect_OP[,-1] <- round(VA_OUTPUTS_Indirect_OP[,-1])
write_csv(VA_OUTPUTS_Indirect_OP,"./Results/Top_5_VA_Indirect_OP.csv")

VA_OUTPUTS_Direct_OP <- DETAILED_DATA %>% filter(YEAR==2029,IMPACT_TYPE=="Direct") %>% rename(Industry=IND_DESC) %>%  group_by(Industry)  %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(`Value Added`))
TOP_20 <- VA_OUTPUTS_Direct_OP[1:5,] 
OTHERS <- VA_OUTPUTS_Direct_OP[1,] 
OTHERS[,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(VA_OUTPUTS_Direct_OP[-1-5,-1] ))
VA_OUTPUTS_Direct_OP <-rbind(TOP_20,OTHERS)
VA_OUTPUTS_Direct_OP[,-1] <- round(VA_OUTPUTS_Direct_OP[,-1])
write_csv(VA_OUTPUTS_Direct_OP,"./Results/Top_5_VA_Direct_OP.csv")

write_csv(cbind(VA_OUTPUTS_Direct_OP,VA_OUTPUTS_Indirect_OP,VA_OUTPUTS_Induced_OP),"./Results/Top5_Operating.csv")
COUNTY_OUTPUT_CONSTRUCTION <- EVENT_DATA %>% filter(YEAR<=2029)  %>% rename(County=COUNTY) %>% group_by(County) %>% summarize('Total Economic Output'=sum(OUTPUT),'Economic Value Added'=sum(EMP_COM+PROP_INC+TOPI+OPI),Employment=sum(EMP),'County Taxes'=sum(SUBCOUNTY_TAX+SPECIAL_TAX+COUNTY_TAX),'State Taxes'=sum(STATE_TAX)) %>% arrange(desc(Employment)) 
COUNTY_OUTPUT_CONSTRUCTION[,-1] <- round(COUNTY_OUTPUT_CONSTRUCTION[,-1])
write_csv(COUNTY_OUTPUT_CONSTRUCTION,"./Results/County_Outcomes_During_Development_(2029).csv")

EMP_OUTPUTS_OPERATING <- DETAILED_DATA %>% filter(YEAR==2030) %>% rename(Industry=IND_DESC) %>%  group_by(Industry)   %>% summarize('Employment'=sum(EMP),'Income'=sum(EMP_COMP+PROP_INC),'Other Profits'=sum(OPI),'Value Added'=sum(EMP_COMP+PROP_INC+TOPI+OPI),'Economic Output'=sum(OUTPUT)) %>% arrange(desc(Employment)) 
TOP_20 <- EMP_OUTPUTS_OPERATING[1:20,] 
OTHERS <- TOP_20[1,]
OTHERS[1,1] <-"Other Industries"
OTHERS[,-1] <- t(colSums(EMP_OUTPUTS_OPERATING[-1-20,-1] ))
EMP_OUTPUTS_OPERATING <-rbind(TOP_20,OTHERS) 
EMP_OUTPUTS_OPERATING[,-1] <- round(EMP_OUTPUTS_OPERATING[,-1])
write_csv(EMP_OUTPUTS_OPERATING,"./Results/Top_20_Yearly_Employmnet_During_Operation_(2030+).csv")

COUNTY_OUTPUTS_OPERATING<- EVENT_DATA %>% filter(YEAR==2030) %>% rename(County=COUNTY) %>% group_by(County) %>% summarize('Total Economic Output'=sum(OUTPUT),'Economic Value Added'=sum(EMP_COM+PROP_INC+TOPI+OPI),Employment=sum(EMP),'County Taxes'=sum(SUBCOUNTY_TAX+SPECIAL_TAX+COUNTY_TAX),'State Taxes'=sum(STATE_TAX)) %>% arrange(desc(Employment)) 
COUNTY_OUTPUTS_OPERATING[,-1] <- round(COUNTY_OUTPUTS_OPERATING[,-1])
write_csv(COUNTY_OUTPUTS_OPERATING,"./Results/County_Yearly_Outcomes_During_Operation_(2030+).csv")


STATE_SUMMARY <- EVENT_DATA %>% ungroup() %>% filter(YEAR<=2030) %>% mutate(Period=ifelse(YEAR!=2030,"Development","Operating")) %>% group_by(Period) %>% summarize('Total Economic Output'=sum(OUTPUT),'Economic Value Added'=sum(EMP_COM+PROP_INC+TOPI+OPI),'County Taxes'=sum(SUBCOUNTY_TAX+SPECIAL_TAX+COUNTY_TAX),Employment=sum(EMP),'State Taxes'=sum(STATE_TAX)) %>% arrange(desc(Employment))
  TEMP <- EVENT_DATA %>% ungroup() %>% filter(YEAR<2030) %>% mutate(Period=ifelse(YEAR!=2030,"Development","Operating")) %>% group_by(Period)  %>% summarize(Employment=sum(EMP)/5,'Total Economic Output'=sum(OUTPUT)/5,'Economic Value Added'=sum(EMP_COM+PROP_INC+TOPI+OPI)/5,'County Taxes'=sum(SUBCOUNTY_TAX+SPECIAL_TAX+COUNTY_TAX)/5,'State Taxes'=sum(STATE_TAX)/5) %>% arrange(desc(Employment))
  STATE_SUMMARY <- rbind(STATE_SUMMARY[2,],TEMP,STATE_SUMMARY[1,])
STATE_SUMMARY[,-1] <- round(STATE_SUMMARY[,-1])
STATE_SUMMARY$Length <- "Average"
STATE_SUMMARY$Length[3] <- "Total"
STATE_SUMMARY <- STATE_SUMMARY %>% select(Period,Length,everything())
write_csv(STATE_SUMMARY,"./Results/State_Summary.csv")



###################Write all tables for publication
kable(STATE_SUMMARY, format = "html", caption = "Economic Impact by Project Period",digits = 1, format.args = list(big.mark = ","))  %>%
  kable_styling(bootstrap_options = c("striped")) %>%
  column_spec(1:2, bold = TRUE, color = "Black")

kable(COUNTY_OUTPUTS_OPERATING, format = "html", caption = "County Level Yearly Economic Impact During Operation",digits = 1, format.args = list(big.mark = ","))  %>%
  kable_styling(bootstrap_options = c("striped")) %>%
  column_spec(1, bold = TRUE, color = "Black")

kable(COUNTY_OUTPUT_CONSTRUCTION, format = "html", caption = "County Level Total Economic Impact During Construction",digits = 1, format.args = list(big.mark = ","))  %>%
  kable_styling(bootstrap_options = c("striped")) %>%
  column_spec(1, bold = TRUE, color = "Black")


kable(EMP_OUTPUTS_CONSTRUCTION, format = "html", caption = "Sector Level Total Economic Impact During Construction",digits = 1, format.args = list(big.mark = ","))  %>%
  kable_styling(bootstrap_options = c("striped")) %>%
  column_spec(1, bold = TRUE, color = "Black")

kable(EMP_OUTPUTS_OPERATING, format = "html", caption = "Sector Level Yearly Economic Impact During Operation",digits = 1, format.args = list(big.mark = ","))  %>%
  kable_styling(bootstrap_options = c("striped")) %>%
  column_spec(1, bold = TRUE, color = "Black")


#############Make All Figures
#TAX_FILE <- FILES[grep("Taxes",FILES)]
             
              EVENT_DATA$MAJOR_EVENT <- ifelse(EVENT_DATA$MAJOR_EVENT=="Income","Royalties and income",EVENT_DATA$MAJOR_EVENT)
              DATA$MAJOR_EVENT <- ifelse(DATA$MAJOR_EVENT=="Income","Royalties and income",DATA$MAJOR_EVENT)
              ORD <- EVENT_DATA$MAJOR_EVENT %>% unique
              DATA$MAJOR_EVENT %>% unique
              EVENT_DATA$MAJOR_EVENT <- factor(EVENT_DATA$MAJOR_EVENT,levels=ORD)
              DATA$MAJOR_EVENT <- factor(DATA$MAJOR_EVENT,levels=ORD)
         
TAX_EVENT <- ggplot(aes(x=YEAR,y=WY_TOTAL_TAX/10^6,group=MAJOR_EVENT,fill=MAJOR_EVENT),data=EVENT_DATA)+geom_bar(stat = "identity")+
                  ylab("Wyoming Taxes (Million USD)")  + 
                xlab("Year")+
                labs(fill='Economic Event')+
                scale_x_continuous(breaks=2025:2031)+
                theme(legend.position = "top")+
                theme(text=element_text(size=20))+scale_fill_brewer(palette = "Pastel1")
EMP_EVENT<- ggplot(aes(x=YEAR,y=EMP,group=MAJOR_EVENT,fill=MAJOR_EVENT),data=EVENT_DATA)+geom_bar(stat = "identity")+
                ylab("Added Employment (Person-Years)")  + 
                xlab("Year")+
                labs(fill='Economic Event')+
                scale_x_continuous(breaks=2025:2031)+
                theme(legend.position = "top")+
                theme(text=element_text(size=20))+scale_fill_brewer(palette = "Set3")
VA_EVENT <- ggplot(aes(x=YEAR,y=VA/10^6,group=MAJOR_EVENT,fill=MAJOR_EVENT),data=EVENT_DATA)+geom_bar(stat = "identity")+
                ylab("Value Added (Million USD)")  + 
                xlab("Year")+
                labs(fill='Economic Event')+
                scale_x_continuous(breaks=2025:2031)+
                theme(legend.position = "top")+
                theme(text=element_text(size=20))+scale_fill_brewer(palette = "Pastel1")
OUTPUT_EVENT <- ggplot(aes(x=YEAR,y=OUTPUT/10^6,group=MAJOR_EVENT,fill=MAJOR_EVENT),data=EVENT_DATA)+geom_bar(stat = "identity")+
                    ylab("Value Added (Million USD)")  + 
                    xlab("Year")+
                    labs(fill='Economic Event')+
                    scale_x_continuous(breaks=2025:2031)+
                    theme(legend.position = "top")+
                    theme(text=element_text(size=20))+scale_fill_brewer(palette = "Pastel1")
TAX_TYPE <- ggplot(aes(x=YEAR,y=WY_TOTAL_TAX/10^6,group=IMPACT_TYPE,fill=IMPACT_TYPE),data=EVENT_DATA)+geom_bar(stat = "identity")+
              ylab("Wyoming Taxes (Million USD)")  + 
              xlab("Year")+
              labs(fill='Impact Type')+
              scale_x_continuous(breaks=2025:2031)+
              theme(legend.position = "top")+
              theme(text=element_text(size=20))

EMP_TYPE <- ggplot(aes(x=YEAR,y=EMP,group=IMPACT_TYPE,fill=IMPACT_TYPE),data=EVENT_DATA)+geom_bar(stat = "identity")+
              ylab("Added Employment (Person-Years)")  + 
              xlab("Year")+
              labs(fill='Impact Type')+
              scale_x_continuous(breaks=2025:2031)+
              theme(legend.position = "top")+
              theme(text=element_text(size=20))+scale_fill_brewer(palette = "Pastel1")

VA_TYPE <- ggplot(aes(x=YEAR,y=VA/10^6,group=IMPACT_TYPE,fill=IMPACT_TYPE),data=EVENT_DATA)+geom_bar(stat = "identity")+
              ylab("Value Added (Million USD)")  + 
              xlab("Year")+
              labs(fill='Impact Type')+
              scale_x_continuous(breaks=2025:2031)+
              theme(legend.position = "top")+
              theme(text=element_text(size=20))

OUTPUT_TYPE <- ggplot(aes(x=YEAR,y=OUTPUT/10^6,group=IMPACT_TYPE,fill=IMPACT_TYPE),data=EVENT_DATA)+geom_bar(stat = "identity")+
                      ylab("Total Output (Million USD)")  + 
                      xlab("Year")+
                      labs(fill='Impact Type')+
                      scale_x_continuous(breaks=2025:2031)+
                      theme(legend.position = "top")+
                      theme(text=element_text(size=20))
COMBINED_EVENT <- rbind(DATA %>% select(YEAR,MAJOR_EVENT,RES=OUTPUT) %>% mutate(GROUP="Economic Output",AREA="Total"),
              DATA %>% select(YEAR,MAJOR_EVENT,RES=VA) %>% mutate(GROUP="Economic Value Added",AREA="Total"),
DATA %>% select(YEAR,MAJOR_EVENT,RES=EMP_COM) %>% mutate(GROUP="Wyoming Salaries Paid",AREA="Wyoming"),
DATA %>% select(YEAR,MAJOR_EVENT,RES=WY_TOTAL_TAX) %>% mutate(GROUP="Wyoming Taxes",AREA="Wyoming")) %>% filter(YEAR<2032)
COMBINED_EVENT


FACET_PLOT_EVENT <- ggplot(aes(x=YEAR,y=RES/10^6,fill=MAJOR_EVENT,group=GROUP),data=COMBINED_EVENT)+
  geom_bar(stat = "identity")+facet_wrap(~GROUP,nrow=2)+
  ylab("Million USD")  + 
  xlab("Year")+
  labs(fill='Impact Type')+
  scale_x_continuous(breaks=2025:2031)+
  scale_y_continuous(breaks=c(0,5,10,15,seq(20,80,by=10)))+
  theme(legend.position = "top")+
  theme(text=element_text(size=20))+scale_fill_brewer(palette = "Set3")
FACET_PLOT_EVENT

COMBINED_TYPE <- rbind(EVENT_DATA %>% select(YEAR,IMPACT_TYPE,RES=OUTPUT) %>% mutate(GROUP="Economic Output",AREA="Total"),
                       EVENT_DATA %>% select(YEAR,IMPACT_TYPE,RES=VA) %>% mutate(GROUP="Economic Value Added",AREA="Total"),
                       EVENT_DATA %>% select(YEAR,IMPACT_TYPE,RES=EMP_COM) %>% mutate(GROUP="Wyoming Salaries Paid",AREA="Wyoming"),
                       EVENT_DATA %>% select(YEAR,IMPACT_TYPE,RES=WY_TOTAL_TAX) %>% mutate(GROUP="Wyoming Taxes",AREA="Wyoming")) %>% filter(YEAR<2032)
FACET_PLOT_TYPE <- ggplot(aes(x=YEAR,y=RES/10^6,fill=IMPACT_TYPE,group=IMPACT_TYPE),data=COMBINED_TYPE)+
  geom_bar(stat = "identity")+facet_wrap(~GROUP,nrow=2)+
  ylab("Million USD")  + 
  xlab("Year")+
  labs(fill='Impact Type')+
  scale_x_continuous(breaks=2025:2031)+
  scale_y_continuous(breaks=c(0,5,10,15,seq(20,80,by=10)))+
  theme(legend.position = "top")+
  theme(text=element_text(size=20))+scale_fill_brewer(palette = "Pastel1")
FACET_PLOT_TYPE
FACET_PLOT_EVENT
EMP_EVENT
EMP_TYPE

DIRECT_TAX <- EVENT_DATA %>% group_by(YEAR) %>% summarize(SUBCOUNTY_TAX=sum(SUBCOUNTY_TAX) ,SPECIAL_TAX=sum(SPECIAL_TAX),COUNTY_TAX=sum(COUNTY_TAX),STATE_TAX=sum(STATE_TAX) ,FEDERAL_TAX=sum(FEDERAL_TAX) )
DIRECT_TAX$TOTAL<- (rowSums(DIRECT_TAX[,-1]))

D <- EVENT_DATA %>% filter(IMPACT_TYPE =="Direct") %>% group_by(YEAR) %>% summarize(EMP=sum(EMP) ,EMP_COM =sum(EMP_COM ),VA=sum(VA),OUTPUT=sum(OUTPUT) )
EVENT_DATA  %>% group_by(YEAR) %>% summarize(EMP=sum(EMP) ,EMP_COM =sum(EMP_COM ),VA=sum(VA),OUTPUT=sum(OUTPUT) )
DIRECT_TAX$TOTAL<- (rowSums(DIRECT_TAX[,-1]))