KOF-ch / kofdata

Get Data from the KOF Datenservice API
5 stars 2 forks source link

Question on usage #7

Open christophsax opened 4 years ago

christophsax commented 4 years ago
library(tidyverse)
library(kofdata)
#> Loading required package: jsonlite
#> 
#> Attaching package: 'jsonlite'
#> The following object is masked from 'package:purrr':
#> 
#>     flatten
#> Loading required package: httr
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo

I am interested in ‘Business Situation’, which seems to be public:

as_tibble(list_available_sets())
#> # A tibble: 24 x 3
#>    set_name                   set_description                     is_public
#>    <chr>                      <chr>                               <lgl>    
#>  1 ds_bs_monthly              Business Situation Overview Monthl… TRUE     
#>  2 ds_bs_quarterly            Business Situation Overview Quarte… TRUE     
#>  3 ds_bs_indicator_mixed_freq KOF Geschäftslageindikator          TRUE     
#>  4 ds_kof_consensus_mean_qua… KOF Consensus Mean                  TRUE     
#>  5 ds_kof_consensus_stdev_qu… KOF Consensus Standard Deviation    TRUE     
#>  6 ds_kof_consensus_prob_qua… KOF Consensus Aggregated Probabili… TRUE     
#>  7 ds_globidx.v2017           ""                                  TRUE     
#>  8 ds_kmi_mixed_freq          KOF Main Indicators (KMI)           TRUE     
#>  9 ds_globidx.v2018           KOF Globalization index 2018 vinta… TRUE     
#> 10 ds_globidx_2018_full_fx    KOF Globalization index 2018 vinta… TRUE     
#> # … with 14 more rows

I can list the keys:

x <- list_keys_in_set("ds_kmi_mixed_freq")
x
#>  [1] "kofbarometer"                               
#>  [2] "ch.kof.ie.retro.ch_total.ind.d11"           
#>  [3] "ch.kof.aiu.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [4] "ch.kof.bau.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [5] "ch.kof.dhu.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [6] "ch.kof.dlu.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [7] "ch.kof.fvu.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [8] "ch.kof.ggu.run1.ng08.fx.q_ql_ass_bs.balance"
#>  [9] "ch.kof.ghu.run1.ng08.fx.q_ql_ass_bs.balance"
#> [10] "ch.kof.inu.run1.ng08.fx.q_ql_ass_bs.balance"

But when I want to download it complains:

get_time_series(x)
#> Error in get_time_series(x): The API responded with
#> The following keys do not exist: [ch.kof.aiu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.bau.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.dhu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.dlu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.fvu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.ggu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.ghu.run1.ng08.fx.q_ql_ass_bs.balance, ch.kof.inu.run1.ng08.fx.q_ql_ass_bs.balance]!.
#> Are you sure the requested series are ALL public?

Bonus Question: Is there something like a last update in kofdata, so that I don’t need to download everything every day?

Created on 2019-10-06 by the reprex package (v0.3.0)

mbannert commented 4 years ago

Hmm, I guess available sets is what's outdated and mislead you. I'll crosspost cause swissdata is not public yet:

This should do the job

library(kofdata) tsl <- kofdata::get_dataset("bs_indicator")

basically "Geschäftslage Indikator" is a bit misleading. It's not a single indicator. In fact there is bts_total series that represents and aggregation across sectors and there are public series for every of the 8 sectors KOF surveys.

Use get_dataset instead of get_time_series. This will query the dataset endpoint of the API as opposed to the single ts endpoint.

Edit: Bonus answer.

Yup, we got you covered here. Yet, it's only series based at the moment:

kofdata::get_metadata("ch.kof.bts_total.ng08.fx.q_ql_ass_bs.balance.d11")

But since all of them have the same update / release date you could simply query the top series. However, I see this is last updated, not last release. So it won't be of much help for now since the API won't return stuff before the release date. We are currently working on an overhaul of our publication pipeline. This will be fixed in the process.