1.0: 27/2/2019: Worked against excel and csv files on disk
1.1: July - September: Moved data storage to Zeus and revised figures to harmonize with AEA and PEFA
2.0: December 2019
2.01: September 2020.
2.1: December 2020 - January 2021.
2.3: February 2023 - May 2023.
2.3.1: July 2023.
3.0.0: February 2024: Re-coding
EW-MFA Tables B, C, D and E contain information on how much goods are imported and exported. Initial questionnaires had separation between trade from outside the EU or from within the EU. This part was phased out in 2022.
These data for this table comes first and foremost from the trade database. Eurostat provides annex information that assists in mapping customs numbers against weight. Part of the preparation for the processing here is therefore to review tha mapping from the toll numbers to MFA classes.
The following processes are available/run
sub_proc | skjal_nafn | skjal_fannst |
---|---|---|
table_be_biti_1 | MFA-Table_B.biti.1.rmd | TRUE |
table_be_biti_2 | MFA-Table_B.biti.2.rmd | TRUE |
table_be_biti_3 | MFA-Table_B.biti.3.rmd | TRUE |
table_be_biti_4 | MFA-Table_B.biti.4.rmd | TRUE |
table_be_biti_5 | MFA-Table_B.biti.5.rmd | TRUE |
table_be_store | MFA-Table_B.db_storage.rmd | TRUE |
This project will therefore be solved by:
The basic collection for Table B and Table D are in a database view named mfa.sub_gogn_verslun. The query in this view is:
select
g.land_cd,
g.ar,
g.tlsk,
g.eink,
g.magn_kg/1000 gildi,
'TONN' eining,
tx.mfa_cd,
tx.ms_id,
tx.titill
from vrsl.v_gogn_verslun_ar g
left join mfa.verslun_tlsk_mfa_varpanir_fra tx
on tx.tlsk = g.tlsk and g.ar between year(tx.gildir_fra) AND year(tx.gildir_til)
where the view vrsl.v_gogn_verslun_ar is a summary view of the vrsl.gogn_verslun data and mfa.verslun_tlsk_mfa_varpanir_fra is a table that contains the mapping between tlsk and mfa_cd.
The trade database (verslun) is inconveniently structured to run timeseries queries, since each year trade is stored in separate tables. The trade data is also somewhat cumbersome to work with, since products are imported and exported under a toll-number (tlsk), which is close to (but not quite) harmonized with the common nomenclature (CN) system. The table vrsl.gogn_verslun is therefore processed snapshot from the trade database, where I have aggregated lines to months (from days) and unified the tables from 1990 to the current year into a single table. The snapshot is updated sporatically (every year), except for the newest year, which is updated each month. The annual update updates any changes and changes to previous years that the trade-db team inserts into the database. This can change the outcome in the EW-MFA compilation.
The mapping between tlsk numbers to mfa categories is also reviewed each year. This review sometimes exposes mistakes, which can change the outcome in the EW-MFA compilation. The data is therefore somewhat “volatile”. A comprehensive view of the TLSK-MFA mapping is also done when a new toll-number registry is issued.
This process - Collects data from the database - Maps tlsk to mfa_cd and ms_id. This step can be fragile, since the tlsk values can change and some ar re-used for different material between years. The most common change is, however, spelling and punctuation corrections, which should not change the mfa_cd mapping - 09-2021: New toll numbers introduced - Joins the data into a single table. - Does some rudimentary data-checks
Here I check if the quantities in the vrsl.gogn_verslun data are identical to the values in mfa.sub_gogn_verslun. If I have “orphan” toll numbers, viz toll numbers that have no mapping to mfa classes (e.g. when I get new tlsk numbers into the database), the quantity in the mfa.sub_gogn_verslun will be lower than in the vrsl.gogn_verslun.
## Quantities are identical, all toll numbers are mapped
If this error comes up I need to review each year where the error appears and find what toll-numbers are orphaned.
The data from the mfa.sub_gogn_verslun view is stored in a parquet file on the local drive in order to speed up processing. The file is not automatically deleted if it is outdated and may need to be manually removed if there are changes to the mapping.
ar | tlsk | eink | mfa_cd | ms_id | eining | gildi |
---|---|---|---|---|---|---|
2024 | 97040000 | X | MF5 | SM_FIN | TONN | 0.048 |
2024 | 97051010 | M | MF5 | SM_FIN | TONN | 0.005 |
2024 | 97052910 | M | MF5 | SM_FIN | TONN | 0.008 |
2024 | 97052910 | X | MF5 | SM_FIN | TONN | 0.142 |
2024 | 97053900 | M | MF5 | SM_FIN | TONN | 0.019 |
2024 | 97069040 | M | MF5 | SM_FIN | TONN | 0.037 |
Key dimensions in the data
All values shouild be in tonnes. The data is a left-join between tlsk and mapping. Some mfa_cd may therefore be NULL. This is acceptable for some tollnumbers, mainly those that start on 999, since this is an unspecified or unknown product. Tollstjóri has been notified that using this number is not an acceptable practice, but some values remain
Some quantities are imported and exported in large quantities. Errors in values here can affect the EW-MFA outcome. Here I choose MFA classes that exceed 100 kt import or export per year
The largest value is for MF227, which is aluminum. The imported material is actually aluminum oxide, where the exported material is mostly pure aluminum (Al) or aluminum alloys. The weight fraction of aluminum in pure aluminum oxide is 52.926%, which means that if Al2O3 were the only material in MF227 import and pure Al is the only material in MF227, the ratio of export to import should be close to this value.
pure exported aluminum has the toll-number 76011000, whereas aluminum oxide has the toll-number 28182000. This allows me to calculate slightly “cleaner” ratio.
Yield values > 100 can arise when the factories have stocked up manufactured goods (when the market is slow) and export larger quantity than would be expected from the imported raw materials. The yield has been decreasing in the recent years, as the manufacturers have started producing aluminum alloys and shaped aluminum products (rods, platec etc.) rathern than just pure Aluminum blocks.
Other material classes that are noticable in import are the fuel classes MF4231, MF4232 og MF4233. The other major export (MF141) is fish.
I am not too concerned if there are some unmapped toll numbers, as long as the quantity does not go much over 1000 tonnes. The key orphan tollnumbers are 988xxx and 999xx.
The structure of the data in the trade database is slightly different than the structure of corrections and additions that are produced in later stages of the assembly, although the values are eventually all aggregated down to the same form. Tables B and D also have sub-parts which consider the state of manufacturing. This changes the form needed for the assembly data.
## Length Class Mode
## table_b_verslun 10 tbl_df list
## table_d_verslun 10 tbl_df list
## MFA-Table_B.biti.1.rmd completed
Some corrections need to be made to trade figures, where import and export are not directly mapped to material consumption, or when more detailed information is needed for the material category. There are some minor adjustments that may be nescessary for the biomatter category (not everything that is labeled as grain is grain etc.). The largest adjustments are, however for fuels, or
Here, each category needs to be examined individually in order to assess whether figures from the Energy Authority (Orkustofnun; OS) or from the Air Emission Account (AEA) accounting can be used to retrieve more accurate information. The method here is to:
The processing uses the following datasources and steps:
Diesel and gasoline are used in road transport. Gasoline is not used for any purpose other than for cars, while diesel oil is imported for ships, for heating, for energy production and for road transport.
Here are three things I can do:
Results from method 1: I had a hard time in ballancing the correct amount between classes without getting a minus count in class MF421 for a few years, especially when looking at the amount exported. This happens since the fuel type in OS and AEA data is not directly identifiable from the TLSK number.
Method 2: Here I first try to put all the fuel that is obviously for ships and road transport into MF42, which is a category that should not be used otherwise. This keeps the MF421 “clean” until I put the ball from the MF42 back in there. This can be done in one final step after road transport and shipping are clear. Vinnslan er því efirfarandi:
January 2021 Went back to recording all fuel to MF421 and set up the processing as a debit account from MF421 to MF4231
In the AEA accounting, I have made calculations on the fuel consumption of foreign tourists since 1995. These figures are based on the OS figures This means that I basically just need to
June 2023 Updated the mapping table for the customs files, then something went wrong and this run stopped working. I was also just starting to see some suspicious numbers in the MFA accounts for the MF.4.3 class that I got comments on.
July 2023 The method I was using ended up deducting too much from the MF421 category at the end, so the total for 2021 and the previous few years was negative. This was an error I missed in the return documents in Table_D:MF421!! ANNOYING
The following toll categories are taken as potentially used in road transport:
tlsk | kandidat.mf | vörpun | fuel_cd |
---|---|---|---|
27100019 | MF4231 | annað bensín -> samgöngur | BENSIN |
27101129 | MF4231 | annað bensín -> samgöngur | BENSIN |
27101229 | MF4231 | annað bensín -> samgöngur | BENSIN |
27102029 | MF4231 | annað bensín -> samgöngur | BENSIN |
27101121 | MF4231 | Blýlaust bensín -> samgöngur | BENSIN |
27101221 | MF4231 | Blýlaust bensín -> samgöngur | BENSIN |
27100012 | MF4231 | Blýlaust bensín -> samgöngur | BENSIN |
27102021 | MF4231 | Blýlaust bensín með <30% lífdíselolíu-> samgöngur | BENSIN |
27100060 | MF4231 | Gasolíur -> samgöngur | DIESEL |
27101930 | MF4231 | Gasolíur -> samgöngur | DIESEL |
27102065 | MF4231 | Gasolíur með <30% af lífdíselolíu -> samgöngur | DIESEL |
Fuel in the trade database that may be related to road transport is stored in category MF421. The table above shows mapping from of this fuel into the candidate MF category. These values will then be subtracted from the quantity in MF421.
ar | mfa_cd | 27100012 | 27100019 | 27100060 | 27101121 | 27101129 | 27101930 | 27101221 | 27101229 | 27102021 | 27102029 | 27102065 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1990 | MF421 | 46134.50 | 81189.647 | 335775.7 | NA | NA | NA | NA | NA | NA | NA | NA |
1991 | MF421 | 78204.33 | 53827.037 | 247711.4 | NA | NA | NA | NA | NA | NA | NA | NA |
1992 | MF421 | 88894.31 | 52212.869 | 310076.6 | NA | NA | NA | NA | NA | NA | NA | NA |
1993 | MF421 | 70688.35 | 48486.839 | 283007.3 | NA | NA | NA | NA | NA | NA | NA | NA |
1994 | MF421 | 121002.62 | 20189.491 | 294202.3 | NA | NA | NA | NA | NA | NA | NA | NA |
1995 | MF421 | 114670.24 | 16212.763 | 296041.5 | NA | NA | NA | NA | NA | NA | NA | NA |
1996 | MF421 | 140630.14 | 6825.718 | 355160.2 | NA | NA | NA | NA | NA | NA | NA | NA |
1997 | MF421 | 132528.29 | NA | 336953.8 | NA | NA | NA | NA | NA | NA | NA | NA |
1998 | MF421 | 141033.61 | NA | 371387.1 | NA | NA | NA | NA | NA | NA | NA | NA |
1999 | MF421 | 147748.83 | NA | 402246.4 | NA | NA | NA | NA | NA | NA | NA | NA |
2000 | MF421 | 152474.93 | 0.740 | 443687.1 | NA | NA | NA | NA | NA | NA | NA | NA |
2001 | MF421 | 137914.92 | 0.623 | 375114.3 | NA | NA | NA | NA | NA | NA | NA | NA |
2002 | MF421 | NA | NA | NA | 145010.5 | 3.404 | 402834.07 | NA | NA | NA | NA | NA |
2003 | MF421 | NA | NA | NA | 139395.2 | 5.365 | 386246.32 | NA | NA | NA | NA | NA |
2004 | MF421 | NA | NA | NA | 151987.5 | 101.662 | 479476.76 | NA | NA | NA | NA | NA |
2005 | MF421 | NA | NA | NA | 163308.5 | 3.351 | 423218.28 | NA | NA | NA | NA | NA |
2006 | MF421 | NA | NA | NA | 165290.4 | 39.901 | 450527.08 | NA | NA | NA | NA | NA |
2007 | MF421 | NA | NA | NA | 156543.8 | 17.163 | 420917.29 | NA | NA | NA | NA | NA |
2008 | MF421 | NA | NA | NA | 151944.5 | 4.953 | 390843.35 | NA | NA | NA | NA | NA |
2009 | MF421 | NA | NA | NA | 156515.8 | 9.170 | 375021.19 | NA | NA | NA | NA | NA |
2010 | MF421 | NA | NA | NA | 143990.5 | 1.781 | 321326.61 | NA | NA | NA | NA | NA |
2011 | MF421 | NA | NA | NA | 144549.6 | 2.417 | 333872.09 | NA | NA | NA | NA | NA |
2012 | MF421 | NA | NA | NA | NA | NA | 322111.21 | 137746.56 | 0.418 | 228.765 | NA | NA |
2013 | MF421 | NA | NA | NA | NA | NA | 316212.00 | 132823.19 | 2.928 | NA | 2.352 | NA |
2014 | MF421 | NA | NA | NA | NA | NA | 341791.59 | 133080.52 | 2.288 | NA | 0.034 | NA |
2015 | MF421 | NA | NA | NA | NA | NA | 404858.88 | 139315.99 | 2.734 | NA | 0.016 | NA |
2016 | MF421 | NA | NA | NA | NA | NA | 397962.28 | 136733.37 | 0.383 | 0.001 | 0.090 | NA |
2017 | MF421 | NA | NA | NA | NA | NA | 396555.05 | 139090.39 | 3.605 | NA | NA | NA |
2018 | MF421 | NA | NA | NA | NA | NA | 441458.24 | 134806.54 | 1.888 | 0.015 | 0.064 | NA |
2019 | MF421 | NA | NA | NA | NA | NA | 467563.27 | 123742.90 | 1.078 | NA | 1.222 | NA |
2020 | MF421 | NA | NA | NA | NA | NA | 448057.34 | 94514.14 | 7083.174 | NA | 0.081 | NA |
2021 | MF421 | NA | NA | NA | NA | NA | 507799.21 | 83544.68 | 20736.121 | NA | 0.148 | 53.576 |
2022 | MF421 | NA | NA | NA | NA | NA | 623066.96 | 101116.72 | 14158.969 | NA | 0.006 | NA |
2023 | MF421 | NA | NA | NA | NA | NA | 617449.37 | 109751.29 | 11953.068 | NA | NA | NA |
2024 | MF421 | NA | NA | NA | NA | NA | 93213.85 | 15160.01 | 645.763 | NA | NA | NA |
The function Table_BE.kandiat_eldsneyti_til_samgangna_ur_mf421.fGet(df.verslun) is a wrapper that does the following
This returns the table with the following columns
In fact, all exports of gasoline could be ignored here, as this is an insignificant amount. There is some export of diesel oil, but this export is primarily to ships and only a fraction to foreign tourists.
Here we are missing fuel consumption recorded in the AEA accounts and in the data from the Energy Agency concerning fuel from the pump. This processing has two functions.
The outcome here is:
These numbers from the AEA are the numbers I’m going to put into the MF4231 next. Then I subtract the same amount from the MF421 amount
The most important thing here is that the amount of fuel recorded in the AEA/OS numbers is not higher than the amount recorded in the import numbers. Normal behavior is:
5000 tons is about 4% of the imported amount. Fluctuations within these limits are therefore acceptable. It just annoys me that the difference in gas can be as much as 16% between what I calculate in AEA and here for the most recent years, but in these years there is always a risk that I overestimate the amount.
Here again it is obvious that the exported quantity is much more than the imported quantity. The exported quantity here is sales to foreign tourists, while gasoline is not exported in the trade data except in exceptional cases.
Here it would be tempting to coldly subtract the gasoline imports from the MF42 category since the AEA/OS data gives the correct figures.
The use of Diesel is clearly negligible compared to the imported amount
Exports here are again primarily to foreign tourists. However, according to trade data, exports are very high to fishing vessels and to some extent to cruise ships and cruise ships.
In the previous process, there was a lot of fuss around the division of fuel between EU and NON.EU countries, where I used a number of tourists to divide the fuel. Since this processing is not necessary, the processing is considerably simplified.
So I basically just need to take the amount I’ve settled on from the AEA data and subtract the same amount from the store numbers in the MF421 category. Since the MFA processing does not look at duty categories, I am pretty sure that this amount in the deduction never zeros out the amount in the MF421.
2023/07/14: I have to be careful NOT to blindly withdraw the export of gasoline and Diesel oil from MF421!! I can deduct Gasoline and Diesel from the import figures (M), but I should NOT deduct the Gasoline and Diesel figures from the exports in the customs data as these exports are not customs registered.
I’m going to add an amount to the MF4231 and subtract the same amount from the MF421. If I have the wrong module on the MF4231 data, everything goes to shit. Here it is good to check again whether the amount I have in the supplement, e.g. for petrol, is still similar to what is in the retail figures.
Here, I prefer to check whether the amount I am going to enter is somewhat 1000 times more or less than the amount that is in the store numbers (i.e. more than 1000% difference)
## This error was not found
The process here is finding values to subtract from MF421. The sales to tourists is, however, not quantity that is
mfa_cd | eink | neg | gildi |
---|---|---|---|
MF421 | M | TRUE | -7800.1160 |
MF4231 | M | FALSE | 7800.1160 |
MF4231 | X | FALSE | 325.3631 |
The values in the eink=‘M’ should cancel out, but the eink=‘X’ should not.
In update 05-2023, I decided to automatically insert the data into the bases regardless of what is already there, since it was otherwise such a long process. The processing here saves all data into its own sub_gogn table. In other parts, I have put all the numbers I generate into the same data table so as not to end up with a myriad of tables in the database. However, this will be an update that I will do later in Table B
The following sql processin is then done
truncate table mfa.sub_gogn_vegasamgongur
insert into mfa.sub_gogn_vegasamgongur(
eu28, ar, mfa_cd, ms_id,
eink, fuel_cd, gildi,
vinnsla, reiknad_dags)
select
eu28, ar, mfa_cd, ms_id,
eink, fuel_cd, gildi,
vinnsla, reiknad_dags
from tmp_sub_gogn_vegasamgongur
drop table tmp_sub_gogn_vegasamgongur
The same data as is stored in the database is also put into the data assembly for later checks and validations
## Length Class Mode
## table_b_verslun 10 tbl_df list
## table_d_verslun 10 tbl_df list
## table_b_vegasamgongur 10 tbl_df list
## table_d_vegasamgongur 10 tbl_df list
## End of MFA-Table_B.biti.2.rmd
Aircraft fuel is recorded in the commercial data much more precisely than for other fuels. There is therefore no need to go to the AEA accounting, except in order to find the fuel purchased for the, as the AEA accounting has a longer time series for fuel bought abroad by Icelandic aircraft than is in the commercial base
In older processing, all fuel was first classified as MF421. Then the “potential” mapping of the fuel was retrieved in the function fGet.fuel_map() and the share of fuel was subtracted from the quantity in MF421. This method is still used for marine fuels and for road transport fuels that are not obviously used for road transport (e.g. Gas oils). Fuel for aviation is, however, quite easily identifiable in the description of the customs category.
tlsk | mfa_cd | ms_id | titill |
---|---|---|---|
27101110 | MF4233 | SM_FIN | Flugvélabensín |
27100011 | MF4233 | SM_FIN | Flugvélabensín |
27100020 | MF4233 | SM_FIN | Bensínkennt þotueldsneyti |
27100042 | MF4233 | SM_FIN | Þotueldsneyti |
27101912 | MF4233 | SM_FIN | Þotueldsneyti (jet fuel) |
27101918 | MF4233 | SM_FIN | Eldsneyti keypt erlendis af íslenskum flugvélum |
27102010 | MF4233 | SM_FIN | Flugvélabensín með <30% af lífdíselolíu |
27102030 | MF4233 | SM_FIN | Bensínkennt þotueldsneyti með <30% af lífdíselolíu |
27102052 | MF4233 | SM_FIN | Þotueldsneyti með <30% af lífdíselolíu |
27101210 | MF4233 | SM_FIN | Flugvélabensín |
27101230 | MF4233 | SM_FIN | Bensínkennt þotueldsneyti |
These customs categories are already marked in the trade data, so I don’t need to process them further, unless I only need data (older time series)
A review of the quantities of fuel registered in the trade database reveals several interesting aspects
The data from the Energy Agency has an older classification for fuel bought abroad and fuel sold to foreign companies. This data is retrieved by the function Table_BE.os_flug.x_eldri().
ar | eink | gildi | vinnsla |
---|---|---|---|
2013 | M | 188059.2 | Table_BE.os_flug.x_eldri |
2014 | M | 232123.8 | Table_BE.os_flug.x_eldri |
2015 | M | 239036.6 | Table_BE.os_flug.x_eldri |
2016 | M | 332951.3 | Table_BE.os_flug.x_eldri |
2017 | M | 358592.5 | Table_BE.os_flug.x_eldri |
2018 | M | 399038.1 | Table_BE.os_flug.x_eldri |
In the AEA accounting, the turnover figures of airlines were also examined in order to prepare data for the purchase of errands. This data can be retrieved by running the following sql script:
select
f.ar,
'M' eink,
sum(f.eydsla)/1000 gildi_tonn
from aea.gogn_mapped_eldsneyti_flug f
where f.nace_cd in ('BRIDGE_AIR_TRANSPORT', 'BRIDGE_NR_AIR_TRANSPORT')
group by f.ar, f.nace_cd
These numbers are retrieved in the function Table_BE.verslun_gogn.aea_abroad(this.connection)
ar | eink | gildi | vinnsla |
---|---|---|---|
2023 | M | 71283.743 | Table_BE.verslun_gogn.aea_abroad |
2023 | X | 7165.432 | Table_BE.verslun_gogn.aea_abroad |
2022 | M | 419937.082 | Table_BE.verslun_gogn.aea_abroad |
2022 | X | 29202.423 | Table_BE.verslun_gogn.aea_abroad |
2021 | M | 146888.836 | Table_BE.verslun_gogn.aea_abroad |
2021 | X | 28433.154 | Table_BE.verslun_gogn.aea_abroad |
The AEA and OS numbers can be combined to select a full set. This processing is in the function Table_BE.eldsneyti_flug.os_aea(aea, os)
These figures need to be added to the figures already obtained from the trade data. This means that older time series will be slightly confusing, but this can be improved by inserting correction entries in the base to subtract or add fuel.
This function also takes care not to return data that has already entered the database.
Here you need to look specifically at
This data has a certain irregularity in it, which is normal, but must be corrected at the end of the processing. The final step is to select data from this collection that has not entered the database.
eink | mfa_cd | neg | gildi |
---|---|---|---|
M | MF4233 | FALSE | 4332311 |
X | MF4233 | FALSE | 437871 |
In update 05-2023, I decided to automatically insert numbers into the base. This just speeds up the processing of the entire run and I no longer have to go in and run the base sql scripts manually.
Health check of the data that was entered. Only data that is not already in the store numbers is being entered here. This means that the data does not cover the current year, this is normal.
ar | dalkar | radir | M | X |
---|---|---|---|---|
1990 | 10 | 1 | 155.7545 | 37.654 |
1991 | 10 | 1 | 141.3288 | NA |
1992 | 10 | 1 | 152.3553 | 31.061 |
1993 | 10 | 1 | 127.4286 | 30.058 |
1994 | 10 | 1 | 146.1094 | 32.066 |
1995 | 10 | 1 | 104.9237 | 37.968 |
1996 | 10 | 1 | 151.1956 | 40.081 |
1997 | 10 | 1 | 169.1282 | 41.134 |
1998 | 10 | 1 | 178.7968 | 41.543 |
1999 | 10 | 1 | 216.3527 | 43.632 |
2000 | 10 | 1 | 245.8884 | 44.237 |
2001 | 10 | 1 | 201.2684 | 30.023 |
2002 | 10 | 1 | 180.4010 | 28.414 |
2003 | 10 | 1 | 216.1555 | NA |
2004 | 10 | 1 | 222.9716 | NA |
2005 | 10 | 1 | 242.4705 | NA |
2006 | 10 | 1 | 249.0053 | NA |
2007 | 10 | 1 | 234.3578 | NA |
2008 | 10 | 1 | 217.4630 | NA |
2009 | 10 | 1 | 158.9764 | NA |
2010 | 10 | 1 | 192.4320 | NA |
2011 | 10 | 1 | 197.3506 | NA |
2012 | 10 | 1 | 230.1966 | NA |
Data is expected to be NULL for X after 2003. After this the following sql processes are executed
truncate table mfa.sub_gogn_flugsamgongur
insert into mfa.sub_gogn_flugsamgongur(
eu28, ar, mfa_cd, ms_id,
eink, gildi, eining, vinnsla,
reiknad_dags)
select
eu28, ar, mfa_cd, ms_id,
eink, gildi, eining, vinnsla,
reiknad_dags
from tmp_sub_gogn_flugsamgongur
drop table tmp_sub_gogn_flugsamgongur
The same data as is stored in the database is also put into the data assembly for later checks and validations
## Length Class Mode
## table_b_verslun 10 tbl_df list
## table_d_verslun 10 tbl_df list
## table_b_vegasamgongur 10 tbl_df list
## table_d_vegasamgongur 10 tbl_df list
## table_b_flug 10 tbl_df list
## table_d_flug 10 tbl_df list
## MFA-Table_B.biti.3.rmd completed
Here we find ourselves in a bit of a gap between the fuel sold to ships and the fuel imported to Iceland. Some of the imported black oil is used for domestic heating, and a large part of the imported diesel oil is used for road transport. There is also a big discrepancy in what the Norwegian Energy Agency says about the use of materials by “Other ships”. After 2019, almost no black oil has been used by Icelandic ships, and little or nothing has been imported. The 2022 tariff redefinition could even eliminate “fuel oil” from the list.
After a lot of trouble I decided to use data from aea processing to find these numbers and not have a lot of design in the EW-MFA processing in this
The trading data is set up so that all oil content (even fuel bought abroad) is put into MF421. Customs categories that are used in maritime transport are marked separately in this process.
fuel_cd | tlsk | kandidat.mf | vörpun |
---|---|---|---|
27101948 | 27101948 | MF4232 | Eldsneyti keypt erlendis af íslenskum skipum -> sjósamgöngur |
RFO | 27101940 | MF4232 | Brennsluolíur -> Sjósamgöngur |
RFO | 27100070 | MF4232 | Brennsluolíur -> Sjósamgöngur |
RFO | 27102070 | MF4232 | Brennsluolíur með <30% af lífdíselolíu-> Sjósamgöngur |
DIESEL | 27100060 | MF4232 | Gasolíur -> sjósamgöngur |
DIESEL | 27101930 | MF4232 | Gasolíur -> sjósamgöngur |
DIESEL | 27102065 | MF4232 | Gasolíur -> sjósamgöngur |
This mapping is used to pick up fuels from the trade data.
It is worth noting here that exports only go back to 1998 or so. Exports are also insignificant until 2003. However, I know that foreign vessels have been taking some oil back until 1995. This means that I cannot guarantee that the use in MF4232 is not greater than the exports recorded in MF421. I can be pretty sure that imports into MF421 are always greater than usage into MF4232, as long as I leave out tariff class 27101948 and don’t deduct foreign bought fuel coming into MF4232 from the amount in MF421
Here I would like to use a similar idea as I did in road transport, i.e. Use AEA, NIR and OS to find the amount of fuel based on emission/use. This is less accurate, but easier to process than what I’ve done using oil numbers directly. With this I can use the design work I do in AEA and coordinate the result. The processing is therefore:
The process is then:
I then compare these numbers with imports in the trade data (which is automatically recorded in MF421). Then I need to prepare a subtractor for the chart to move the oil from MF421 to MF4232. This is quite obvious for tariff class 27101948, but is not obvious for other classes. Here I have to be careful not to end up in the red.
Class MF4232 is only for water transport, so I can get rid of “BRIDGE_FISHING” and “A03” from the data. I can also get rid of “BIO” fuel. NR_WATER_TRANSPORT is fuel exported. So I only have fuel that is for H50 and BRIDGE_NR_WATER_TRANSPORT
ar | fuel_cd | nace_cd | is_bio | magn | eining | lind |
---|---|---|---|---|---|---|
2020 | DIESEL | BRIDGE_NR_WATER_TRANSPORT | FALSE | 1105.0000 | tonn | os_fuel.skip(Dísilolía, erlend fiskiskip) |
2020 | DIESEL | H50 | FALSE | 2962.0000 | tonn | os_fuel.skip(Dísilolía, önnur skip, innlend notkun) |
2020 | MGO | BRIDGE_NR_WATER_TRANSPORT | FALSE | 7512.6870 | tonn | os_fuel.skip(Flotadísilolía, erlend fiskiskip) |
2020 | MGO | BRIDGE_NR_WATER_TRANSPORT | FALSE | 15437.0000 | tonn | os_fuel.skip(Skipagasolía, erlend fiskiskip) |
2020 | MGO | BRIDGE_NR_WATER_TRANSPORT | FALSE | 22519.7350 | tonn | tollagogn.eldsneyti_utflutt.brige_nr |
2020 | MGO | BRIDGE_WATER_TRANSPORT | FALSE | 17320.3360 | tonn | os_fuel.skip.eftir_ad_leidretta(Flotadísilolía, önnur skip, millilandanotkun) |
2020 | MGO | BRIDGE_WATER_TRANSPORT | FALSE | 6955.0000 | tonn | os_fuel.skip.eftir_ad_leidretta(Skipagasolía, önnur skip, millilandanotkun) |
2020 | MGO | BRIDGE_WATER_TRANSPORT | FALSE | 63336.9735 | tonn | tollagogn.eldsneyti_keypt_erlendis.bridge_mgo(DK) |
2020 | MGO | BRIDGE_WATER_TRANSPORT | FALSE | 906.0705 | tonn | tollagogn.eldsneyti_keypt_erlendis.bridge_mgo(NL) |
2020 | MGO | BRIDGE_WATER_TRANSPORT | FALSE | -22519.7350 | tonn | tollagogn.eldsneyti_utflutt.bridge_leidretting |
2020 | MGO | H50 | FALSE | 113.6990 | tonn | os_fuel.skip(Flotadísilolía, önnur skip, innlend notkun) |
2020 | MGO | H50 | FALSE | 4758.0000 | tonn | os_fuel.skip(Skipagasolía, önnur skip, innlend notkun) |
2020 | MGO | H50 | FALSE | 17320.3360 | tonn | os_fuel.skip.eftir_ad_leidretta(Flotadísilolía, önnur skip, millilandanotkun) |
2020 | MGO | H50 | FALSE | 6955.0000 | tonn | os_fuel.skip.eftir_ad_leidretta(Skipagasolía, önnur skip, millilandanotkun) |
2020 | MGO | H50 | FALSE | 63336.9735 | tonn | tollagogn.eldsneyti_keypt_erlendis.nace_mgo(DK) |
2020 | MGO | H50 | FALSE | 906.0705 | tonn | tollagogn.eldsneyti_keypt_erlendis.nace_mgo(NL) |
2020 | MGO | H50 | FALSE | -22519.7350 | tonn | tollagogn.eldsneyti_utflutt.h50_leidretting |
2020 | RFO | BRIDGE_WATER_TRANSPORT | FALSE | 54.2970 | tonn | os_fuel.skip.eftir_ad_leidretta(Likan label= Áælað m.v. innflutning) |
2020 | RFO | BRIDGE_WATER_TRANSPORT | FALSE | 63336.9735 | tonn | tollagogn.eldsneyti_keypt_erlendis.bridge_mgo(DK) |
2020 | RFO | BRIDGE_WATER_TRANSPORT | FALSE | 906.0705 | tonn | tollagogn.eldsneyti_keypt_erlendis.bridge_mgo(NL) |
2020 | RFO | H50 | FALSE | 54.2970 | tonn | os_fuel.skip.eftir_ad_leidretta(Likan label= Áælað m.v. innflutning) |
2020 | RFO | H50 | FALSE | 63336.9735 | tonn | tollagogn.eldsneyti_keypt_erlendis.nace_rfo(DK) |
2020 | RFO | H50 | FALSE | 906.0705 | tonn | tollagogn.eldsneyti_keypt_erlendis.nace_rfo(NL) |
Inspection shows that BRIDGE_WATER_TRANSPORT are mostly the same numbers as in the H50 category (e.g. for RFO). I can therefore get rid of this NACE category. I can also very easily set up import and export labels on the data. However, I do not have a good description of which customs categories are behind, but I can assume that all this fuel is already marked with MF category MF421 and with candidate category MF4323 (according to collection above)
Here I also select NACE categories H50 and BRIDGE_NR_WATER_TRANSPORT, as these should be the same or similar numbers.
ar | efni_cd | nace_cd | titill_is | gildi |
---|---|---|---|---|
2020 | CO2 | H50 | Flutningar á sjó og vatnaleiðum | 444.8979 |
2020 | CO2 | BRIDGE_NR_WATER_TRANSPORT | Þar fyrir utan: Sjóflutningur erlendra aðila hérlendis | 149.5390 |
The ratio between emissions and material consumption should be fairly constant, since almost all of the fuel for these companies is in shipping. Here I need to calculate the total amount of oil regardless of type. I know that the normal value for CO2 emissions per tonne of oil is around 3.2-3.4 tonnes of CO2 per tonne of oil.
ar | BRIDGE_NR_WATER_TRANSPORT | H50 |
---|---|---|
2016 | 0.0031762 | 0.0032714 |
2017 | 0.0031674 | 0.0032363 |
2018 | 0.0031742 | 0.0032328 |
2019 | 0.0031772 | 0.0032462 |
2020 | 0.0032108 | 0.0032209 |
2021 | 0.0032108 | 0.0032269 |
2022 | 0.0032108 | 0.0032345 |
Here, it is natural that the H50 has a higher emission factor, as part of the emission comes from the burning of fuel on land. These figures allow me to get a total of tons of oil for the year beyond what is in the quantity figures.
NACE categories H50 and BRIDGE_NR_WATER_TRANSPORT, where these should be the same or similar numbers.
sector | sector_title | efni_cd | ar | losun | eining | ID_unfccc_mengunarefni | ID_unfccc_sheet_key | ar_skrad |
---|---|---|---|---|---|---|---|---|
1.A.3.d | 1.A.3.d - Domestic Navigation | CO2 | 2020 | 24.90962 | kt | 4 | 321 | 2023 |
1.Memo.1.b | 1.Memo.1.b - Navigation | CO2 | 2020 | 77.19078 | kt | 4 | 347 | 2023 |
These numbers do not differentiate between imports and exports, so it is never as accurate as the AEA calculation. However, I can prepare a model of what the emissions in these items are compared to emissions in NACE categories
2023-07-11: Here’s a pretty obvious flaw I’ve been struggling with in the data. The oil figures for the H50 from 1995-2003 are beyond insane. This needs to be fixed in the next submission
2023-07-11: The same gap exists between NIR and recorded oil consumption in the AEA system. This usage is therefore wrong, especially for H50. The usage is not identical from map for BRIDGE_NR_WATER_TRANSPORT
Here I have two options:
2023-07-11: Decided to use method 2 for returns in 2023. Method 1 will be the default in the next returns
The steps are as follows:
Comments here.
Set export figures in MF421 to deduction category. This means that the fuel I have marked as likely for shipping in the trade figures will be deducted in MF421, but the amount I find in aea is instead put in MF4232. As a backup (and since this is math) I don’t deduct 100% of the fuel, but only about 95%
Deduct fuel in the customs category “fuel purchased abroad by Icelandic ships” from MF421. This fuel is included in the MF4232 numbers from the AEA, but only in customs data from 2013
The result after these two steps:
Calculate the amount of oil based on NIR data and enter the numbers for 1990-1994 Here I can add quantity in MF4232 for years 1990-1994.
For the 2023 return, I seem to have too little oil recorded in the aea.gogn_mapped_eldsneyti_skip_lind table for the years 1995-2002. I can prepare a supplement according to a schedule from the NIR and add in for these years. This correction is only made for selected years (2023) but is otherwise not included
ar | eink | nir_gildi | mapped_tonn | mismunur |
---|---|---|---|---|
1995 | M | 54348.58 | 12831 | 41517.580 |
1995 | X | 42610.75 | 44406 | -1795.250 |
1996 | M | 84340.19 | 14062 | 70278.186 |
1996 | X | 66124.98 | 39000 | 27124.976 |
1997 | M | 86957.98 | 8532 | 78425.975 |
1997 | X | 68177.39 | 46920 | 21257.394 |
1998 | M | 96614.41 | 7871 | 88743.414 |
1998 | X | 75748.30 | 54503 | 21245.302 |
1999 | M | 76421.66 | 6419 | 70002.659 |
1999 | X | 59916.64 | 50927 | 8989.638 |
2000 | M | 89112.45 | 5941 | 83171.448 |
2000 | X | 69866.56 | 67069 | 2797.559 |
2001 | M | 106626.34 | 7126 | 99500.342 |
2001 | X | 83597.92 | 46337 | 37260.923 |
2002 | M | 138882.95 | 6403 | 132479.954 |
2002 | X | 108887.98 | 64806 | 44081.975 |
Skref | Fjöldi raða | Samtals magn fyrir öll ár |
---|---|---|
aea_oliutolur | 467 | 3965306.6 |
utflutningur.verslun421.fradrattur | 53 | -1483923.9 |
eldsneyti_keypt_erlendis_ut | 12 | -897253.1 |
nir_vidbot1990_1994 | 10 | 634513.1 |
Here I was hoping that the net sum of everything would be zero, but the data has a mis-long timeline. This data is otherwise plus numbers that should all go to the MF4232 class and minus numbers that should all go to the MF421 class.
I think this result is quite acceptable. I can always try to revise the projection in aea to fuel, but this is not an out of the box result (and much easier than the previous processing).
In update 05-2023, I decided to automatically insert all data generated in this process into the database instead of doing this manually. This only simplifies the overall run. The data entered here comes from the following list.
Following sql queries are then done
truncate table mfa.sub_gogn_skipasamgongur
insert into mfa.sub_gogn_skipasamgongur(
eu28, ar, mfa_cd, ms_id,
eink, gildi, eining, vinnsla,
reiknad_dags)
select
eu28, ar, mfa_cd, ms_id,
eink, gildi, eining, vinnsla,
reiknad_dags
from tmp_sub_gogn_skipasamgongur
drop table tmp_sub_gogn_skipasamgongur
The same data as is stored in the database is also put into the data assembly for later checks and validations
## Length Class Mode
## table_b_verslun 10 tbl_df list
## table_d_verslun 10 tbl_df list
## table_b_vegasamgongur 10 tbl_df list
## table_d_vegasamgongur 10 tbl_df list
## table_b_flug 10 tbl_df list
## table_d_flug 10 tbl_df list
## table_b_skip 10 tbl_df list
## table_d_skip 10 tbl_df list
## MFA-Table_B.biti.4.rmd finished
In the older processing of the trade figures, I put some fuels (for road transport and shipping) into category MF42. In the correction figures, I calculated a subtraction term based on the OS and AEA data. In some cases, the total deduction is more than the amount entered from the store data. In other cases, some fuel remains. Here I assume that the difference is going to heating, melting or on a fishing vessel. This fuel is about to go into the MF421.
2023-07-12 I think this work process unnecessary and it is therefore omitted
Althought most of the data is based on a view that is automatically updated, I still find it useful to still store the processed data, which can be some 290 thousand lines in full breakdown, in a table in the database. This the data is automatically purged and updated when the script is run, but this method matches the current design of the calculation. The data is stored in the table mfa.gogn_tafla_be (this used to store the eu28/non-eu data as well). The stored data does not have a set of unique columns, although the columns ‘table_cd’, ‘mfa_cd’, ‘ms_id’, ‘ar’, ‘vara_cd’ could become unique in later designs.
After this the following sql processes are executed
truncate table mfa.gogn_tafla_be
insert into mfa.gogn_tafla_be(
table_cd, mfa_cd, ms_id, ar, gildi, eining_inn, vara_cd, lind_texti, vinnsla, reiknad_dags)
select
table_cd, mfa_cd, ms_id, ar, gildi, eining_inn, vara_cd, lind_texti, vinnsla, reiknad_dags
from tmp_gogn_tafla_be
drop table tmp_gogn_tafla_be
The stored data is then checked for consistency and basic quality.
The top part of the table contains the import of material in kilotonnes. This total is summed up at the bottom of the table. There are a lot of values in this table, which means things can easily change without me noticing it.
Here I calculate the difference between the newest submission of the MFA and the data as it is here in the compilation. Some values may need to be tweaked by hand, but most of the table is prepared in this processing. The matrix is then collored by:
Major changes in the outcome result from
## Warning: Removed 309 rows containing missing values (`geom_text()`).
## Warning: Removed 278 rows containing missing values (`geom_text()`).
## Warning: Removed 276 rows containing missing values (`geom_text()`).
## Warning: Removed 228 rows containing missing values (`geom_text()`).
## Warning: Removed 4 rows containing missing values (`geom_text()`).
## Warning: Removed 2 rows containing missing values (`geom_text()`).
The state of manufacturing is a fragile part of the account. I have rarely managed to get the sum of all states of manufacturing to match upp with the total of all products, probably since I am doing some adjusting with fuels that may have different SM designation in imports than what I assign in the processing.
## Warning: Removed 6 rows containing missing values (`geom_text()`).
## Warning: Removed 2 rows containing missing values (`geom_text()`).
One problem has commonly been that the sum of all products by state of manufacturing has been different than the sum over the import quantity. This shouldn’t happen, but can happen if there is a mismatch in the SM designation for the import products and from the products that I use in residental principle adjustments. Example of this is if I record gasoline as SM_FIN into MF421, but then allocate crude oil (residual oils) for the shipping industry (MF4233). This means i will be adding X amoung of SM_SFIN to the shipping industry and then subtracting the same amount from the gasoline value (SM_FIN). This crude-oil was, however, never in the MF421 category, which means I need to retroactively fix the value. This can cause a small mismatch.
ar | TOTAL.TABLE_B | TOTAL.TABLE_B.sm | diff |
---|---|---|---|
1990 | 1943.1267 | 1943.1267 | 0 |
1991 | 1798.1044 | 1798.1044 | 0 |
1992 | 1890.8251 | 1890.8251 | 0 |
1993 | 1842.2589 | 1842.2589 | 0 |
1994 | 1964.1670 | 1964.1670 | 0 |
1995 | 1927.4939 | 1927.4939 | 0 |
1996 | 2120.9677 | 2120.9677 | 0 |
1997 | 2103.4291 | 2103.4291 | 0 |
1998 | 2706.0535 | 2706.0535 | 0 |
1999 | 2768.3411 | 2768.3411 | 0 |
2000 | 3058.3448 | 3058.3448 | 0 |
2001 | 2940.6340 | 2940.6340 | 0 |
2002 | 2980.7924 | 2980.7924 | 0 |
2003 | 3137.4955 | 3137.4955 | 0 |
2004 | 3498.3458 | 3498.3458 | 0 |
2005 | 3735.3203 | 3735.3203 | 0 |
2006 | 4187.6693 | 4187.6693 | 0 |
2007 | 4313.8796 | 4313.8796 | 0 |
2008 | 4892.0926 | 4892.0926 | 0 |
2009 | 4212.6692 | 4212.6692 | 0 |
2010 | 4221.5150 | 4221.5150 | 0 |
2011 | 4253.2343 | 4253.2343 | 0 |
2012 | 4384.1653 | 4384.1653 | 0 |
2013 | 4457.0634 | 4457.0634 | 0 |
2014 | 4527.1802 | 4527.1802 | 0 |
2015 | 5061.7416 | 5061.7416 | 0 |
2016 | 5331.7062 | 5331.7062 | 0 |
2017 | 5814.6164 | 5814.6164 | 0 |
2018 | 6069.7840 | 6069.7840 | 0 |
2019 | 5376.3967 | 5376.3967 | 0 |
2020 | 4655.0319 | 4655.0319 | 0 |
2021 | 5115.1077 | 5115.1077 | 0 |
2022 | 5727.8255 | 5727.8255 | 0 |
2023 | 6485.8153 | 6485.8153 | 0 |
2024 | 840.3645 | 840.3645 | 0 |
The structure of this table has the same structure as Table A
Here I calculate the difference between the newest submission of the MFA and the data as it is here in the compilation. Some values may need to be tweaked by hand, but most of the table is prepared in this processing. The matrix is then collored by:
Major changes in the outcome result from
## Warning: Removed 511 rows containing missing values (`geom_text()`).
## Warning: Removed 145 rows containing missing values (`geom_text()`).
## Warning: Removed 220 rows containing missing values (`geom_text()`).
## Warning: Removed 55 rows containing missing values (`geom_text()`).
## Warning: Removed 5 rows containing missing values (`geom_text()`).
## Warning: Removed 2 rows containing missing values (`geom_text()`).
The state of manufacturing is a fragile part of the account. I have rarely managed to get the sum of all states of manufacturing to match upp with the total of all products, probably since I am doing some adjusting with fuels that may have different SM designation in imports than what I assign in the processing.
## Warning: Removed 6 rows containing missing values (`geom_text()`).
## Warning: Removed 2 rows containing missing values (`geom_text()`).
One problem has commonly been that the sum of all products by state of manufacturing has been different than the sum over the import quantity. This shouldn’t happen, but can happen if there is a mismatch in the SM designation for the import products and from the products that I use in residental principle adjustments. Example of this is if I record gasoline as SM_FIN into MF421, but then allocate crude oil (residual oils) for the shipping industry (MF4233). This means i will be adding X amoung of SM_SFIN to the shipping industry and then subtracting the same amount from the gasoline value (SM_FIN). This crude-oil was, however, never in the MF421 category, which means I need to retroactively fix the value. This can cause a small mismatch.
ar | TOTAL.TABLE_D | TOTAL.TABLE_D.sm | diff |
---|---|---|---|
1990 | 967.3083 | 967.3083 | 0 |
1991 | 754.1475 | 754.1475 | 0 |
1992 | 912.6352 | 912.6352 | 0 |
1993 | 1021.2472 | 1021.2472 | 0 |
1994 | 1265.9715 | 1265.9715 | 0 |
1995 | 1283.4495 | 1283.4495 | 0 |
1996 | 1318.3040 | 1318.3040 | 0 |
1997 | 1351.2389 | 1351.2389 | 0 |
1998 | 1291.0746 | 1291.0746 | 0 |
1999 | 1299.5669 | 1299.5669 | 0 |
2000 | 1436.7444 | 1436.7444 | 0 |
2001 | 1490.3184 | 1490.3184 | 0 |
2002 | 1524.4889 | 1524.4889 | 0 |
2003 | 1490.5871 | 1490.5871 | 0 |
2004 | 1570.2374 | 1570.2374 | 0 |
2005 | 1522.9484 | 1522.9484 | 0 |
2006 | 1437.3386 | 1437.3386 | 0 |
2007 | 1710.3944 | 1710.3944 | 0 |
2008 | 2076.2354 | 2076.2354 | 0 |
2009 | 2027.2363 | 2027.2363 | 0 |
2010 | 2056.3612 | 2056.3612 | 0 |
2011 | 2123.6319 | 2123.6319 | 0 |
2012 | 2208.0015 | 2208.0015 | 0 |
2013 | 2234.0759 | 2234.0759 | 0 |
2014 | 2180.3119 | 2180.3119 | 0 |
2015 | 2186.4681 | 2186.4681 | 0 |
2016 | 2191.4453 | 2191.4453 | 0 |
2017 | 2230.3521 | 2230.3521 | 0 |
2018 | 2512.0543 | 2512.0543 | 0 |
2019 | 2283.8188 | 2283.8188 | 0 |
2020 | 2290.5784 | 2290.5784 | 0 |
2021 | 2333.0278 | 2333.0278 | 0 |
2022 | 2528.2879 | 2528.2879 | 0 |
2023 | 2398.4725 | 2398.4725 | 0 |
2024 | 412.1943 | 412.1943 | 0 |
## MFA-Table_B.rmd completed