Hi
Statistics Norway has now made available all its data through API. They have made examples of how to download data directly into programs such as
SAS:
proc http in=in out=out url="http://data.ssb.no/api/v0/no/table/07459"
method="post";
run;
and pyjstat
from pyjstat import pyjstat
import requests
from collections import OrderedDict
EXAMPLE_URL = 'http://data.ssb.no/api/v0/no/table/03024'
payload = {"query": [{"code": "VareGrupper2", "selection": {"filter": "item", "values": ["01", "02"] } }, {"code": "ContentsCode", "selection": {"filter": "item", "values": ["Vekt", "Kilopris"] } }, {"code": "Tid", "selection": {"filter": "top", "values": ["53"] } } ], "response": {"format": "json-stat"} }
data = requests.post(EXAMPLE_URL, json = payload)
results = pyjstat.from_json_stat(data.json(object_pairs_hook=OrderedDict))
# results[0].to_csv("03024.csv", sep=';', encoding='utf-8') # lagre .csv
print(results)
How can I import data directly into Eviews in a similar manner?
Thomas
API
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: API
Getting the data in in some fashion is easy:
Figuring out the formatting of the source data is tricky though. Do they give documentation on the format?
Code: Select all
wfopen(type=text) http://data.ssb.no/api/v0/no/table/07459
-
tvonbrasch
- Posts: 569
- Joined: Fri Apr 15, 2011 5:35 am
Re: API
Hi
thanks for this.
To me it looks like that Eviews then imports the query infomration (see attached picture).
If you go into the API console http://data.ssb.no/api/v0/no/console and start to enter "07459:" you can choose "07459: Folkemengde, etter kjønn og ettårig alder. 1. januar (K) 1986 - 2016". If you then press "Kjør" (Run) you get the values of the different statistics in the json-stat format. this can also be saved in an Excel file. what I was hoping is that these data can be directly imported into Eviews, so that Eviews first queries the SSB database and then import these data into Eviews.
Is this possible?
Thomas
thanks for this.
To me it looks like that Eviews then imports the query infomration (see attached picture).
If you go into the API console http://data.ssb.no/api/v0/no/console and start to enter "07459:" you can choose "07459: Folkemengde, etter kjønn og ettårig alder. 1. januar (K) 1986 - 2016". If you then press "Kjør" (Run) you get the values of the different statistics in the json-stat format. this can also be saved in an Excel file. what I was hoping is that these data can be directly imported into Eviews, so that Eviews first queries the SSB database and then import these data into Eviews.
Is this possible?
Thomas
- Attachments
-
- api.PNG (37.47 KiB) Viewed 6916 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: API
Can the API be used to retrieve in CSV rather than JSON? (My Google-Translated browse around the site found the answer to be inconclusive).
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: API
You can do this:
Code: Select all
wfopen(t=text) http://data.ssb.no/api/v0/dataset/85430.csv?lang=en
-
tvonbrasch
- Posts: 569
- Joined: Fri Apr 15, 2011 5:35 am
Re: API
Hi Gareth!
Thanks for looking into this!
The command wfopen(t=text) http://data.ssb.no/api/v0/dataset/85430.csv?lang=en works fine.
However, the reason that it works is because SSB published only a limited set of variables on the cite http://data.ssb.no/api/ that could be directly downloaded as .csv files. (the table 85430 is one of them)
The full databank must be accessed through an API console: http://data.ssb.no/api/v0/no/console
and then query the data. In the console the data is then retrieved and can be stored as a CSV file or in JSON format (im not sure what that is).
I noticed that other software could query and download data directly into the program, which would be extremely convenient. And I was told that many providers of statistics are using the same type of api/json for computers to access data directly. would this be possible in Eviews? If not, this is also on my wishlist for Eviews 10.
Thomas
Thanks for looking into this!
The command wfopen(t=text) http://data.ssb.no/api/v0/dataset/85430.csv?lang=en works fine.
However, the reason that it works is because SSB published only a limited set of variables on the cite http://data.ssb.no/api/ that could be directly downloaded as .csv files. (the table 85430 is one of them)
The full databank must be accessed through an API console: http://data.ssb.no/api/v0/no/console
and then query the data. In the console the data is then retrieved and can be stored as a CSV file or in JSON format (im not sure what that is).
I noticed that other software could query and download data directly into the program, which would be extremely convenient. And I was told that many providers of statistics are using the same type of api/json for computers to access data directly. would this be possible in Eviews? If not, this is also on my wishlist for Eviews 10.
Thomas
Who is online
Users browsing this forum: No registered users and 1 guest
