Manipulating MA unemployment data
Now that you've added some lags, differences, and rolling values to your GDP and US unemployment data, it's time to take these skills back to your assignment.
Remember that your client wants information relevant to the Boston tourism industry. In addition to data on the US economy in general, it may help to prepare some relevant indicators for your Massachusetts economic data.
In this exercise, you'll use your time series data manipulation skills to generate: a one-year lag, a six-month first order difference, a six-month rolling average, and a one-year rolling maximum in the MA unemployment rate. Your client is waiting!
This exercise is part of the course
Case Study: Analyzing City Time Series Data in R
Exercise instructions
- Use
lag()
to generate a one-year lag of the MA unemployment rate (contained in thema
column of your monthlyunemployment
data). Remember to set thek
argument equal to a year's worth of observations. Save this indicator to yourunemployment
data asma_yearlag
. - Use
diff()
to generate a six-month first order difference in the MA unemployment rate. Remember to specify the correct column in yourunemployment
data. Save this indicator to yourunemployment
data asma_sixmonthdiff
. - Measure the six-month rolling average of MA unemployment using
rollapply()
Be sure to provide the appropriate specification for thewidth
andFUN
arguments. Save this indicator to yourunemployment
data asma_sixmonthavg
. - Measure the "high water mark" in unemployment over the past year using another call to
rollapply()
with the appropriate specification of thewidth
argument. This time, set theFUN
argument tomax
. Save this final indicator to yourunemployment
data asma_yearmax
. - Use
tail()
to view the last year ofunemployment
data (n = 12
).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a one-year lag of MA unemployment
unemployment$ma_yearlag <-
# Add a six-month difference of MA unemployment
unemployment$ma_sixmonthdiff <-
# Add a six-month rolling average of MA unemployment
unemployment$ma_sixmonthavg <-
# Add a yearly rolling maximum of MA unemployment
unemployment$ma_yearmax <-
# View the last year of unemployment data