API

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

tvonbrasch
Posts: 569
Joined: Fri Apr 15, 2011 5:35 am

API

Postby tvonbrasch » Mon May 02, 2016 1:37 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: API

Postby EViews Gareth » Mon May 02, 2016 1:46 am

Getting the data in in some fashion is easy:

Code: Select all

wfopen(type=text) http://data.ssb.no/api/v0/no/table/07459
Figuring out the formatting of the source data is tricky though. Do they give documentation on the format?

tvonbrasch
Posts: 569
Joined: Fri Apr 15, 2011 5:35 am

Re: API

Postby tvonbrasch » Mon May 02, 2016 5:57 am

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
Attachments
api.PNG
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

Postby EViews Gareth » Mon May 02, 2016 8:28 am

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

Postby EViews Gareth » Mon May 02, 2016 10:15 am

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

Postby tvonbrasch » Tue May 03, 2016 12:14 am

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


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest