1

I am trying forecast forward 5 years and understand if there is a reason that the percentage of people in the workforce in the US with an advanced degree is declining. I am attempting to do so with hierarchical time series so that I can compare the total labor force, the percentage of those with advanced degrees and then splitting that into male and female.

I am new to R and need some help setting this up so that I can acquire some forecast data on the subject at hand.

The data set I am using has been cleaned up in Excel as can be seen here:

linked a picture here

All help is welcome, and more info can be provided, thank you.

I am trying to recreate something similar to this book example My current work is majorly from the provided book that is linked above:


title: "Final Notebook"

output: html_notebook

Created a working directory to import the dataset,

setwd("C:/Users/carso/OneDrive/Documents/03 Junior/Forecasting")
View(LaborForceFinal)
import.package('fpp2')
import.package('hts')

import.package('dplyr')
import.package('stringr')
import.package('tidyr')
LaborForce.hts <- hts(LaborForceFinal,characters = c())

LaborForce.hts %>% aggts(levels=0:1) %>%
  autoplot(facet=TRUE) +
  xlab("Year") + ylab("millions") + ggtitle("Labor Force")
p1 <- prison.gts %>% aggts(level=0) %>%
  autoplot() + ggtitle("Australian prison population") +
    xlab("Year") + ylab("Total number of prisoners ('000)")

groups <- aggts(prison.gts, level=1:3)

cols <- sample(scales::hue_pal(h=c(15,375),
          c=100,l=65,h.start=0,direction = 1)(NCOL(groups)))

p2 <- as_tibble(groups) %>%

  gather(Series) %>%

  mutate(Date = rep(time(groups), NCOL(groups)),
         Group = str_extract(Series, "([A-Za-z ]*)")) %>%

  ggplot(aes(x=Date, y=value, group=Series, colour=Series)) +
    geom_line() +
    xlab("Year") + ylab("Number of prisoners ('000)") +
    scale_colour_manual(values = cols) +
    facet_grid(.~Group, scales="free_y") +
    scale_x_continuous(breaks=seq(2006,2016,by=2)) +
    theme(axis.text.x = element_text(angle = 90, hjust = 1))

gridExtra::grid.arrange(p1, p2, ncol=1)
carson1398
  • 11
  • 2
  • What did you use? Is there a code block you're trying? Can you share please? – E. Zeytinci Dec 12 '19 at 06:11
  • Hello, welcome to SO ! Please look into [How to make a reproducible example](https://stackoverflow.com/q/5963269/6478701) for your post. It makes it a lot easier to help you. Screenshots of data is one of the most painful things we can run into on this website ! :-) – RoB Dec 12 '19 at 07:07
  • I want to recreate something similar to this code in Rstudio https://otexts.com/fpp2/gts.html – carson1398 Dec 12 '19 at 18:59

0 Answers0