diff --git a/ARMA_Pop.r b/ARMA_Pop.r new file mode 100644 index 0000000..b60a2c6 --- /dev/null +++ b/ARMA_Pop.r @@ -0,0 +1,22 @@ +library(tidyverse) +library(forecast) + +source("Scripts/Functions.r") +#source("Scripts/Load_Wyoming_Web_Data.r") + +DF <- FRED_GET('WYLINC3POP','LN_POP') %>% select(-YEAR) +TS <- 1000*ts(DF,start=c(1970),end=c(2024),frequency=1) +BC <- BoxCox.lambda(TS) +MODEL <- auto.arima(TS, lambda = BC) + +plot(forecast(MODEL,h=35),main="Lincoln County Population Forecast") + +#####Plan and ideas +#1) Review IMPLAN for industry multipliers +#2) Review IMPLAN for employment to population multipliers (imparted) +#3) Find a list of all planned new projects +#4) Use the IMPLAN multipliers for each sector to estimate total change +#5) Develop survey to estimate likelihood of new projects +#6) Compare to the ARMA percentile +#7) Adjust the ARMA up assuming some of these outputs are known. +####Other ideas, develop larger plan? Maybe look at decline in other industries as a proportion of employment diff --git a/BVAR_Pop.r b/BVAR_Pop.r index 5e0b04b..07603a6 100644 --- a/BVAR_Pop.r +++ b/BVAR_Pop.r @@ -33,6 +33,7 @@ DATA_TO_GATHER[[length(DATA_TO_GATHER)+1]] <- c('IDCARI9POP','CARIBOU_POP',FALS DATA_TO_GATHER[[length(DATA_TO_GATHER)+1]] <- c('IDBONN0POP','BONNEVILLE_POP',FALSE) ###US Population DATA_TO_GATHER[[length(DATA_TO_GATHER)+1]] <- c('POPTOTUSA647NWDB','US_POP',FALSE) +DATA_TO_GATHER[[length(DATA_TO_GATHER)+1]] <- c('CE16OV','US_EMP',FALSE) @@ -44,21 +45,48 @@ for(x in 1:length(DATA_TO_GATHER)){ if(x==1){RES <- C_DATA}else{RES <- RES %>% full_join(C_DATA)} rm(CURRENT,C_DATA) } + DATA <- RES %>% mutate(US_POP=US_POP-WY_POP,WY_POP=WY_POP-LN_POP-UINTA_POP-SUBLETTE_POP-SWEETWATER_POP-TETON_POP) colnames(DATA) -TS_DATA_ORIG <- DATA %>% select(YEAR,LN_POP,US_POP,WY_POP,UINTA_POP,SUBLETTE_POP,SWEETWATER_POP,TETON_POP,BEAR_LAKE_POP,CARIBOU_POP,BONNEVILLE_POP) %>% filter(!is.na(LN_POP)) %>% arrange(YEAR) %>% select(-YEAR) - +TS_DATA_ORIG <- DATA %>% select(YEAR,LN_POP,LN_EMPLOYMENT,US_EMP,US_POP,WY_POP,UINTA_POP,SUBLETTE_POP,SWEETWATER_POP,TETON_POP,BEAR_LAKE_POP,CARIBOU_POP,BONNEVILLE_POP) %>% + filter(!is.na(LN_POP),!is.na(LN_EMPLOYMENT)) %>% + arrange(YEAR) %>% select(-YEAR) +TEST <- RES %>% filter(!is.na(LN_EMPLOYMENT)) %>% mutate(LAG_LN_EMP=lag(LN_EMPLOYMENT)) +TEST %>% select(LN_EMPLOYMENT,LAG_LN_EMP) +feols(log(LN_POP)~log(LAG_LN_EMP)+lag(LN_POP)+YEAR,data=TEST ) +colnames(DATA) TS_DATA <- log(ts(TS_DATA_ORIG,start=c(1970),end=c(2024),frequency=1)) -plot(TS_DATA) -?bv_minnesota -MOD <- bvar(TS_DATA,lags=2, n_draw=15000) +tsplot(TS_DATA) +library(fixest) +TEMP <- feols(log(LN_POP) ~ lag(LN_POP)+log(US_EMP)+lag(log(US_EMP))+log(US_POP),data=DATA) +TEM + +plot(TEMP$residuals) +MOD <- bvar(TS_DATA,exogen="sdfs",sdflkj=5,lags=2, n_draw=15000) +plot(predict(MOD,horizon=25,value="LN_POP"),area=TRUE) +forecast(MOD,variables=c("LN_POP"),horizon=25) +?predict.bvar +?bv_mh summary(MOD) plot(MOD) plot(fitted(MOD,type="mean")) plot(residuals(MOD,type="mean"),vars=c("LN_POP","UINTA_POP","SWEETWATER_POP")) plot(MOD, type = "dens", vars_response = "LN_POP", vars_impulse = "LN_POP-lag1") opt_irf <- bv_irf(horizon = 25, identification = TRUE) -plot(irf(MOD,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_response = c("LN_POP"),vars_impulse = c("UINTA_POP","SWEETWATER_POP","WY_POP")) -plot(predict(MOD,horizon=25,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars=c("LN_POP","UINTA_POP")) + +plot(irf(MOD,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_impulse = c("LN_EMP"),vars_response = c("WY_POP","LN_POP","UINTA_POP","SUBLETTE_POP","SWEETWATER_POP")) +plot(irf(MOD,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_impulse = c("LN_EMP"),vars_response = c("TETON_POP","BEAR_LAKE_POP","CARIBOU_POP","BONNEVILLE_POP")) + +plot(irf(MOD,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_impulse = c("LN_POP"),vars_response = c("WY_POP","LN_POP","UINTA_POP","SUBLETTE_POP","SWEETWATER_POP")) +plot(irf(MOD,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_impulse = c("LN_POP"),vars_response = c("TETON_POP","BEAR_LAKE_POP","CARIBOU_POP","BONNEVILLE_POP")) + +DATA2 <- RES %>% mutate(US_POP=US_POP-WY_POP,WY_POP=WY_POP-LN_POP-UINTA_POP-SUBLETTE_POP-SWEETWATER_POP-TETON_POP) +TS_DATA2 <- DATA2 %>% select(YEAR,LN_POP,US_POP,WY_POP,UINTA_POP,SUBLETTE_POP,SWEETWATER_POP,TETON_POP,BEAR_LAKE_POP,CARIBOU_POP,BONNEVILLE_POP) %>% + dplyr::filter(!is.na(LN_POP)) %>% + arrange(YEAR) %>% select(-YEAR) %>% ts %>% log +MOD2 <- bvar(TS_DATA2,lags=5, n_draw=15000) +plot(irf(MOD2,opt_irf,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars_response = c("LN_POP")) +?plot.bvar_irf +plot(predict(MOD,horizon=25,conf_bands = c(0.05, 0.1,0.15)),area=TRUE,vars=c("LN_POP")) exp(3.5)-exp(3) acf(resid(MOD)) \ No newline at end of file