Created
July 6, 2016 16:42
-
-
Save jindrichmynarz/9377ec9ab5231fe3ffa461745357f999 to your computer and use it in GitHub Desktop.
Normalization of amounts of money using exchange rates and GDP deflators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PREFIX country: <http://eurostat.linked-statistics.org/dic/geo#> | |
| PREFIX currency: <http://eurostat.linked-statistics.org/dic/currency#> | |
| PREFIX deflator-unit: <http://eurostat.linked-statistics.org/dic/unit#> | |
| PREFIX eurostat: <http://eurostat.linked-statistics.org/property#> | |
| PREFIX na-item: <http://eurostat.linked-statistics.org/dic/na_item#> | |
| PREFIX qb: <http://purl.org/linked-data/cube#> | |
| PREFIX sdmx-code: <http://purl.org/linked-data/sdmx/2009/code#> | |
| PREFIX sdmx-dimension: <http://purl.org/linked-data/sdmx/2009/dimension#> | |
| PREFIX sdmx-measure: <http://purl.org/linked-data/sdmx/2009/measure#> | |
| PREFIX statinfo: <http://eurostat.linked-statistics.org/dic/statinfo#> | |
| PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> | |
| SELECT ?normalizedAmount ?country ?year ?currency | |
| WHERE { | |
| # In-query data about EU-funded datasets | |
| VALUES (?amount ?currency ?year ?country) { | |
| # Greek project from 2013 for 1 million EUR | |
| (1000000 currency:EUR "2013-01-01"^^xsd:date country:EL) | |
| # Romanian project from 2007 for 4 million RON | |
| (4000000 currency:RON "2007-01-01"^^xsd:date country:RO) | |
| } | |
| BIND ("2013-01-01"^^xsd:date AS ?targetYear) | |
| # GDP deflator based in 2010 | |
| BIND (deflator-unit:PD10_NAC AS ?deflatorUnit) | |
| # Source deflator | |
| GRAPH <http://eurostat.linked-statistics.org/data/nama_10_gdp> { | |
| [] a qb:Observation ; | |
| qb:dataSet <http://eurostat.linked-statistics.org/data/nama_10_gdp> ; | |
| eurostat:na_item na-item:B1GQ ; # Gross domestic product at market prices: | |
| sdmx-dimension:freq sdmx-code:freq-A ; # Per year | |
| eurostat:unit ?deflatorUnit ; | |
| eurostat:geo ?country ; | |
| sdmx-dimension:timePeriod ?year ; | |
| sdmx-measure:obsValue ?sourceDeflator . | |
| # Target deflator | |
| [] a qb:Observation ; | |
| qb:dataSet <http://eurostat.linked-statistics.org/data/nama_10_gdp> ; | |
| eurostat:na_item na-item:B1GQ ; | |
| sdmx-dimension:freq sdmx-code:freq-A ; | |
| eurostat:unit ?deflatorUnit ; | |
| eurostat:geo ?country ; | |
| sdmx-dimension:timePeriod ?targetYear ; | |
| sdmx-measure:obsValue ?targetDeflator . | |
| } | |
| # Exchange rate | |
| { | |
| GRAPH <http://eurostat.linked-statistics.org/data/tec00033> { | |
| [] a qb:Observation ; | |
| qb:dataSet <http://eurostat.linked-statistics.org/data/tec00033> ; | |
| eurostat:statinfo statinfo:AVG ; # Average | |
| sdmx-dimension:freq sdmx-code:freq-A ; | |
| eurostat:currency ?currency ; | |
| sdmx-dimension:timePeriod ?targetYear ; | |
| sdmx-measure:obsValue ?exchangeRate . | |
| } | |
| } UNION { | |
| # If the currency is EUR, then its exchange rate to EUR is 1. | |
| VALUES (?currency ?exchangeRate) { | |
| (currency:EUR 1) | |
| } | |
| } | |
| BIND ((xsd:decimal(?targetDeflator) * ?amount) | |
| / | |
| (xsd:decimal(?sourceDeflator) * xsd:decimal(?exchangeRate)) AS ?normalizedAmount) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment