API Listing

WiNDC.NationalTableType
NationalTable

Subtype of WiNDCtable that holds the national data.

Fields

  • table::DataFrame: The main table of the WiNDCtable.
  • sets::DataFrame: The sets of the WiNDCtable.

Domain

  • :commodities
  • :sectors
  • :year
source
WiNDC.StateTableType
StateTable

A table that contains data for state-level data.

Fields

  • table::DataFrame - The data table.
  • sets::DataFrame - The sets table.
source
WiNDC.WiNDCtableType
WiNDCtable

Abstract supertype for all WiNDCtables.

Required Fields

  • table::DataFrame: The main table of the WiNDCtable.
  • sets::DataFrame: The sets of the WiNDCtable.

Required Functions

  • domain(data::T) where T<:WiNDCtable: domain

To Do:

Add general idea of how this works.

source
DataFrames.subsetMethod
subset(
        data::T, 
        @nospecialize(args...)
    ) where T <: WiNDCtable

Return a subset of data based on the conditions given in args. This will subset both the main table and the set table.

Required Arguments

  • data::T: The WiNDCtable to subset.
  • args::Tuple: Pairs of the form set_name => boolean function.

Return

A table of type T.

Example

If data is a detailed NationalTable and we want to only view the soybean commodity:

```julia

subset(data, :commodities => (y -> y=="1111A0") )

source
WiNDC.absorption_tax_rateMethod
absorption_tax_rate(data::AbstractNationalTable; column::Symbol = :value, output::Symbol = :value)

Calculate the absorption tax rate of the sectors.

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.

Output

Returns a DataFrame with the columns :sectors and :value.

source
WiNDC.armington_supplyMethod
armington_supply(data::AbstractNationalTable; column::Symbol = :value, output::Symbol = :value)

Calculate the armington supply of the sectors.

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.

Output

Returns a DataFrame with the columns :sectors and :value.

Process

\[\sum_{s\in\text{Sectors}} \text{Intermediate_Demand} + \text{Exogenous_Final_Demand} + \text{Personal_Consumption}\]

source
WiNDC.build_national_tableMethod
build_national_table(
    file_paths::Vector{String};
    aggregation = :detailed
)

Builds the national data from the supply and use tables.

Required Arguments

  • file_paths::Vector{String}: A vector of file paths to the supply and use tables. Uses regex to search for the correct files. This should be the output of fetch_supply_use

Optional Arguments

  • aggregation::Symbol = :detailed: The type of table. Either :detailed or :summary.

Return

A NationalTable.

Process

The data undergoes a series of transformations to create the final table. The data is loaded from the XLSXFiles, transformed into a DataFrame, and then joined with the sets created from the table.

The following data tranformations take place:

  1. Negative flows from intermediate_demand and intermediate_supply are reversed.
  2. subsidies and sector_subsidy are negated.
  3. margin_demand retains only positive values.
  4. margin_supply retains only negative values, these are made positive
  5. personal_consumption retains only positive values.
  6. household_supply retains only negative values, these are made positive.
source
WiNDC.calibrateMethod
calibrate(data::AbstractNationalTable)

This is currently geared toward calibrating the national dataset. I'll be working to make this be a general calibration function.

Returns a new AbstractNationalTable with the calibrated values and the model.

There are three primary balancing operations:

  1. Zero Profit - Column sums are equal
  2. Market Clearance - Row sums are equal
  3. Margin Balance - The margins balance

The three tax rates are fixed. The tax rates are:

  1. Output Tax Rate
  2. Absorption Tax Rate
  3. Import Tariff Rate

The following are fixed:

  1. Labor Compensation
  2. Imports
  3. Exports
  4. Household Supply

Any zero values will remain zero.

source
WiNDC.calibrateMethod
calibrate(data::T; silent = false, lower_bound = .01, upper_bound = 10)

General calibration functions. Handles variable creation, objective function, optimization and post-processing.

Required Arguments

  • data::T: A table of data to calibrate.

Optional Arguments

  • silent::Bool=false: If true, the optimization solver will not print output.
  • lower_bound::Number=.01: The lower bound multiplier for the variables.
  • upper_bound::Number=10: The upper bound multiplier for the variables.

Returns

A tuple of the calibrated data and the optimization model. The calibrated data will have the same type as the input data.

Functions

calibrate_fix_variables - Fix variables that should not be calibrated. calibrate_constraints - Add constraints to the model.

source
WiNDC.calibrate_constraintsMethod
calibrate_constraints(
    M::Model, 
    data::AbstractNationalTable; 
    lower_bound = .01, 
    upper_bound = 10
    )

There are three primary balancing operations:

  1. zero_profit - Column sums are equal
  2. market_clearance - Row sums are equal
  3. margin_balance - The margins balance

Two table sums are bounded by lower_bound and upper_bound multipliers. These are:

  1. gross_output
  2. armington_supply

The three tax rates are fixed. The tax rates are:

  1. other_tax_rate
  2. absorption_tax_rate
  3. import_tariff_rate
source
WiNDC.calibrate_fix_variablesMethod
calibrate_fix_variables(M::Model, data::AbstractNationalTable)

Four subtables are exogenous to the model and are fixed. These are:

  • imports
  • exports
  • labor_demand
  • household_supply
source
WiNDC.create_national_setsMethod
create_national_sets(
    use::XLSX.Worksheet, 
    supply::XLSX.Worksheet,
    set_regions)

This function creates the sets for the detailed national data.

set regions for detailed table

Dict(
    "commodities" => ("use", ["A7:B408"], :commodities),
    "labor_demand" => ("use", ["A410:B410"], :commodities),
    "other_tax" => ("use", ["A411:B411"], :commodities),
    "capital_demand" => ("use", ["A412:B412"], :commodities),
    "sectors" => ("use", ["C5:ON6"], :sectors),
    "personal_consumption" => ("use", ["OP5:OP6"], :sectors),
    "household_supply" => ("use", ["OP5:OP6"], :sectors),
    "exports" => ("use", ["OV5:OV6"], :sectors),
    "exogenous_final_demand" => ("use", ["OQ5:OU6","OW5:PH6"], :sectors),
    "imports" => ("supply", ["OP5:OP6"], :sectors),
    "margin_demand" => ("supply", ["OS5:OT6"], :sectors),
    "margin_supply" => ("supply", ["OS5:OT6"], :sectors),
    "duty" => ("supply", ["OV5:OV6"], :sectors),
    "tax" => ("supply", ["OW5:OW6"], :sectors),
    "subsidies" => ("supply", ["OX5:OX6"], :sectors)
)
source
WiNDC.detailed_summary_mapMethod
detailed_summary_map(detailed_path)

This function reads the detailed table and returns a DataFrame that maps the detailed sectors to the summary sectors. The first sheet of the detailed table is a map between the detailed sectors and the summary sectors. In addition this maps value added, final demand and supply extras to the summary sectors.

source
WiNDC.disaggregate_national_to_stateMethod
disaggregate_national_to_state(
    data::NationalTable,
    data_path::String,
    files::Vector{Tuple{String,String}},
    summary_map;
    industry_codes = "industry_codes.csv",
    state_fips = "state_fips.csv",
    aggregation = :detailed
)

This function disaggregates the national data to the state level. It takes in the national data, the path to the state data, the files that contain the state data, a summary map that maps the national data to the state data, and the industry codes. It returns a StateTable.

source
WiNDC.domainMethod
domain(data::T) where T<:WiNDCtable

Return the domain of the WiNDCtable object. Must be implemented for any subtype of WiNDCtable. Will throw an error if not implemented.

Required Arguments

  1. data - A WiNDCtable-like object.

Output

Returns a vector of symbols representing the domain of the WiNDCtable object.

source
WiNDC.down_fillMethod
down_fill(X)

This function fills in the missing values in a column with the last non-missing value.

source
WiNDC.fetch_supply_useMethod
fetch_supply_use(
    ;
    url::String = "https://apps.bea.gov/industry/iTables%20Static%20Files/AllTablesSUP.zip",
    output_path::String = joinpath(pwd(), "data/national"),
)

Fetch the supply and use tables from the BEA website. The data is stored in a zip file, which is downloaded and extracted to the output_path. The extracted files are then returned as a vector of strings.

Optional Arguments

  • url::String: The url of the zip file containing the supply and use tables. Default is

"https://apps.bea.gov/industry/iTables%20Static%20Files/AllTablesSUP.zip".

  • output_path::String: The path to save the extracted files. Default is the directory data/national

Output

Returns a vector of the absolute paths to the extracted files.

source
WiNDC.filter_to_sutMethod
filter_to_sut(x::AbstractString)

Return true if the string x corresponds to either a detailed or summary supply or use table. Otherwise, return false.

source
WiNDC.get_setMethod
get_set(data::T) where T<:WiNDCtable  

get_set(data::T, set_name::String) where T<:WiNDCtable

get_set(data::T, set_name::Vector{String}) where T<:WiNDCtable

Return the elements of the given sets. If no set is given, return all sets.

Required Arguments

  1. data - A WiNDCtable-like object.
  2. set_name - A string or vector of strings representing the set names to be extracted.

Returns

Returns a DataFrame with three columns, :element, :set and :description

source
WiNDC.get_subtableMethod
get_subtable(data::T, subtable::String, column::Vector{Symbol}; negative::Bool = false, keep_all_columns = false) where T<:WiNDCtable

get_subtable(data::T, subtable::String; column::Symbol = :value, output::Symbol = :value, negative = false) where T<:WiNDCtable

get_subtable(data::T, subtable::Vector{String}) where T<:WiNDCtable

Return the subtables requested as a DataFrame

Required Arguments

  1. data - A WiNDCtable-like object.
  2. subtable - A string or vector of strings representing the subtable names to be extracted.

Optional Arguments

  • column - A symbol representing the column to be extracted. Default is :value.
  • output - A symbol representing the output column name. Default is :value.
  • negative - A boolean representing whether the values should be negated. Default is false.

Returns

Returns a DataFrame with the requested subtables and columns.

source
WiNDC.get_tableMethod
get_table(data::T) where T<:WiNDCtable

Return the main table of the WiNDCtable object as a DataFrame

Required Arguments

  1. data - A WiNDCtable-like object.

Output

Returns a DataFrame with columns domain(data), subtable, and value.

source
WiNDC.gross_outputMethod
gross_output(data::AbstractNationalTable; column::Symbol = :value, output::Symbol = :value)

Calculate the gross output of the sectors.

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.

Output

Returns a DataFrame with the columns :sectors and :value.

Process

\[\sum_{s\in\text{Sectors}} \text{Intermediate_Demand} + \text{Household_Supply} - \text{Margin_Supply}\]

source
WiNDC.import_tariff_rateMethod
import_tariff_rate(data::AbstractNationalTable; column::Symbol = :value, output::Symbol = :value)

Calculate the import tariff rate of the sectors.

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.

Output

Returns a DataFrame with the columns :sectors and :value.

source
WiNDC.load_national_dataMethod
load_national_data(
    use::XLSX.XLSXFile,
    supply::XLSX.XLSXFile;
    table_type = :detailed,
    use_range = "A6:PI417",
    supply_range = "A6:OZ409"
)

Load the national supply and use tables. This function loads the data from the XLSXFiles and returns a DataFrame with the following columns:

  • :commodities: The commodities in the table.
  • :sectors: The sectors in the table.
  • :value: The value of the commodity in the sector.
  • :year: The year of the data.

Required Arguments

  • use::XLSX.XLSXFile: The XLSXFile containing the use table.
  • supply::XLSX.XLSXFile: The XLSXFile containing the supply table.

Optional Arguments

  • table_type::Symbol = :detailed: The type of table. Either :detailed or :summary.
  • use_range::String = "A6:PI417": The range of the use table in the XLSXFile.
  • supply_range::String = "A6:OZ409": The range of the supply table in the XLSXFile.

Return

A DataFrame.

source
WiNDC.load_national_data_single_yearMethod
load_national_data_single_year(
    X::XLSX.XLSXFile,
    year,
    range,
    table_name::String;
    scale = 1_000,
    data_start_row = 2
)

Load a single year of national data. This function is used to load data from the supply and use tables. The data is transformed into a DataFrame with the following columns:

  • :commodities: The commodities in the table.
  • :sectors: The sectors in the table.
  • :value: The value of the commodity in the sector.
  • :year: The year of the data.
  • :table: The name of the table.

Required Arguments

  • X::XLSX.XLSXFile: The XLSXFile containing the data.
  • year: The year of the data.
  • range: The range of the data in the XLSXFile.
  • table_name::String: The name of the table. Usually "use" or "supply".

Optional Arguments

  • scale::Int = 1_000: The scale of the data.
  • data_start_row::Int = 2: The row in the XLSXFile where the data starts. Summary tables start at 3, detailed at 2.

Return

A DataFrame.

source
WiNDC.load_tableMethod
load_table(
    file_path::String
    years::Int...;
)

Load a WiNDCtable from a file.

Required Arguments

  • file_path::String: The path to the file.
  • years::Int...: The years to load. If no years are provided, all years in the file will be loaded.

Returns

A subtype of a WiNDCtable, with the data and sets loaded from the file.

source
WiNDC.make_subtableMethod
make_subtable(sets, rows, columns, table, subtable)

A helper function for extracting subtables.

source
WiNDC.margin_balanceMethod
margin_balance(data::AbstractNationalTable; column = :value, output = :margin_balance)

Calculate the margin balance condition for the given data. In a calibrated dataset all values will be zero.

Required Arguments

  1. data - A WiNDCtable-like object.

Optional Arguments

  • column::Symbol: The column to use for the calculation. Default is :value.
  • output::Symbol: The name of the output column. Default is :margin_balance.

Output

Returns a DataFrame with the margin balance condition.

source
WiNDC.market_clearanceMethod
market_clearance(data::AbstractNationalTable; column = :value, output = :market_clearance)

Calculate the market clearance condition for the given data. In a calibrated dataset all values will be zero.

Required Arguments

  1. data - A WiNDCtable-like object.

Optional Arguments

  • column::Symbol: The column to use for the calculation. Default is :value.
  • output::Symbol: The name of the output column. Default is :market_clearance.

Output

Returns a DataFrame with the market clearance condition.

source
WiNDC.national_mpsgeMethod
national_mpsge(data::NationalTable)

Create a MPSGE model from the given NationalTable object.

Required Arguments

  1. data - A NationalTable object.

Output

Returns a MPSGEModel object.

To Do:

Describe Model

source
WiNDC.other_tax_rateMethod
other_tax_rate(data::AbstractNationalTable; column = :value, output = :value)

Calculate the other tax rate of the sectors.

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.

Output

Returns a DataFrame with the columns :sectors and :value.

source
WiNDC.save_tableMethod
save_table(
    output_path::String
    MU::T;
    overwrite::Bool = false
) where T<:WiNDCtable

Save a WiNDCtable to a file. The file format is HDF5, which can be opened in any other language. The file will have the following structure:

year - DataFrame - The data for each year in the WiNDCtable sets - DataFrame - The sets of the WiNDCtable columns - Array - The column names of each yearly DataFrame

Required Arguments

  • output_path::String: The path to save the file. Must end in .jld2.
  • MU::WiNDCtable: The WiNDCtable to save.

Optional Arguments

  • overwrite::Bool: If true, overwrite the file if it already exists. Default is false.
source
WiNDC.weight_functionMethod
weight_function(year_detail, year_summary, minimum_detail, maximum_detail)

Create the weight function for the interpolation of the detailed table to the summary table based solely on the year.

source
WiNDC.zero_profitMethod
zero_profit(data::AbstractNationalTable; column = :value, output = :zero_profit)

Calculate the zero profit condition for the given data. In a calibrated dataset all values will be zero.

Required Arguments

  1. data - A WiNDCtable-like object.

Optional Arguments

  • column::Symbol: The column to use for the calculation. Default is :value.
  • output::Symbol: The name of the output column. Default is :zero_profit.

Output

Returns a DataFrame with the zero profit condition.

source