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!
Cet exercice fait partie du cours
Case Study: Analyzing City Time Series Data in R
Instructions
- Use
lag()to generate a one-year lag of the MA unemployment rate (contained in themacolumn of your monthlyunemploymentdata). Remember to set thekargument equal to a year's worth of observations. Save this indicator to yourunemploymentdata asma_yearlag. - Use
diff()to generate a six-month first order difference in the MA unemployment rate. Remember to specify the correct column in yourunemploymentdata. Save this indicator to yourunemploymentdata asma_sixmonthdiff. - Measure the six-month rolling average of MA unemployment using
rollapply()Be sure to provide the appropriate specification for thewidthandFUNarguments. Save this indicator to yourunemploymentdata asma_sixmonthavg. - Measure the "high water mark" in unemployment over the past year using another call to
rollapply()with the appropriate specification of thewidthargument. This time, set theFUNargument tomax. Save this final indicator to yourunemploymentdata asma_yearmax. - Use
tail()to view the last year ofunemploymentdata (n = 12).
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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