fred <- read.csv('fred_qd.csv')
fred <- fred[-(1:2),]
fred_ts <- fred
fred_ts <- ts(fred[,-1],start=c(1959,1),frequency = 4)
# It gets rid of the first column "sasdate"
fred$NETEX <- (fred$EXPGSC1-fred$IMPGSC1)
install.packages(“stargazer”)
library(stargazer) library(graphics)
stargazer(subset(fred,select=c(GDPC1,PCECC96,GPDIC1,GCEC1,NETEX)),type='text')
#GDP CV
sd(fred$GDPC1, na.rm = TRUE)/mean(fred$GDPC1, na.rm = TRUE)
#Consumption CV
sd(fred$PCECC96, na.rm = TRUE)/mean(fred$PCECC96, na.rm = TRUE)
#Investment CV
sd(fred$GPDIC1, na.rm = TRUE)/mean(fred$GPDIC1, na.rm = TRUE)
#Governemtn Expenditure CV
sd(fred$GCEC1, na.rm = TRUE)/mean(fred$GCEC1, na.rm = TRUE)
#NX CV
sd(fred$NETEX, na.rm = TRUE)/mean(fred$NETEX, na.rm = TRUE)
fred_ts <- ts(fred[,-1],start=c(1959,1),frequency = 4)
gdp_components <- fred_ts[, c("GDPC1", "PCECC96", "GPDIC1", "GCEC1", "NETEX")]
plot(gdp_components)
#All the graphs are trending upwards except net exports which is trending down.
ts.plot(gdp_components,
main="Macroeconomic Aggregates",
xlab="Quarters",
ylab="Billions 2012 USD",
col=c("red","green","blue","black","brown"))
legend("topleft",
legend = c("GDP (Red)","Consumption (Green)", "Investment(Blue)", "Government Spending (Black)", "Net Exports (Brown)"),
col = c("red", "green", "blue", "black", "brown"))
sumcomponents <- fred$PCECC96+fred$GPDIC1+fred$GCEC1+fred$NETEX
differenceGDP <- fred$GDPC1 - sumcomponents
summary(differenceGDP)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -198.782 -111.661 -27.578 -56.635 1.121 51.296
t.test(differenceGDP)
##
## One Sample t-test
##
## data: differenceGDP
## t = -13.123, df = 262, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -65.13214 -48.13695
## sample estimates:
## mean of x
## -56.63455
Deviation <- c(fred$GDPC1,sumcomponents)
plot(Deviation,
xlab="Deviation",
ylab="GDP",
col=c("black","red"))