calc_cf: Calculate/Simulate model counterfactual

Description Usage Arguments Details Value

View source: R/calc_cf.R

Description

TODO: CLEAN THIS UP calc_cf is a wrapper function for the cpp function that calculates the model counterfactual described in the paper for a given set of data and a shock.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
calc_cf(
  data,
  shock,
  parameters,
  tol = 1e-08,
  zeta = 0.3,
  maxiter = 10000,
  method = "automatic",
  nthreads = 1L
)

Arguments

data

a list of model variables possibly derived from convert_io which contains

location_id

vector of location ids

sector_id

vector of sector ids

R

matrix of location-sector revenues with N = length(location_id) rows and J = length(sector_id) columns

D

vector of locations' deficit transfers, i.e. positive for a trade deficit and negative for a trade surplus

pi

vector of import shares across locations for each sector-destination-use combination, where the import share of origin o in sector s products used in destination d and use category u is at position o + (d-1)*N + (s-1)*N*N + (u-1)*N*N*J

alpha

matrix of sectoral consumption shares in each location with N rows and J columns

gamma_jrs

vector of intermediate cost shares across sectrs for each destination-use combination, where the cost share of sector s intermediates used in destination d and use category u is at position d + (s-1)*N + (u-1)*N*J

gamma_js

matrix of location-sector labor cost shares with N rows and J columns

shock

a list containing a shock with values

T_hat

technological shock

tol

tolerance for algorithm to stop

zeta

dampening factor

maxiter

maximum number of iterations

method

either matrix or RHS

nthreads

number of threads to use in parallel. This relies on OpenMP and thus has no effect on MacOS.

Details

The main purpose of this function is twofold. Firstly to do some basic checks and input manipulations (e.g. from character to numeric) before calling the cpp code. Secondly, the main set of market clearing equations of the model can be solved as a linear equation system at each step of the iterative counterfactual solution algorithm or one can directly use right hand side values of R. The former converges much faster and is more stable in converging but problematic when the simulation involves shocks with infinitely high trade barriers (preventing a matrix inversion to sole the linear system). Therefore this function also decides which cpp algorithm to pick based upon the shock.

Value

Returns a list of R_hat, P_hat, multres, multres_tmp, R_div, P_hat_div, C_hat, Q_hat, D_prime, L_prime, L_tilde_hat, c_hat, pi_hat


okrebs/DeGVC documentation built on March 15, 2021, 1:17 a.m.