Functions
GlobalTradeAnalysisProjectModelV7.aggregate_data
— Method aggregate_data(; hData, hParameters, hSets, comMap, regMap, endMap)
Aggregates data, parameters and sets based on the provided mapping vectors.
Args:
hData
: a dictionary of GTAP data (arrays) with the names as found in HAR fileshParameters
: a dictionary of GTAP parameters (arrays) with the names as found in HAR fileshSets
: a dictionary of GTAP sets (vectors of strings) with the names as found in HAR filescomMap
: a mapping vector (NamedVector) which provides for each element in setcomm
the desired aggregate nameregMap
: a mapping vector (NamedVector) which provides for each element in setreg
the desired aggregate nameendMap
: a mapping vector (NamedVector) which provides for each element in setendw
the desired aggregate name
Retruns:
A named tuple with elements hData, hParameters, hSets containing the aggregated data
Example:
julia (; hData, hParameters, hSets) = aggregate_data(hData=data, hParameters=parameters, hSets=sets, comMap=comMap, regMap=regMap, endMap=endMap)
GlobalTradeAnalysisProjectModelV7.aggregate_data_legacy
— Method aggregate_data_legacy(; hData, hParameters, hSets, comMap, regMap, endMap)
Aggregates data, parameters and sets based on the provided mapping vectors while incorporating an error in aggregation found in GTAPAgg2 or FlexAgg, where three parameters (i.e., ESUBM, ESUBD and ESUBV) are aggregated globally even though they are defined as region-specific
Args:
hData
: a dictionary of GTAP data (arrays) with the names as found in HAR fileshParameters
: a dictionary of GTAP parameters (arrays) with the names as found in HAR fileshSets
: a dictionary of GTAP sets (vectors of strings) with the names as found in HAR filescomMap
: a mapping vector (NamedVector) which provides for each element in setcomm
the desired aggregate nameregMap
: a mapping vector (NamedVector) which provides for each element in setreg
the desired aggregate nameendMap
: a mapping vector (NamedVector) which provides for each element in setendw
the desired aggregate name
Retruns:
A named tuple with elements hData, hParameters, hSets containing the aggregated data
Example:
julia (; hData, hParameters, hSets) = aggregate_data_legacy(hData=data, hParameters=parameters, hSets=sets, comMap=comMap, regMap=regMap, endMap=endMap)
GlobalTradeAnalysisProjectModelV7.build_model!
— Methodbuild_model!(mc; max_iter=50, constr_viol_tol=1e-8, bound_push=1e-15)
Builds the GTAP model in the provided model container (mc
) which has an empty Ipopt model. This function is not typically called by the user; instead, it is invoked by generate_initial_model()
. However, if the user wishes to change the model, he or she can extend this function.
Args:
mc
: a model container
Optional args:
max_iter
: maximum number of iterationsconstr_viol_tol
: accuracy for constraint satisfactionbound_push
: mandatory move of the starting values from constraint bounds
Retruns:
Nothing but it modifies the mc
object, adding on the existing model
element
Example:
julia build_model!(mc)
GlobalTradeAnalysisProjectModelV7.calculate_ev
— MethodDeprecated. Use calculate_expenditure()
GlobalTradeAnalysisProjectModelV7.calculate_expenditure
— Method calculate_expenditure(; sets, data0, data1, parameters, max_iter=50, constr_viol_tol=1e-5, bound_push=1e-15)
Calculate the expenditure at post simulation utility (in data1) at original prices (data0)
Args:
sets
: a dictionary of setsdata0
: a dictionary of data from baseline solutiondata1
: a dictionary of data from simulation solutionparameters
: a dictionary of parameters
Optional args:
max_iter
: maximum number of iterationsconstr_viol_tol
: accuracy for constraint satisfactionbound_push
: mandatory move of the starting values from constraint bounds
Returns:
A vector of expenditures.
GlobalTradeAnalysisProjectModelV7.calculate_gdp
— Methodcalculate_gdp(; sets, data0, data1)
Calculate GDP from post-simulation quantities at pre-simulation prices.
Args:
sets
: a dictionary of setsdata0
: a dictionary of data from baseline solutiondata1
: a dictionary of data from simulated solution
GlobalTradeAnalysisProjectModelV7.extract_model!
— Methodextract_model!(model_container)
GlobalTradeAnalysisProjectModelV7.generate_calibration_inputs
— Methodgenerate_calibration_inputs(model_container, start_data)
Produces the required inputs for default calibration. The calibration is focused on the value flows in the GTAP database.
Args:
model_container
: the model container with the current modelstart_data
: a dictionary with the data representing the desired calibration level
Returns
A named tuple with two elements: fixed_calibration
containing the closure, and data_calibration
containing the desired calibration data.
GlobalTradeAnalysisProjectModelV7.generate_initial_model
— Methodgenerate_initial_model(; hSets, hData, hParameters)
Produces an initial model container based on data, parameters and sets.
Args:
hSet
: a dictionary of setshData
: a dictionary of datahParameters
: a dictionary of parameters
Returns:
A model container with the following elements:
model
: an empty Ipopt modeldata
: a dictionary of data (variables in the model)parameters
: a dictionary of parameter valuessets
: a dictionary of setsfixed
: a dictionary of Boolean arrays defining the closure of the model (exogenous/fixed variables)lower
: a dictionary of lower bounds for model variablesupper
: a dictionary of upper bounds for model variables
Example:
$julia generate_initial_model(; hSets, hData, hParameters)$
GlobalTradeAnalysisProjectModelV7.generate_starting_values
— Methodgenerate_starting_values(; hSets, hData, hParameters)
Produces starting values for all required variables in the model. This is typically not called by the user; instead, this is invoked in the process of producing the initial model.
Args:
hSets
: a dictionary of setshData
: a dictionary of datahParameters
: a dictionary of parameters
Returns:
A named tuple with six elements: sets sets
, parameters parameters
, data data
, closure fixed
, lower bounds lower
, and upper bounds upper
GlobalTradeAnalysisProjectModelV7.get_sample_data
— Methodget_sample_data()
Returns a small sample data set from publicly available version 9 of the GTAP database.
Args:
- None
Retruns:
A named tuple with
hData
: a dictionary with sample aggregated datahParamters
: a dictionary with sample aggregated parametershSets
: a dictionary with sample aggregated sets
Example:
julia (; hData, hParameters, hSets) = get_sample_data()
GlobalTradeAnalysisProjectModelV7.initialize_model!
— Methodinitialize_model!(model_container)
GlobalTradeAnalysisProjectModelV7.rebuild_model!
— Methodrebuild_model(mc; calibration = false)
Rebuilds the model, typically to create a slimmer model without calibration equations
Args:
mc
: model containercalibration
: include calibration equations
Returns:
An updated model container
Example:
$julia rebuild_model!(mc)$
GlobalTradeAnalysisProjectModelV7.run_model!
— Methodrun_model!(model_container; max_iter=50, constr_viol_tol=1e-8, bound_push=1e-15)
Runs the model (modelcontainer.model) by executing these steps: (1) set all starting values to those found in the data (modelcontainer.data), (2) fix all variables that are specified as exogenous (modelcontainer.fixed), (3) solve the model, (4) load all variable values to the data (modelcontainer.data)
Args:
model_container
: model container
Optional args:
max_iter
: maximum number of iterationsconstr_viol_tol
: accuracy for constraint satisfactionbound_push
: mandatory move of the starting values from constraint bounds
GlobalTradeAnalysisProjectModelV7.solve_model!
— Methodsolve_model!(model_container; max_iter, constr_viol_tol, bound_push)
GlobalTradeAnalysisProjectModelV7.solve_model
— Methodsolve_model(; sets, data, parameters, fixed, max_iter=50, constr_viol_tol=1e-8, bound_push=1e-15, model=nothing)