Translate

Monday, December 14, 2020

Analyzing GDP by Industry with R

 






































library(quantmod)
library(Quandl)
library(xts)
library(zoo)

Industry_Data <- read.csv("Industry Data.csv")
View(Industry_Data)

GDP<-ts(Industry_Data, start=c(2005,1), end=c(2020,2), frequency=4)

data<-GDP

data

# Percent changes from previous

percent_GDP<-diff(data, lag=4)/lag(data, k=-4)*100


Hw# Percentage of each industry in total industry

pct_GDP<-(data/data[,1])*100

summary(percent_GDP)


plot(pct_GDP)

par(mfrow=c(2,1))
plot(percent_GDP[,2], main="Private Industry")
plot(pct_GDP[,2])


par(mfrow=c(2,1))
plot(percent_GDP[,3], main="  Agriculture, forestry, fishing, and hunting")
plot(pct_GDP[,3])


par(mfrow=c(2,1))
plot(percent_GDP[,4], main="      Farms")
plot(pct_GDP[,4])


par(mfrow=c(2,1))
plot(percent_GDP[,6], main="       Mining")
plot(pct_GDP[,6])


par(mfrow=c(2,1))
plot(percent_GDP[,7], main="        Oil and gas extraction")
plot(pct_GDP[,7])


par(mfrow=c(2,1))
plot(percent_GDP[,11], main=" Construction")
plot(pct_GDP[,11])



par(mfrow=c(2,1))
plot(percent_GDP[,12], main="   Manufacturing")
plot(pct_GDP[,12])



par(mfrow=c(2,1))
plot(percent_GDP[,13], main="     Durable goods")
plot(pct_GDP[,13])


par(mfrow=c(2,1))
plot(percent_GDP[,19], main="Computer and electronic products")
plot(pct_GDP[,19])

par(mfrow=c(2,1))
plot(percent_GDP[,20], main="Electrical equipment, appliances, and components")
plot(pct_GDP[,20])

par(mfrow=c(2,1))
plot(percent_GDP[,21], main="Motor vehicles, bodies and trailers, and parts")
plot(pct_GDP[,21])


par(mfrow=c(2,1))
plot(percent_GDP[,27], main="    Textile mills and textile product mills")
plot(pct_GDP[,27])



par(mfrow=c(2,1))
plot(percent_GDP[,28], main="         Apparel and leather and allied products")
plot(pct_GDP[,28])

par(mfrow=c(2,1))
plot(percent_GDP[,34], main="    Wholesale trade")
plot(pct_GDP[,34])

par(mfrow=c(2,1))
plot(percent_GDP[,35], main="     Retail trade")
plot(pct_GDP[,35])

par(mfrow=c(2,1))
plot(percent_GDP[,40], main="   Transportation and warehousing")
plot(pct_GDP[,40])


par(mfrow=c(2,1))
plot(percent_GDP[,41], main="      Air transportation")
plot(pct_GDP[,41])



par(mfrow=c(2,1))
plot(percent_GDP[,42], main=" Rail transportation")
plot(pct_GDP[,42])


par(mfrow=c(2,1))
plot(percent_GDP[,49], main="Information")
plot(pct_GDP[,49])

par(mfrow=c(2,1))
plot(percent_GDP[,55], main="    Finance and insurance")
plot(pct_GDP[,55])


par(mfrow=c(2,1))
plot(percent_GDP[,60], main=" Real estate")
plot(pct_GDP[,60])


par(mfrow=c(2,1))
plot(percent_GDP[,62], main=" Housing")
plot(pct_GDP[,62])









No comments:

Post a Comment