Skip to contents

The goal of the aggregate.model Package is to implement and operationalise the Aggregate Model, developed by Moritz Schwarz, Jonas Kurle, Felix Pretis, and Andrew Martinez. This is an adaptation of the Norwegian Aggregate Model, developed by Gunnar Bardsen and Ragnar Nymoen.

Installation

You can install the development version of aggregate.model from GitHub with:

# install.packages("devtools")
devtools::install_github("moritzpschwarz/aggregate.model")

Basic Workflow

This is an example which shows you how to run the model:

First we load the package:

Specify the model

The we calibrate the model specification and save this in a tibble. Here the column names and the structure of the specification table must follow the basic structure below.

spec <- dplyr::tibble(
  type = c(
    "n",
    "n",
    "n",
    "n",
    "d",
    "n",
    "n",
    "n",
    "n"
  ),
  dependent = c(
    "Import",
    "FinConsExpHH",
    "GCapitalForm",
    "Emissions",
    "GDP",
    "GValueAddGov", # as in NAM, technical relationship
    "GValueAddManuf", # more complicated in NAM, see 2.3.3 and 6.3.1
    "GValueAddConstr" ,
    "GValueAddWholesaletrade"
  ),
  independent = c(
    "FinConsExpHH + GCapitalForm",
    "",
    "FinConsExpGov + FinConsExpHH",
    "GDP + Export + GValueAddIndus",
    "GValueAddGov + GValueAddAgri + GValueAddIndus + GValueAddConstr + GValueAddWholesaletrade + GValueAddInfocom + GValueAddFinance + GValueAddRealest + GValueAddResearch + GValueAddArts",
    "FinConsExpGov", # as in NAM, technical relationship
    "Export + LabCostManuf", # NAM uses 'export market indicator' not exports - unclear what this is, NAM uses unit labour cost in NOR manufacturing relative to the foreign price level - here is just total labour cost
    "LabCostConstr + BuildingPermits", # in NAM some form of YFP2J = 0.3JBOL + 0.2JF P N + 0.3JO + 0.3JOIL. Unclear what this is. Using Building Permits instead
    "Export + LabCostService"
  ))

To summarise this, we can print out the specification table:

type dependent independent
n Import FinConsExpHH + GCapitalForm
n FinConsExpHH
n GCapitalForm FinConsExpGov + FinConsExpHH
n Emissions GDP + Export + GValueAddIndus
d GDP GValueAddGov + GValueAddAgri + GValueAddIndus + GValueAddConstr + GValueAddWholesaletrade + GValueAddInfocom + GValueAddFinance + GValueAddRealest + GValueAddResearch + GValueAddArts
n GValueAddGov FinConsExpGov
n GValueAddManuf Export + LabCostManuf
n GValueAddConstr LabCostConstr + BuildingPermits
n GValueAddWholesaletrade Export + LabCostService

In order to run this model, we also need a dictionary that translates our model variables to EUROSTAT codes so that the download process can be automated. You can either pass a new dictionary to the model function, or you can use the built in dictionary aggregate.model::dict:

model_varname full_name database variable_code dataset_id var_col freq geo unit s_adj nace_r2 ipcc_sector cpa2_1 siec
TOTS Total Supply NA TOTS NA NA NA NA NA NA NA NA NA NA
GDP Gross domestic product at market prices eurostat B1GQ namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
GValueAdd Value added, gross eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA TOTAL NA NA NA
Export Exports of goods and services eurostat P6 namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
Import Imports of goods and services eurostat P7 namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
GCapitalForm Gross capital formation eurostat P5G namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
FinConsExp Final consumption expenditure eurostat P3 namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
FinConsExpGov Final consumption expenditure of general government eurostat P3_S13 namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
FinConsExpHH Household and NPISH final consumption expenditure eurostat P31_S14_S15 namq_10_gdp na_item q AT CLV05_MEUR SCA NA NA NA NA
StatDiscrep Statistical discrepancy (expenditure approach) eurostat YA0 namq_10_gdp na_item q AT CP_MEUR SCA NA NA NA NA
Emissions Greenhouse Gas Emissions (All NACE and HH) eurostat GHG env_ac_aigg_q airpol q AT THS_T SCA TOTAL_HH NA NA NA
LabCostManuf Manufacturing Labour cost index - Total Labour Cost eurostat LM-LCI-TOT ei_lmlc_q indic q AT I20 SCA C NA NA NA
DomDemand Domestic Demand NA DomDemand NA NA NA NA NA NA NA NA NA NA
GValueAddManuf Value added, gross Manufacturing eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA C NA NA NA
GValueAddGov Value added, gross Government eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA O-Q NA NA NA
LabCostConstr Construction Labour cost index - Total Labour Cost eurostat LM-LCI-TOT ei_lmlc_q indic q AT I20 SCA F NA NA NA
BuildingPermits Building permits - m^2 useful floorspace - Buildings eurostat PSQM sts_cobp_q indic_bt q AT I15 SCA F_CC1 NA CPA_F41001_41002 NA
LabCostService Service Labour cost index - Total Labour Cost eurostat LM-LCI-TOT ei_lmlc_q indic q AT I20 SCA G-N NA NA NA
GValueAddConstr Value added, gross Construction eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA F NA NA NA
GValueAddAgri Value added, gross Agriculture eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA A NA NA NA
GValueAddIndus Value added, gross Industry eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA B-E NA NA NA
GValueAddInfocom Value added, gross Information and Communication eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA J NA NA NA
GValueAddFinance Value added, gross Financial Services eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA K NA NA NA
GValueAddRealest Value added, gross Real Estate eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA L NA NA NA
GValueAddResearch Value added, gross Scientific and Professional Services eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA M_N NA NA NA
GValueAddArts Value added, gross Arts and Entertainment eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA R-U NA NA NA
GValueAddWholesaletrade Value added, gross Wholesale and retail trade and Tourism eurostat B1G namq_10_a10 na_item q AT CLV05_MEUR SCA G-I NA NA NA
HICP Harmonised Index of Consumer Prices, all items, index 100 = 2015 eurostat CP00 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Energy Harmonised Index of Consumer Prices, Energy, index 100 = 2015 eurostat NRG prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Electricity Harmonised Index of Consumer Prices, Electricity, index 100 = 2015 eurostat CP0451 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Gas Harmonised Index of Consumer Prices, Gas, index 100 = 2015 eurostat CP0452 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Liquid_Fuels Harmonised Index of Consumer Prices, Liquid Fuels, index 100 = 2015 eurostat CP0453 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Solid_Fuels Harmonised Index of Consumer Prices, Solid Fuels, index 100 = 2015 eurostat CP0454 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HICP_Heat Harmonised Index of Consumer Prices, Heat Energy, index 100 = 2015 eurostat CP0455 prc_hicp_midx coicop m AT I15 NA NA NA NA NA
HDD Heating Degree Days eurostat HDD nrg_chdd_m indic_nrg m AT NR NA NA NA NA NA
CDD Cooling Degree Days eurostat CDD nrg_chdd_m indic_nrg m AT NR NA NA NA NA NA
EmiCH4Livestock Methane Emissions from Livestock edgar NA https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/EDGAR/datasets/v70_FT2021_GHG/v70_FT2021_CH4_m_2000_2021.zip NA m AT NA NA NA 3.A NA NA
EmiCO2Industry Carbon Emissions from Industrial Processes and Product Use edgar NA https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/EDGAR/datasets/v70_FT2021_GHG/v70_FT2021_CO2_m_2000_2021.zip NA m AT NA NA NA 2 NA NA
EmiCO2Combustion Carbon Emissions from Fuel Combustion Activities edgar NA https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/EDGAR/datasets/v70_FT2021_GHG/v70_FT2021_CO2_m_2000_2021.zip NA m AT NA NA NA 1.A NA NA
EmiN2OTotal Nitrous Oxide Emissions Total edgar NA https://jeodpp.jrc.ec.europa.eu/ftp/jrc-opendata/EDGAR/datasets/v70_FT2021_GHG/v70_FT2021_N2O_m_2000_2021.zip NA m AT NA NA NA TOTAL NA NA

Running the model

Now we are ready to run the model with the run_model() function:

model_result <- run_model(
  specification = spec,
  save_to_disk = "inst/extdata/InputData.xlsx",
  primary_source = "download",
  trend = TRUE,
  saturation.tpval = 0.01
)
#> Dataset query already saved in cache_list.json...
#> Reading cache file C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/d63eb01c350ec7f1bc8d8a8748cbaf1c.rds
#> Table  namq_10_gdp  read from cache file:  C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/d63eb01c350ec7f1bc8d8a8748cbaf1c.rds
#> Dataset query already saved in cache_list.json...
#> Reading cache file C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/70233871602d11a16e54c9ad5a1c57c1.rds
#> Table  env_ac_aigg_q  read from cache file:  C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/70233871602d11a16e54c9ad5a1c57c1.rds
#> Dataset query already saved in cache_list.json...
#> Reading cache file C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/4081fb052bac8868b67123e3066ec6a0.rds
#> Table  ei_lmlc_q  read from cache file:  C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/4081fb052bac8868b67123e3066ec6a0.rds
#> Dataset query already saved in cache_list.json...
#> Reading cache file C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/0ce900d1db16519a6a4802bf61a2de80.rds
#> Table  namq_10_a10  read from cache file:  C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/0ce900d1db16519a6a4802bf61a2de80.rds
#> Dataset query already saved in cache_list.json...
#> Reading cache file C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/8c5d516c94180cbe8c02ed2720aaf9b7.rds
#> Table  sts_cobp_q  read from cache file:  C:\Users\morit\AppData\Local\Temp\RtmpAHxT8m/eurostat/8c5d516c94180cbe8c02ed2720aaf9b7.rds
#> Warning in load_or_download_variables(specification = module_order, dictionary
#> = dictionary, : Unbalanced panel, will lose more than 20\% of data when making
#> balanced
#> 
#> --- Estimation begins ---
#> Estimating GValueAddGov = FinConsExpGov 
#> Estimating GValueAddManuf = Export + LabCostManuf 
#> Estimating GValueAddConstr = LabCostConstr + BuildingPermits 
#> Estimating GValueAddWholesaletrade = Export + LabCostService 
#> Estimating FinConsExpHH =  
#> Constructing GDP = GValueAddGov + GValueAddAgri + GValueAddIndus + GValueAddConstr + GValueAddWholesaletrade + GValueAddInfocom + GValueAddFinance + GValueAddRealest + GValueAddResearch + GValueAddArts 
#> Estimating GCapitalForm = FinConsExpGov + FinConsExpHH 
#> Estimating Emissions = GDP + Export + GValueAddIndus 
#> Estimating Import = FinConsExpHH + GCapitalForm

The first time that we run this, all data will be downloaded and saved in the folder data/use/InputData.xlsx.

The next time that we run the same model, we can save some time and just load the data from our earlier run:

model_result <- run_model(
  specification = spec,
  primary_source = "local",
  inputdata_directory = "inst/extdata",
  trend = TRUE,
  saturation.tpval = 0.01
)

Forecasting the model

Now that we have run the model, we can forecast the model (here using an AR process for the exogenous values and for 10 time periods):

model_forecast <- forecast_model(model_result, n.ahead = 10, exog_fill_method = "AR", plot.forecast = FALSE)
#> No exogenous values provided. Model will forecast the exogenous values with an AR4 process (incl. Q dummies, IIS and SIS w 't.pval = 0.001').
#> Alternative is exog_fill_method = 'last'.

Once we are done, we can plot the forecast:

plot(model_forecast, order.as.run = TRUE)