Skip to content

Commit

Permalink
Created new retail data for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
robjhyndman committed Jan 8, 2024
1 parent aeaebb4 commit 38b888b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Binary file added assignments/8501011.xlsx
Binary file not shown.
53 changes: 53 additions & 0 deletions assignments/Project.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
library(tidyverse)
library(readxl)
library(tsibble)

# xlsx file downloaded on 8 January.
# Need to download latest file on 6 Feb 2024 from
# https://www.abs.gov.au/statistics/industry/retail-and-wholesale-trade/retail-trade-australia/dec-2023/8501011.xlsx
download.file(
url = "https://www.abs.gov.au/statistics/industry/retail-and-wholesale-trade/retail-trade-australia/oct-2023/8501011.xlsx",
destfile = here::here("assignments/8501011.xlsx")
)

# Read data and meta data from xlsx file
series <- read_excel(here::here("assignments/8501011.xlsx"), sheet = 2, skip = 9) |>
rename(Month = `Series ID`) |>
gather(`Series ID`, Turnover, -Month) |>
mutate(Month = yearmonth(Month))
dict <- read_excel(here::here("assignments/8501011.xlsx"), sheet = 1, skip = 9) |>
filter(`Series Type` == "Original") |>
separate(`Data Item Description`, c("Category", "State", "Industry"), sep = ";", extra = "drop") |>
transmute(
State = trimws(State),
Industry = trimws(Industry),
`Series ID`
) |>
filter(
Industry != "Total (Industry)",
State != "Total (State)"
)

# Construct tibble
aus_retail <- left_join(dict, series, by = "Series ID") |>
filter(!is.na(Turnover)) |>
as_tibble()

# Make sure series go right to end
short_series <- aus_retail |>
summarise(Month = max(Month), .by="Series ID") |>
filter(Month < max(Month)) |>
pull(`Series ID`)

aus_retail <- aus_retail |>
filter(!(`Series ID` %in% short_series))

# Turn into tsibble
aus_retail <- aus_retail |>
as_tsibble(
index = Month,
key = c(State, Industry)
)

# Save data
saveRDS(aus_retail, here::here("assignments/retail.rds"))
Binary file added assignments/retail.rds
Binary file not shown.

0 comments on commit 38b888b

Please sign in to comment.