API Listing
WiNDCNational.National
— TypeNational
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.
WiNDCContainer.calibrate_constraints
— Methodcalibrate_constraints(M::Model, X::National; lower_bound = .01, upper_bound = 10)
We implement the following constraints:
zero_profit
equal to 0market_clearance
equal to 0margin_balance
equal to 0gross_output
is bounded bylower_bound
andupper_bound
of its valuearmington_supply
is bounded bylower_bound
andupper_bound
of its value
We fix the following tax rates:
WiNDCContainer.calibrate_fix_variables
— Methodcalibrate_fix_variables(M::Model, X::National)
Four parameters are considered to be exogenous and fixed in the calibration:
- Import
- Export
- Labor Demand
- Household Supply
WiNDCNational.absorption_tax
— Methodabsorption_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
. ```
WiNDCNational.absorption_tax_rate
— Methodabsorption_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
. ```
WiNDCNational.adjust_intermediate_flows
— Methodadjust_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.
WiNDCNational.armington_supply
— Methodarmington_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
. ```
WiNDCNational.balance_of_payments
— Methodbalance_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
. ```
WiNDCNational.build_australia_table
— Methodbuild_australia_table(yaml_path::String)
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.
WiNDCNational.build_national_table
— Methodbuild_national_table(yaml_path::String)
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
.
WiNDCNational.build_us_table
— Methodbuild_us_table(yaml_path::String)
build_us_table(aggregation::Symbol = :summary)
Build the US national table. Structure YAML file as specified by build_national_table
.
WiNDCNational.create_margin_categories
— Methodcreate_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.
WiNDCNational.create_margin_categories
— Methodcreate_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.
WiNDCNational.create_pce_categories
— Methodcreate_pce_categories(X::AustraliaNational; kwargs...)
Split Personal_Consumption
parameters into Personal_Consumption
(negative values) and Household_Supply
(positive values).
Return a AustraliaNational table.
WiNDCNational.create_pce_categories
— Methodcreate_pce_categories(X::National; kwargs...)
Split Personal_Consumption
parameters into Personal_Consumption
(negative values) and Household_Supply
(positive values).
Return a National table.
WiNDCNational.gross_output
— Methodgross_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
.
WiNDCNational.import_tariff_rate
— Methodimport_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
. ```
WiNDCNational.load_national_yaml
— Methodload_national_yaml(yaml_path::String)
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.
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. In particular, it's useful to have an insurance_codes
keyword for the redistribution of CIF_FOB
data to imports and transport.
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 - Either "use" or "supply"
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 - Either "use" or "supply"
- 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
WiNDCNational.margin_balance
— Methodmargin_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
.
WiNDCNational.market_clearance
— Methodmarket_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
.
WiNDCNational.merge_export_reexport
— Methodmerge_export_reexport(X::AustraliaNational; kwargs...)
Merge export and re-export values in the dataset.
Return a AustraliaNational table.
WiNDCNational.national_mpsge
— Methodnational_mpsge(data::T; year = 2023) where T<:AbstractNationalTable
Create a MPSGE model from the given National object.
Required Arguments
data
- A National object.
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
table(X,
:Intermediate_Supply,
:Intermediate_Demand,
:Labor_Demand,
:Capital_Demand;
normalize = :Use
) |>
x -> DefaultDict(0, Dict((row[:row], row[:col], parameter_col(row[:parameter])) => row[:value] for row in eachrow(x))) |>
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)
table(X, :Margin_Supply; normalize=:Margin_Supply) |>
x -> DefaultDict(0, Dict((row[:row], row[:col]) => row[:value] for row in eachrow(x))) |>
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)
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)
) |>
x -> DefaultDict(0, Dict((row[:row], row[:col], row[:parameter]) => row[:value] for row in eachrow(x))) |>
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)
### Demands
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)
) |>
x -> DefaultDict(0, Dict((row[:row], row[:col], parameter_col(row[:parameter])) => row[:value] for row in eachrow(x))) |>
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)
WiNDCNational.output_tax
— Methodoutput_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
.
WiNDCNational.output_tax_rate
— Methodoutput_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
.
WiNDCNational.redistribute_cif_fob
— Methodredistribute_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.
WiNDCNational.sectoral_output
— Methodsectoral_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
.
WiNDCNational.zero_profit
— Methodzero_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
.