library(fredr)
## Warning: package 'fredr' was built under R version 4.1.3

Acquiring time series and visualizing data

  1. Go to FRED’s website and find a data series that looks interesting to you. Find the series id and then use fredr to open the data here.
#Answer
fredr_set_key("b457ae0ea6c0b0245d19b24319c7d1f2")
EXUSEU<-fredr(series_id = "EXUSEU")
  1. Use the ts() function to create a time series variable.
#Answer
EXUSEUts<-ts(EXUSEU$value,start=c(1999,1), end=c(2022,2), frequency = 12)
  1. Use the xts() function to create an extensible time series data frame.
#Answer
library(xts)
## Warning: package 'xts' was built under R version 4.1.2
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
EXUSEUxts<-as.xts(EXUSEUts)
  1. Plot your time series.
#Answer
plot(EXUSEUts)

plot.xts(EXUSEUxts)

  1. Describe the trends in your time series.

ANSWER: The relationship of the value of US dollars to one Euro is consistently changing. After 2008 during the Great Recession, over 1.5 US dollars equaled 1 US dollar. This increase is the result of the very low inflation rates during this time. After the Great Recession the value of one US dollar increased and grew closer to the value of the Euro. In 2015 the value of the US dollar is around 1.2 times the value of one Euro.

Simulating a time series DGP

  1. Simulate a time series that has the DGP: \[ X_t = 20 + 0.25X_{t-1} + 0.35X_{t-2} + \varepsilon_{t} + 0.25*\varepsilon_{t-1}\]

where \(\varepsilon \sim N(10,2)\).

Your “initial values” xstart1 and xstart2 (hint: you need 2 of them) and time values are already listed below.

t<-c(1:400)
xstart1<-35
xstart2<-44
yinit = 0
xinit = xstart1
Y<-yinit
e<- rnorm(length(t), mean = 10, sd = 2)
for (i in 2:length(t)) {
  Y[i] = 20+0.25*Y[i-1]+0.35*Y[i-1]+e[i]+0.25*e[i-1]
  print(Y[i])
}
## [1] 30.29309
## [1] 47.49641
## [1] 61.43663
## [1] 67.30586
## [1] 72.53778
## [1] 76.13598
## [1] 75.11273
## [1] 73.18245
## [1] 78.7075
## [1] 78.44157
## [1] 78.04515
## [1] 79.44111
## [1] 80.51148
## [1] 83.93985
## [1] 87.00509
## [1] 83.44747
## [1] 81.82798
## [1] 80.10513
## [1] 79.92362
## [1] 84.21585
## [1] 85.12904
## [1] 83.5501
## [1] 82.6412
## [1] 83.08923
## [1] 80.12239
## [1] 81.2056
## [1] 83.92746
## [1] 82.28993
## [1] 80.79949
## [1] 83.02961
## [1] 84.29846
## [1] 83.43927
## [1] 83.64669
## [1] 83.69867
## [1] 82.858
## [1] 79.39338
## [1] 81.24562
## [1] 83.2447
## [1] 82.82317
## [1] 83.09176
## [1] 85.26101
## [1] 83.58781
## [1] 83.99235
## [1] 79.00922
## [1] 77.64449
## [1] 78.30045
## [1] 78.8529
## [1] 83.48492
## [1] 85.26355
## [1] 81.59072
## [1] 81.78821
## [1] 80.91422
## [1] 81.5265
## [1] 82.78646
## [1] 83.93542
## [1] 85.18921
## [1] 82.19862
## [1] 80.20193
## [1] 80.72967
## [1] 79.70275
## [1] 78.31148
## [1] 77.21532
## [1] 79.95021
## [1] 82.06258
## [1] 78.06116
## [1] 77.06965
## [1] 79.37157
## [1] 81.55414
## [1] 78.51817
## [1] 75.47667
## [1] 75.93144
## [1] 75.93267
## [1] 77.51474
## [1] 80.27963
## [1] 76.33627
## [1] 76.22971
## [1] 76.83762
## [1] 78.2017
## [1] 78.20979
## [1] 80.84078
## [1] 81.29536
## [1] 83.22563
## [1] 84.36768
## [1] 84.57333
## [1] 81.86418
## [1] 78.49227
## [1] 79.67113
## [1] 81.29041
## [1] 81.73073
## [1] 80.60832
## [1] 79.39067
## [1] 77.07273
## [1] 79.19504
## [1] 84.22793
## [1] 77.8175
## [1] 82.31209
## [1] 81.90275
## [1] 82.9094
## [1] 83.01395
## [1] 79.32732
## [1] 81.15806
## [1] 80.25521
## [1] 78.4718
## [1] 81.28916
## [1] 79.65799
## [1] 80.76363
## [1] 81.17929
## [1] 82.16978
## [1] 78.02418
## [1] 79.78299
## [1] 80.25904
## [1] 78.75808
## [1] 75.70415
## [1] 78.48881
## [1] 79.24227
## [1] 77.17023
## [1] 77.43104
## [1] 79.74847
## [1] 83.45017
## [1] 85.39333
## [1] 84.73818
## [1] 81.41196
## [1] 80.05707
## [1] 80.33837
## [1] 81.7731
## [1] 80.23263
## [1] 77.96704
## [1] 77.40529
## [1] 78.23516
## [1] 76.99201
## [1] 77.5614
## [1] 74.87381
## [1] 75.62843
## [1] 76.17547
## [1] 78.58848
## [1] 78.83733
## [1] 79.33934
## [1] 80.5778
## [1] 81.38507
## [1] 78.21648
## [1] 76.69652
## [1] 79.49478
## [1] 85.8102
## [1] 87.94156
## [1] 86.88824
## [1] 85.58724
## [1] 83.16694
## [1] 80.1607
## [1] 80.71207
## [1] 83.24199
## [1] 82.34872
## [1] 84.30297
## [1] 84.74725
## [1] 82.97333
## [1] 81.46318
## [1] 81.1082
## [1] 81.60441
## [1] 81.0437
## [1] 81.60119
## [1] 80.9171
## [1] 79.48923
## [1] 78.93922
## [1] 77.26361
## [1] 76.91185
## [1] 74.33943
## [1] 75.16943
## [1] 79.1897
## [1] 80.43659
## [1] 81.72095
## [1] 80.15536
## [1] 79.35709
## [1] 81.68989
## [1] 79.54101
## [1] 80.75482
## [1] 80.76591
## [1] 82.58881
## [1] 82.20702
## [1] 78.4732
## [1] 79.48117
## [1] 81.77461
## [1] 79.06396
## [1] 81.90496
## [1] 82.47798
## [1] 81.03062
## [1] 82.56848
## [1] 81.58705
## [1] 78.05899
## [1] 77.48981
## [1] 79.9125
## [1] 81.84199
## [1] 83.76392
## [1] 86.60383
## [1] 85.16085
## [1] 80.25767
## [1] 77.9683
## [1] 77.30615
## [1] 76.80513
## [1] 77.15176
## [1] 79.4263
## [1] 79.76183
## [1] 78.94696
## [1] 79.40153
## [1] 83.02944
## [1] 81.3157
## [1] 85.2089
## [1] 84.41255
## [1] 82.40016
## [1] 84.96622
## [1] 82.48253
## [1] 82.11904
## [1] 78.80091
## [1] 80.64564
## [1] 80.46086
## [1] 79.84022
## [1] 80.26828
## [1] 77.83447
## [1] 76.62891
## [1] 75.63238
## [1] 78.23033
## [1] 76.4807
## [1] 76.31409
## [1] 76.95211
## [1] 77.99829
## [1] 80.83043
## [1] 80.57571
## [1] 81.58501
## [1] 80.7781
## [1] 78.833
## [1] 76.72824
## [1] 83.10899
## [1] 85.62148
## [1] 87.73393
## [1] 86.21379
## [1] 84.2971
## [1] 84.60818
## [1] 83.95551
## [1] 82.86886
## [1] 83.69451
## [1] 86.0121
## [1] 82.64486
## [1] 80.18286
## [1] 83.02339
## [1] 81.61022
## [1] 83.89979
## [1] 78.85279
## [1] 75.74732
## [1] 77.87042
## [1] 79.9745
## [1] 81.62413
## [1] 79.74453
## [1] 76.65083
## [1] 74.70685
## [1] 77.74542
## [1] 79.79095
## [1] 83.466
## [1] 79.86827
## [1] 78.58025
## [1] 79.59374
## [1] 84.28659
## [1] 82.63206
## [1] 81.57158
## [1] 80.22889
## [1] 79.68659
## [1] 83.44081
## [1] 85.3224
## [1] 81.41937
## [1] 78.78096
## [1] 80.13116
## [1] 81.07381
## [1] 78.94143
## [1] 79.57109
## [1] 79.56723
## [1] 77.36614
## [1] 79.22529
## [1] 81.9169
## [1] 77.64803
## [1] 78.19535
## [1] 81.39768
## [1] 78.65138
## [1] 79.45548
## [1] 79.00009
## [1] 77.88318
## [1] 78.97997
## [1] 77.69976
## [1] 79.21302
## [1] 80.32005
## [1] 78.9573
## [1] 81.93643
## [1] 82.92437
## [1] 81.6653
## [1] 84.62419
## [1] 83.54599
## [1] 84.51897
## [1] 85.08776
## [1] 83.15663
## [1] 81.4936
## [1] 84.05847
## [1] 83.38376
## [1] 82.72499
## [1] 79.8694
## [1] 76.19611
## [1] 77.54305
## [1] 82.58744
## [1] 79.78915
## [1] 79.32426
## [1] 78.76643
## [1] 78.7665
## [1] 82.53007
## [1] 82.12036
## [1] 79.85292
## [1] 82.74186
## [1] 77.40129
## [1] 74.77428
## [1] 75.84521
## [1] 77.04994
## [1] 78.04547
## [1] 82.09156
## [1] 83.68056
## [1] 83.0612
## [1] 84.09001
## [1] 82.67212
## [1] 82.60206
## [1] 85.83827
## [1] 84.47523
## [1] 85.41996
## [1] 87.1832
## [1] 86.51633
## [1] 83.50727
## [1] 81.58821
## [1] 82.58785
## [1] 81.56953
## [1] 85.25689
## [1] 86.89982
## [1] 86.42303
## [1] 84.73704
## [1] 87.02947
## [1] 86.75729
## [1] 84.24581
## [1] 80.41267
## [1] 80.55132
## [1] 77.8067
## [1] 82.21362
## [1] 80.91536
## [1] 76.25321
## [1] 77.55474
## [1] 77.06474
## [1] 79.64935
## [1] 81.34898
## [1] 85.45616
## [1] 86.31743
## [1] 82.2967
## [1] 82.44405
## [1] 80.0938
## [1] 81.24922
## [1] 80.22521
## [1] 79.69797
## [1] 76.98165
## [1] 80.5826
## [1] 85.2987
## [1] 85.12518
## [1] 82.94097
## [1] 81.4832
## [1] 78.39007
## [1] 77.86187
## [1] 81.14713
## [1] 82.09065
## [1] 82.05051
## [1] 81.28446
## [1] 78.5681
## [1] 74.29997
## [1] 77.00789
## [1] 79.39943
## [1] 79.76022
## [1] 81.78745
## [1] 81.96044
## [1] 82.78143
## [1] 81.35287
## [1] 83.27311
## [1] 83.09838
## [1] 81.1596
## [1] 83.34714
## [1] 80.38417
## [1] 78.61785
## [1] 79.3284
## [1] 82.13622
## [1] 81.52505
## [1] 82.54081
## [1] 81.01493
## [1] 84.07352
## [1] 84.32708
## [1] 82.72009
## [1] 82.01363
## [1] 80.73165
## [1] 77.82736
## [1] 79.33342
## [1] 79.05418
## [1] 73.77219
## [1] 74.34144
## [1] 72.94923
plot(t,Y, type = "l")

#ANSWER 
  1. Describe the time series.

ANSWER: The time series increases rapidly in the beginning, then trends around 80. The deterministic factors of the function cause for the decaying trendline of the time series. The stochastic factors cause for the random shifts in the value of Y once t equals 5.