Start of population project
This commit is contained in:
parent
a1dce05323
commit
e87f5d1ba4
89
Popultaion.R
Normal file
89
Popultaion.R
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
library(rvest)
|
||||||
|
library(tidyverse)
|
||||||
|
library(fixest)
|
||||||
|
#Data found on the page http://eadiv.state.wy.us/pop/
|
||||||
|
PAGE <- read_html("http://eadiv.state.wy.us/pop/BirthDeathMig.htm")
|
||||||
|
NODE <- html_element(PAGE ,"table")
|
||||||
|
TBL <- html_table(NODE)
|
||||||
|
|
||||||
|
ST <- which(toupper(TBL$X1)=="ALBANY")
|
||||||
|
END <- which(toupper(TBL$X1)=="TOTAL")
|
||||||
|
TYPES <- TBL[ST-2,1]
|
||||||
|
|
||||||
|
ST_YEAR <- 1971
|
||||||
|
ALL_DATA <- list()
|
||||||
|
TBL <- TBL[,c(1,which(!is.na(as.numeric(TBL[ST[1],]))))]
|
||||||
|
TBL <- TBL[,-ncol(TBL)]
|
||||||
|
colnames(TBL) <- c("County",(ST_YEAR:(ST_YEAR+ncol(TBL)-1)))
|
||||||
|
TBL$Type <- NA
|
||||||
|
for(i in 1:length(ST)){
|
||||||
|
TBL[ST[i]:END[i],"Type"]<- as.character(TYPES[i,1])
|
||||||
|
}
|
||||||
|
TBL[ST[2]:END[2],"Type"] <- as.character(TYPES[2,1])
|
||||||
|
TBL$Type
|
||||||
|
TBL <- TBL %>% filter(!is.na(Type)) %>% select(County,Type,everything())
|
||||||
|
GROUP <- colnames(TBL)[-1:-2]
|
||||||
|
Data <- pivot_longer(TBL,all_of(GROUP),names_to="Year",values_to="Pop_Change")
|
||||||
|
Data$County <- ifelse(toupper(Data$County)=="TOTAL","Wyoming",Data$County)
|
||||||
|
Data <- pivot_wider(Data,names_from=Type,values_from=Pop_Change)
|
||||||
|
colnames(Data)[5] <-"Migration"
|
||||||
|
HOUSE_INCOME <- read_csv("https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=MEHOINUSWYA672N&scale=left&cosd=1984-01-01&coed=2023-01-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1984-01-01")
|
||||||
|
HOUSE_INCOME <-
|
||||||
|
colnames(HOUSE_INCOME) <- c("Year","WY_INCOME")
|
||||||
|
HOUSE_INCOME <- HOUSE_INCOME %>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
#Employment in construction of Wyoming
|
||||||
|
CON_EMP <- read_csv('https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=WYCONS&scale=left&cosd=1990-01-01&coed=2025-07-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1990-01-01')
|
||||||
|
colnames(CON_EMP) <- c("Year","WY_CON_EMP")
|
||||||
|
CON_EMP <- CON_EMP%>% mutate(Year=year(Year))
|
||||||
|
LINC_UNEMP <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=WYLINC3URN&scale=left&cosd=1990-01-01&coed=2025-07-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1990-01-01'
|
||||||
|
LINC_GDP <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=REALGDPALL56023&scale=left&cosd=2001-01-01&coed=2023-01-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=2001-01-01'
|
||||||
|
LINC_GDP<- read_csv(LINC_GDP)
|
||||||
|
colnames(LINC_GDP) <- c("Year","LINC_GDP")
|
||||||
|
LINC_GDP <- LINC_GDP %>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
|
||||||
|
LINC_PRIV_IND <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=ENU5602320510&scale=left&cosd=1990-01-01&coed=2024-10-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1990-01-01'
|
||||||
|
LINC_PRIV_IND <- read_csv(LINC_PRIV_IND)
|
||||||
|
LINC_PRIV_IND
|
||||||
|
colnames(LINC_PRIV_IND) <- c("Year","LINC_PRIV_IND")
|
||||||
|
LINC_PRIV_IND <- LINC_PRIV_IND %>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
LINC_LABOR_FORCE <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=WYLINC3LFN&scale=left&cosd=1990-01-01&coed=2025-07-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1990-01-01'
|
||||||
|
LINC_LABOR_FORCE<- read_csv(LINC_LABOR_FORCE)
|
||||||
|
colnames(LINC_LABOR_FORCE) <- c("Year","LINC_LABOR_FORCE")
|
||||||
|
LINC_LABOR_FORCE<- LINC_LABOR_FORCE%>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LINC_GOV_GDP <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=GDPGOVT56023&scale=left&cosd=2001-01-01&coed=2023-01-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=2001-01-01'
|
||||||
|
LINC_GOV_GDP <- read_csv(LINC_GOV_GDP)
|
||||||
|
colnames(LINC_GOV_GDP) <- c("Year","LINC_GOV_GDP")
|
||||||
|
LINC_GOV_GDP<-LINC_GOV_GDP%>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
|
||||||
|
LINC_POP <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=WYLINC3POP&scale=left&cosd=1970-01-01&coed=2024-01-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1970-01-01'
|
||||||
|
LINC_POP <- read_csv(LINC_POP)
|
||||||
|
colnames(LINC_POP) <- c("Year","LINC_POP")
|
||||||
|
LINC_POP <- LINC_POP %>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
|
||||||
|
WY_POP <- 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23ebf3fb&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1320&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=WYPOP&scale=left&cosd=1900-01-01&coed=2024-01-01&line_color=%230073e6&link_values=false&line_style=solid&mark_type=none&mw=3&lw=3&ost=-99999&oet=99999&mma=0&fml=a&fq=Annual&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2025-08-29&revision_date=2025-08-29&nd=1900-01-01'
|
||||||
|
WY_POP <- read_csv(WY_POP)
|
||||||
|
colnames(WY_POP) <- c("Year","WY_POP")
|
||||||
|
WY_POP <- WY_POP %>% mutate(Year=year(Year))
|
||||||
|
|
||||||
|
LINC_PRIV_IND
|
||||||
|
DF <- LINC_POP %>% left_join(WY_POP) %>% left_join(LINC_PRIV_IND) %>% left_join(LINC_LABOR_FORCE) %>% left_join(LINC_GOV_GDP) %>% left_join(LINC_GDP) %>% left_join(WY_POP)
|
||||||
|
DF %>% select(LINC_POP,WY_POP)
|
||||||
|
DF <- DF %>% mutate(WY_POP=WY_POP-LINC_POP)
|
||||||
|
#Check a VAR it looks like lags on changes to Private industry could affect other variables
|
||||||
|
feols((LINC_POP)~(WY_POP)+log(LINC_PRIV_IND)+Year,data=DF)
|
||||||
|
feols(log(1000*LINC_POP)~log(LINC_GDP)+log(LINC_PRIV_IND)+log(LINC_LABOR_FORCE)+log(LINC_PRIV_IND)+Year,DF)
|
||||||
|
DF
|
||||||
|
ggplot(data=DF) +geom_point(aes(x=Year,y=WY_POP),color="red")+geom_point(aes(x=Year,y=30*LINC_POP),color="blue")+geom_point(aes(x=Year,y=LINC_GDP/1700),color="black")+geom_point(aes(x=Year,y=LINC_PRIV_IND/1),color="green")+geom_point(aes(x=Year,y=LINC_LABOR_FORCE/20),color="orange")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user