API Listing

WiNDCNational.NationalType
National

The primary container for national data tables. There are three fields, all dataframes:

  • data: The main data table.
  • sets: The sets table, describing the different sets used in the model.
  • elements: The elements table, describing the different elements in the model.
source
WiNDCNational.absorption_taxMethod
absorption_tax(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :absorption_tax,
    minimal::Bool = true
)

Calculate the absorption tax of the sectors. For each commodity, absorption tax is defined as the sum of the following parameters:

  • Tax
  • Subsidy

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:absorption_tax`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :at and :parameter is filled with parameter. ```

source
WiNDCNational.absorption_tax_rateMethod
absorption_tax_rate(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :absorption_tax_rate,
    minimal::Bool = true
)

Calculate the absorption tax rate of the sectors. For each commodity, absorption tax rate is defined as the ratio of absorption_tax and armington_supply.

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:absorptiontaxrate`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :atr and :parameter is filled with parameter. ```

source
WiNDCNational.adjust_intermediate_flowsMethod
adjust_intermediate_flows(X::National; kwargs...)

We take inputs to be negative and outputs to be positive. However, it is possible to have positive values in Intermediate_Demand and negative values in Intermediate_Supply. This function adjusts the flows accordingly.

Returns a National table.

source
WiNDCNational.adjust_negative_value_addedMethod
adjust_negative_value_added(X::National; kwargs...)

There are negative capital demeands in the US table. This function adjusts value added to ensure that all capital demands are non-negative. The adjustment is given by

\[\sum_{va} VA(year, va, sector) \cdot \frac{\sum_{year} VA(year, va, sector)}{\sum_{year, va} VA(year, va, sector)} \]

for any negative value in value added.

Returns a National table.

source
WiNDCNational.armington_supplyMethod
armington_supply(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :armington_supply
    minimal::Bool = true
)

Calculate the armington supply of the sectors. For each commodity, armington supply is defined as the sum of the following parameters:

  • Intermediate_Demand
  • Other_Final_Demand

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:armington_supply`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :as and :parameter is filled with parameter. ```

source
WiNDCNational.armington_supply_dataMethod
armington_supply_data(X::T; output = :DataFrame) where T<:AbstractNationalTable

Extract Armington supply related data from a National object, including:

vcat(
    armington_supply(X, minimal=false),
    gross_output(X, minimal=false) |> x-> subset(x, :value => ByRow(>(1e-6))),
    absorption_tax_rate(X, minimal=false),
    import_tariff_rate(X, minimal=false),
    table(X, :Export, :Import, :Margin_Demand; normalize = :Use)
)
source
WiNDCNational.balance_of_paymentsMethod
balance_of_payments(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :balance_of_payments,
    minimal::Bool = true
)

Calculate the balance of payments of the sectors. For each commodity, balance of payments is defined as the sum of the parameters Exports and Imports. This is a scalar for each year.

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:balanceofpayments`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :row and :col are filled with :bop and :parameter is filled with parameter. ```

source
WiNDCNational.build_australia_tableMethod
build_australia_table(yaml_path::String; base_dir::String = pwd())

Build the Australia national table. Structure YAML file as specified by build_national_table.

!!!note The data files provided by Australia are only available in XLSB format, which Julia cannot open. There are also missing headers in final demand, supply extras, and value added. More work is necessary to rectify these issues.

source
WiNDCNational.build_national_tableMethod
build_national_table(yaml_path::String, output_type::Type{<:AbstractNationalTable}; base_dir::String = pwd())

Build and return the national table. By default this accepts a path to a YAML file describing the sets and parameters in the excel files. For convenience, you can also call this function with the :summary or :detailed symbols to load the corresponding YAML files.

For a full discussion on the structure of the YAML files, refer to load_national_yaml.

source
WiNDCNational.create_margin_categoriesMethod
create_margin_categories(X::AustraliaNational; kwargs...)

Split both the Trade and Transport parameters in to Margin_Demand (positive values) and Margin_Supply (negative values).

Also create the set margin which points at the Transport and Trade sectors.

Return a AustraliaNational table.

source
WiNDCNational.create_margin_categoriesMethod
create_margin_categories(X::National; kwargs...)

Split both the Trade and Transport parameters in to Margin_Demand (positive values) and Margin_Supply (negative values).

Also create the set margin which points at the Transport and Trade sectors.

Return a National table.

source
WiNDCNational.create_pce_categoriesMethod
create_pce_categories(X::AustraliaNational; kwargs...)

Split Personal_Consumption parameters into Personal_Consumption (negative values) and Household_Supply (positive values).

Return a AustraliaNational table.

source
WiNDCNational.create_pce_categoriesMethod
create_pce_categories(X::National; kwargs...)

Split Personal_Consumption parameters into Personal_Consumption (negative values) and Household_Supply (positive values).

Return a National table.

source
WiNDCNational.gross_outputMethod
gross_output(
    data::AbstractNationalTable; 
    column = :value, 
    output = :value,
    parameter::Symbol = :gross_output,
    minimal::Bool = true
)

Calculate the gross output of the sectors. For each commodity, gross output is defined as the sum of the following parameters:

  • Intermediate_Supply
  • Household_Supply
  • Margin_Supply

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:gross_output`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :go and :parameter is filled with parameter.

source
WiNDCNational.import_tariff_rateMethod
import_tariff_rate(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :import_tariff_rate,
    minimal::Bool = true
)

Calculate the import tariff rate of the sectors. For each commodity, import tariff rate is defined as the ratio of the parameters Duty and Import.

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:importtariffrate`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :itr and :parameter is filled with parameter. ```

source
WiNDCNational.load_national_yamlMethod
load_national_yaml(yaml_path::String; base_dir::String = pwd())

Load the YAML file that describes the national tables. This function also ensures the file has the correct structure and fields.

Examples of this file are available for the summary data and detailed data.

The base_dir argument is used to specify the base directory for relative paths in the YAML file. The default is the current working directory.

Structure of YAML file

metadata

There are two options for the metadata, either local or remote.

Remote:

  • download: A dictionary with keys the names of the tables and values (at least one needs to be provided):
    • pattern: A regex pattern to match the file name.
    • url: The URL to download the file from.
  • downloadurlcommon: If the tables are contained a shared zip file. Defaults to "".

Local:

  • paths: A dictionary with keys the names of the tables and values the file paths.

Common:

  • years: A dictionary of years with keys the sheet names and value the year Dict{String, Int}.
  • transformation_keywords: Used to pass parameters to the data transformation

functions. For the United States national tables, we use two transformations: - insurance_codes: A list of insurance codes for the redistribution of CIF_FOB data to imports and transport. - marginal_commodities: A list of marginal commodities to include in the transformation.

  • na_values: A list of values to treat as NA (not available). This is useful for handling missing data in the Excel files.

sets

Each set is listed with the following attributes:

  • description - A description for the set
  • domain - Which column the set operates on
  • values - An Excel range that corresponds to the NAICS codes
  • descriptions - An Excel range that corresponds to the descriptions of the NAICS codes
  • table - Needs to match the listed paths for download names
  • value_labels (optional) - A list of labels for the set elements. If not provided, the values from the Excel range will be used.

parameters

Each parameter name is listed with the following attributes:

  • param - The name of the parameter. This acts as the set to access the parameter.
  • description - A description of the parameter
  • row - The row set of the parameter.
  • col - The column set of the parameter
  • table - Needs to match the listed paths for download names
  • flipsign - Boolean, changes the sign of the data. Only used on `sectorsubsidy` since the values are reported as positive, but must be negative.

The parameters reference the sets, you shouldn't need to update the parameters if you only change the sets.

composite_parameters

Each composite parameter is listed with the following attributes:

  • description - A description of the composite parameter
  • elements - A list of elements that make up the composite parameter. These should be parameter names
source
WiNDCNational.margin_balanceMethod
margin_balance(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :margin_balance,
    minimal::Bool = true
)

Calculate the margin balance condition. For each margin, the margin balance condition is defined as the sum of the following parameters:

  • Margin_Supply
  • Margin_Demand

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:margin_balance`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:col, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :mb and :parameter is filled with parameter.

source
WiNDCNational.margin_supply_dataMethod
margin_supply_data(data::T; output = :DataFrame) where T<:AbstractNationalTable

Extract Margin_Supply from a National object.

table(data, :Margin_Supply; normalize=:Margin_Supply)
source
WiNDCNational.market_clearanceMethod
market_clearance(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :market_clearance,
    minimal::Bool = true
)

Calculate the market clearance condition. For each commodity, the market clearance condition is defined as the sum of the following parameters:

  • Intermediate_Demand
  • Final_Demand
  • Intermediate_Supply
  • Household_Supply
  • Margin_Supply
  • Margin_Demand
  • Imports
  • Tax
  • Duty
  • Subsidies

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:market_clearance`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :mc and :parameter is filled with parameter.

source
WiNDCNational.national_mpsgeMethod
national_mpsge(data::T; year = elements(data, :year) |> x -> maximum(x[!, :name])) where T<:AbstractNationalTable

Create a MPSGE model from the given National object.

Required Arguments

  1. data - A National object.

Keyword Arguments

  • year - The year for which to build the model. Defaults to the maximum year in the data.

Output

Returns a MPSGEModel object.

Model Description

Parameters

- Absorption_Tax[c=commodities], absorption_tax_rate[c]
- Import_Tariff[c=commodities], import_tariff_rate[c]
- Output_Tax[s=sectors], output_tax_rate[s]

Sectors

- Y[s=sectors]  - "Sectoral Production"
- A[c=commodities]  - "Armington Supply"
- MS[m=margins]  - "Margin Supply"

Commodities

- PA[c=commodities] - "Armington Price"
- PY[c=commodities] - "Output Price"
- PVA[va=value_added] - "Value Added Price"
- PM[m=margins] - "Margin Price"
- PFX - Foreign Exchange

Consumers

- RA - Representative Agent

Productions

The data functions are:

    sectoral_production_data(X; output=:Dict) |>  x -> 
    @production(M, Y[s=sectors], [t=0,s=0, va => s=1], begin
        @output(PY[c=commodities], x[c, s, :intermediate_supply], t, taxes = [Tax(RA, Output_Tax[s])])
        @input(PA[c=commodities], x[c, s, :intermediate_demand], s) 
        @input(PVA[va = value_added], x[va, s, :value_added], va)   
    end)

    margin_supply_data(X; output=:Dict) |>  x -> 
    @production(M, MS[m=margins], [t=0, s=0], begin
        @output(PM[m], sum(x[c, m] for c in commodities if x[c, m] != 0), t) 
        @input(PY[c=commodities], x[c,m], s)
    end)


    armington_supply_data(X; output=:Dict) |>  x -> 
    @production(M, A[c=commodities], [t=2, s=0, dm=>s=2], begin
        @output(PA[c], x[c, :as, :armington_supply], t, taxes = [Tax(RA, Absorption_Tax[c])], reference_price = 1-x[c,:atr, :absorption_tax_rate]) 
        @output(PFX, sum(x[c, e, :export] for e in exports), t)
        @input(PM[m=margins], x[c, m, :margin_demand], s)
        @input(PFX, sum(x[c, i, :import] for i in imports), dm, taxes = [Tax(RA, Import_Tariff[c])], reference_price = 1+x[c, :itr, :import_tariff_rate])
        @input(PY[c], x[c, :go, :gross_output], dm) 
    end)


    representative_agent_data(X; output=:Dict) |>  x -> 
    @demand(M, RA, begin
        @final_demand(PA[c=commodities], sum(x[c, pce, :personal_consumption] for pce in PCE)) 
        @endowment(PY[c=commodities], sum(x[c, hhs, :household_supply] for hhs in HHS)) 
        @endowment(PFX, x[:bop, :bop, :balance_of_payments])
        @endowment(PA[c=commodities], -x[c, :ofd, :ofd]) 
        @endowment(PVA[va=value_added], sum(x[va, s, :value_added] for s∈sectors))
    end)
source
WiNDCNational.output_taxMethod
output_tax(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :actual_output_tax,
    minimal::Bool = true
)

Calculate the actual output tax for each sector. For each sector, the output tax is the sum of the parameters:

  • Output_Tax
  • Sector_Subsidy

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:actualoutputtax: The name of the parameter column. This is to avoid potential conflicts with the:output_tax` parameter.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:col, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :ot and :parameter is filled with parameter.

source
WiNDCNational.output_tax_rateMethod
output_tax_rate(
    data::AbstractNationalTable; 
    column = :value, 
    output = :value,
    parameter = :output_tax_rate,
    minimal::Bool = true
)

Calculate the output tax rate of the sectors. This is the ratio of the output_tax to the sectoral_output.

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:outputtaxrate`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:col, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :otr and :parameter is filled with parameter.

source
WiNDCNational.redistribute_cif_fobMethod
redistribute_cif_fob(X::National; insurance_codes::Vector{String} = [], kwargs...)

Redistribute the CIF_FOB parameter to Transport and Import, add all insurance commodities values to Import and non-insurance commodities to Transport. Remove CIF_FOB parameter.

Returns a National table.

source
WiNDCNational.representative_agent_dataMethod
representative_agent_data(X::T; output = :DataFrame) where T<:AbstractNationalTable

Extract representative agent related data from a National object, including:

  • Personal_Consumption, Household_Supply, Value_Added
  • balance_of_payments
  • Investment_Final_Demand, Government_Final_Demand -> Sum values as a new parameter ofd.
vcat(
    table(X, :Personal_Consumption, :Household_Supply, :Value_Added; normalize=:Use),
    balance_of_payments(X, minimal=false),
    table(X, :Investment_Final_Demand, :Government_Final_Demand; normalize=:Use) |>
        x-> groupby(x, [:row, :year]) |>
        x -> combine(x, 
            [:col, :parameter] .=> (y -> (:ofd)) .=> [:col, :parameter],
            :value => sum => :value)
)
source
WiNDCNational.sectoral_outputMethod
sectoral_output(
    data::AbstractNationalTable; 
    column::Symbol = :value, 
    output::Symbol = :value,
    parameter::Symbol = :sectoral_output,
    minimal::Bool = true
)

Calculate the sectoral output tax for each sector. For each sector, the sectoral output is the sum of the parameters:

  • Intermediate_Demand
  • Value_Added
  • Output_Tax
  • Sector_Subsidy

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:sectoral_output`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:col, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :so and :parameter is filled with parameter.

source
WiNDCNational.sectoral_production_dataMethod
sectoral_production_data(data::T; output = :DataFrame) where T<:AbstractNationalTable

Extract Intermediate_Demand, Intermediate_Supply, Labor_Demand, and Capital_Demand from a National object. Also make Labor_Demand and Capital_Demand use value_added as the parameter column.

out = table(data, 
    :Intermediate_Demand,
    :Intermediate_Supply,
    :Labor_Demand,
    :Capital_Demand;
    normalize = :Use
)
source
WiNDCNational.zero_marginal_tax_subsidyMethod
zero_marginal_tax_subsidy(X::National; marginal_commodities::Vector{String} = [], kwargs...)

Set the subsidy and tax parameters for marginal commodities to zero.

Returns a National table.

source
WiNDCNational.zero_profitMethod
zero_profit(X::AbstractNationalTable; column = :value, output = :value)

Calculate the zero profit condition. For each sector, the zero profit condition is defined as the sum of the following parameters:

  • Intermediate_Demand
  • Intermediate_Supply
  • Value_Added

Required Arguments

  • data::AbstractNationalTable: The national data.

Keyword Arguments

  • column::Symbol = :value: The column to be used for the calculation.
  • output::Symbol = :value: The name of the output column.
  • parameter::Symbol =:zero_profit`: The name of the parameter column.
  • minimal::Bool = true: Whether to return a minimal output. If true, only the essential columns are returned: [:row, :year, :parameter, output].

Output

Returns a DataFrame with columns [:row, :col, :year, :parameter, output], where output is the renamed column column. Note that :col is filled with :zp and :parameter is filled with parameter.

source