## rmarkdown::render(file.path(dbpath, "GitHub", "stan", "vignettes", "stan_volume_highchart.Rmd"))

## bowerth.github.io
## file.copy(from=file.path(dbpath, "GitHub", "stan", "vignettes", "stan_volume_highchart.html"), to=file.path(dbpath, "GitHub", "jekyll", "bowerth.github.io", "_includes", "rmarkdown_fragment", "stan_volume_highchart.html"), overwrite=TRUE)

## industry
## file.copy(from=file.path(dbpath, "GitHub", "stan", "vignettes", "stan_volume_highchart.html"), to=file.path(dbpath, "GitHub", "jekyll", "industry", "_includes", "rmarkdown_fragment", "stan_volume_highchart.html"), overwrite=TRUE)

## browseURL(file.path("file:/", Sys.getenv("HOME"), "Dropbox", "GitHub", "stan", "vignettes", "stan_volume_highchart.html"))

library(dygraphs)
library(highcharter)
library(xts)
library(stan)
library(dplyr)

df2xts <- function(data_df) {
  data_xts <- data_df
  rownames(data_xts) <- paste0(data_xts$year, '-01-01')
  ## ordered <- c("VALU", "VKOT")
  ## data_xts <- subset(data_xts, select=c(ordered, names(data_xts)[!names(data_xts)%in%c(ordered, "ind", "year")]))
  data_xts <- subset(data_xts, select=names(data_xts)[!names(data_xts)%in%c("ind", "year")])
  data_xts <- xts::as.xts(data_xts, dateFormat="Date")
  return(data_xts)
}

## dygraph_vignette <- function(...) {
##     dygraph(...) %>%
##       dyLegend(width=550, show="onmouseover")
## }

highchart_vignette <- function() {
    highchart() %>%
    hc_yAxis(
        list(title = list(text = "Value"), align = "left", opposite = FALSE),
        list(title = list(text = "Index"), align = "right", opposite = TRUE)) %>%
                hc_add_theme(hc_theme_darkunica())
}
?stan::stanVolume

General

Chain-linking is obtained by multiplying each annual link as an index by the chain accumulated up until the previous year. The chain obtained using this method is obviously an index number. Therefore, its conversion to monetary terms is performed by multiplying it by the value at current prices for a specific year, called "reference year".

Source: INE

Objective

Calculate previous year price VKPY and chained volume VALK series from current prices VALU and chained index VKOT series

Data Examples

Chained Laspeyres example: Sweden

data_csv <- read.csv(file =
                         system.file(file.path("extdata", "volumeLaspeyresPivot.csv"), package="stan")
                     )
y_lab <- "Billion SEK"
names(data_csv) <- sub("NSONA_", "", names(data_csv))
data_csv_init <- subset(data_csv, select=c("ind", "year", "VALU", "VKOT"))
data_csv_xts <- 
    data_csv_init %>% df2xts()

highchart_vignette() %>%
    hc_title(text = "Initial Data") %>%
        hc_add_series_xts(data_csv_xts[,"VALU"], name = "VALU") %>%
            hc_add_series_xts(data_csv_xts[,"VKOT"], name = "VKOT", yAxis = 1)
data_csv_valk <- data_csv_init %>%
    mutate(VALK=stan::cpIdxCl(data=data_csv_init, var.cp="VALU", var.idx="VKOT", id.vars="ind", refyear=2010))

data_csv_valk_xts <- data_csv_valk %>% df2xts()

highchart_vignette() %>%
    hc_title(text = "Intermediate Data (including VALK)") %>%
    hc_add_series_xts(data_csv_valk_xts[,"VALU"], name = "VALU") %>%
        hc_add_series_xts(data_csv_valk_xts[,"VALK"], name = "VALK") %>%
            hc_add_series_xts(data_csv_valk_xts[,"VKOT"], name = "VKOT", yAxis = 1)
data_csv_valk_vkpy <- 
    data_csv_valk %>%
        mutate(VKPY=stan::cpVolPyp(data=data_csv_valk, var.cp="VALU", var.cl="VALK", id.vars="ind"))

data_csv_valk_vkpy_xts <- data_csv_valk_vkpy %>% df2xts()

highchart_vignette() %>%
    hc_title(text = "Final Data (including VKPY)") %>%
    hc_add_series_xts(data_csv_valk_vkpy_xts[,"VALU"], name = "VALU") %>%
        hc_add_series_xts(data_csv_valk_vkpy_xts[,"VALK"], name = "VALK") %>%
            hc_add_series_xts(data_csv_valk_vkpy_xts[,"VKPY"], name = "VKPY") %>%
            hc_add_series_xts(data_csv_valk_vkpy_xts[,"VKOT"], name = "VKOT", yAxis = 1)

Additional Explanation and Formulas

How do I use chain-type indexes (or chained-dollar) measures of economic activity, such as real GDP?

Use real (chain-type indexes or chain-dollar) estimates when you want to show how output or spending has changed over time. The percent changes in quantity indexes exactly match the percent changes in chained dollars, so they can be used interchangeably for making comparisons. Real estimates remove the effects of price changes, which can obscure changes in output or spending in current dollars. Examples of the use of real estimates include:

Source: www.bea.gov

Laspeyres Formula : $$ \frac{ \sum_{i} p_{it}q_{i0}}{ \sum_{i} p_{i0}q_{i0}} $$

Paasche Formula : $$ \frac{ \sum_{i} p_{it}q_{it}}{ \sum_{i} p_{i0}q_{it}} $$

Fisher formula : $$ \sqrt{\frac{ \sum_{i} p_{it}q_{i0}}{ \sum_{i} p_{i0}q_{i0}} * \frac{ \sum_{i} p_{it}q_{it}}{ \sum_{i} p_{i0}q_{it}}} $$

Geometric average, combination of Paasche and Laspeyres

Source: www.stat.go.jp

See also: http://ec.europa.eu/eurostat/cache/metadata/EN/ei_qna_esms.htm#unit_measure1421916244135

# rmarkdown::render(file.path(dbpath, "GitHub", "stan", "vignettes", "stani3_indices.rmd"))


bowerth/stan documentation built on May 13, 2019, 12:38 a.m.