|
gdrsclib
|
Go to the source code of this file.
Data Structures | |
| struct | tax_entry |
| The tax table has a dynamically allocated array of entries of this form. More... | |
| struct | gdrs_struct |
| This is the main struct that contains data from the sqlite3 database and calculated values. More... | |
Macros | |
| #define | GDRS_OK 0 |
| #define | GDRS_CFGREADERROR 255 |
| #define | GDRS_CFGCLOSEERROR 256 |
| #define | GDRS_FREADERROR 258 |
| #define | GDRS_FCLOSEERROR 259 |
| #define | GDRS_NOMEM 260 |
| #define | GDRS_DIDNOTRUN 261 |
| #define | GDRS_TOO_MANY_TAX_ENTRIES 262 |
| #define | GDRS_ID_TABLE "id='gdrstable'" |
| #define | GDRS_ROW_ID "calcrow" |
| #define | GDRS_CLASS_REGION "class='gdrsregion'" |
| #define | GDRS_ID_WORLD "class='gdrsregion' id='gdrsworld'" |
| #define | GDRS_TEXT_COL "class='gdrstextcol'" |
| #define | GDRS_SQLITE_OFFSET 1024 |
| #define | GDRS_SQLITE_CANTDELETEDB 1023 |
| #define | GDRS_SQLITE_BUFSIZE 2048 |
| #define | GDRS_SQLITE_HALFBUFSIZE 1024 |
| #define | GDRS_NUM_PARAMS 12 |
| #define | GDRS_NUM_TAX_PARAMS 6 |
| #define | EPS_NEWTON 1.0e-9 |
| #define | INIT_Y 500 |
| #define | PER_BEFORE_EP 0 |
| #define | PER_SEQUENCE 1 |
| #define | PER_GDRS 2 |
| #define | ANNEX1 1 |
| #define | ANNEX2 2 |
| #define | XR_PPP 0 |
| #define | XR_MER 1 |
| #define | TAX_MAX_ENTRIES 100 |
| #define | TAX_TYPE_VALUE 0 |
| #define | TAX_TYPE_NATL_QUINTILE 1 |
| #define | TAX_TYPE_GLOBAL_QUINTILE 2 |
| #define | GAP_COMBINE_NONE 0 |
| #define | GAP_COMBINE_ADD 1 |
| #define | GAP_COMBINE_MAX 2 |
| #define | GAP_COMBINE_MIN 3 |
Functions | |
| void | handle_sql3error (sqlite3 *db, sqlite3_stmt *stmt) |
| Function that wraps repetitive code for SQLite3 errors. More... | |
| int | loadgdrs (struct gdrs_struct *gdrs, const char *fname) |
| Function to translate from SQLite3 database to internal data structures. More... | |
| int | readtable (sqlite3 *db, const char *column, struct datablock *table, struct appdata ad) |
| Helper function to read a column from the "core" table into a datablock. More... | |
| void | cleargdrs (struct gdrs_struct gdrs) |
| Clear out the GDRs data structure. More... | |
| void | nextrci (int year, struct gdrs_struct *gdrs) |
| Calculate the GDRs Responsibility-Capacity Indicator for a particular year. More... | |
| double | luxcap (int year, struct gdrs_struct *gdrs) |
| If calculating luxury-capped baselines adjust the luxury threshold if needed to stay above emergency pathway. More... | |
| void | combine_gap (struct fixedfactor *gap, int i, double newgap, int combine) |
| Calculate and store luxury emissions. More... | |
| void | calc_luxemiss (struct fixedfactor *gap, double *totgap, int year, int period, int combine, struct gdrs_struct *gdrs) |
| Calculate and store luxury emissions. More... | |
| void | calc_kab (struct fixedfactor *gap, double *totgap, int year, int period, int combine, struct gdrs_struct *gdrs) |
| Calculate and store "Kyoto gap" for Kyoto-adjusted baselines. More... | |
| void | calcallocs (struct gdrs_struct *gdrs) |
| Calculate allocations for all years. More... | |
| void | calcybar (struct gdrs_struct *gdrs) |
| Calculate mean income from GDP and population. More... | |
| struct datablock | z (double y, struct gdrs_struct *gdrs, int ppp_or_mer) |
| Calculate the "z" transformed version of an income level for all countries and years. More... | |
| double | M (double a, double zc, double ybar, double sigma) |
| Calculate a function \(M_a(y_c,\bar{y},\sigma)\) that is repeatedly used in calculations. More... | |
| double | globaldist (double y, int year, struct gdrs_struct *gdrs, int ppp_or_mer, double *dist_deriv) |
| Calculate the fraction of global population below a specified income level in the given year. More... | |
| double | globalquintile (double q, int year, struct gdrs_struct *gdrs, int ppp_or_mer) |
| Calculate the income at a given quintile for the world as a whole. More... | |
| double | a_gamma (double gamma, double y, double a, double b) |
| Calculate the \(a_\gamma(y;a,b)\) function. More... | |
| double | b_gamma (double gamma, double y, double b) |
| Calculate the \(b_\gamma(y;b)\) function. More... | |
| double | A_gamma (double gamma, double za, double zb, double yl, double yu, double ybar, double sigma) |
| Calculate the \(A_\gamma(a,b;y_l,y_u/\pi_i,\bar{y}_i,\sigma_i)\) function. More... | |
| double | B_gamma (double gamma, double za, double zb, double yu, double ybar, double sigma) |
| Calculate the \(B_\gamma(a,b;y_u/\pi_i,\bar{y}_i,\sigma_i)\) function. More... | |
| double | capbetween (double za, double zb, double zl, double zu, double yl, double yu_ppp, double ybar, double sigma, double pi, double luxmult) |
| Calculate capacity per capita between two income limits. More... | |
| double | respbetween (double gamma, double za, double zb, double zl, double zu, double yl, double yu_ppp, double ybar, double sigma, double A) |
| Calculate responsibility between two income limits. More... | |
| double | rhat (double E, double gamma, double sigma, double ybar) |
| Calculate the factor \(\hat{r}_i\) for a country. More... | |
| double | c_indiv (double y, double yl, double yu, int do_interp) |
| Calculate individual per capita capacity \(c_i(y)\) at a specified income level. More... | |
| double | r_indiv (double gamma, double y, double yl, double yu, double A, int do_interp) |
| Calculate individual per capita annual responsibility \(r_i(y)\) at a specified income level. More... | |
| int | dump2sql3 (const char *fname, struct gdrs_struct gdrs) |
| After the calculation, write all results to the SQLite3 database. More... | |
| double a_gamma | ( | double | gamma, |
| double | y, | ||
| double | a, | ||
| double | b | ||
| ) |
Calculate the \(a_\gamma(y;a,b)\) function.
| gamma | Elasticity |
| y | Income (PPP) at which to evaluate the function |
| a | Lower income limit |
| b | Upper income limit |
\[0 \mbox{ if } |a - b| < \epsilon\]
or\[a_\gamma(y;a,b) = \frac{1}{b - a}\left[\frac{\gamma}{\gamma +1}\left(y^{\gamma+1}-a^{\gamma+1}\right)-a\left(y^\gamma - a^\gamma\right)\right],\]
| double A_gamma | ( | double | gamma, |
| double | za, | ||
| double | zb, | ||
| double | yl, | ||
| double | yu, | ||
| double | ybar, | ||
| double | sigma | ||
| ) |
Calculate the \(A_\gamma(a,b;y_l,y_u/\pi_i,\bar{y}_i,\sigma_i)\) function.
| gamma | Elasticity |
| za | Lower income limit (transformed variable) |
| zb | Upper income limit (transformed variable) |
| yl | Development threshold |
| yu | Luxury threshold |
| ybar | Mean income for the country |
| sigma | Standard deviation of log income for the country |
\[0 \mbox{ if } |y_u - y_l| < \epsilon\]
or\[A_\gamma(a,b) = \frac{1}{y/\pi_i-y_l}\left[ \frac{\gamma}{\gamma+1}\left(M_{\gamma+1}(a) - M_{\gamma+1}(b)\right) - y_l\left(M_\gamma(a) - M_\gamma(b)\right) + \frac{y_l^{\gamma+1}}{\gamma+1} \left(M_0(b) - M_0(a)\right)\right],\]
| double b_gamma | ( | double | gamma, |
| double | y, | ||
| double | b | ||
| ) |
Calculate the \(b_\gamma(y;b)\) function.
| gamma | Elasticity |
| y | Income (PPP) at which to evaluate the function |
| b | Upper income limit |
\[b_\gamma(y;b) = y^\gamma - b^\gamma.\]
| double B_gamma | ( | double | gamma, |
| double | za, | ||
| double | zb, | ||
| double | yu, | ||
| double | ybar, | ||
| double | sigma | ||
| ) |
Calculate the \(B_\gamma(a,b;y_u/\pi_i,\bar{y}_i,\sigma_i)\) function.
| gamma | Elasticity |
| za | Lower income limit (transformed variable) |
| zb | Upper income limit (transformed variable) |
| yu | Luxury threshold |
| ybar | Mean income for the country |
| sigma | Standard deviation of log income for the country |
\[B_\gamma(a,b) = \left(M_\gamma(a)-M_\gamma(b)\right) - \left(\frac{y_u}{\pi_i}\right)^\gamma\left(M_0(a) - M_0(b)\right),\]
| double c_indiv | ( | double | y, |
| double | yl, | ||
| double | yu, | ||
| int | do_interp | ||
| ) |
Calculate individual per capita capacity \(c_i(y)\) at a specified income level.
| y | Income at which to calculate c_indiv |
| yl | Development threshold |
| yu | Luxury threshold |
| do_interp | Boolean: are we interpolating between thresholds? |
| void calc_kab | ( | struct fixedfactor * | gap, |
| double * | totgap, | ||
| int | year, | ||
| int | period, | ||
| int | combine, | ||
| struct gdrs_struct * | gdrs | ||
| ) |
Calculate and store "Kyoto gap" for Kyoto-adjusted baselines.
| gap | Difference between nominal baseline and luxury-adjusted baseline (if doing luxury-capping) |
| totgap | Sum of gaps across all countries |
| year | Current year for the calculation |
| period | For sequencing: PER_BEFORE_EP, PER_SEQUENCE, or PER_GDRS |
| combine | If more than one gap, how are they being combined? GAP_COMBINE_NONE, GAP_COMBINE_ADD, GAP_COMBINE_MAX, GAP_COMBINE_MIN |
| gdrs | The global data structure for the GDRs calculation |
| void calc_luxemiss | ( | struct fixedfactor * | gap, |
| double * | totgap, | ||
| int | year, | ||
| int | period, | ||
| int | combine, | ||
| struct gdrs_struct * | gdrs | ||
| ) |
Calculate and store luxury emissions.
| gap | Difference between nominal baseline and luxury-adjusted baseline (if doing luxury-capping) |
| totgap | Sum of gaps across all countries |
| year | Current year for the calculation |
| period | For sequencing: PER_BEFORE_EP, PER_SEQUENCE, or PER_GDRS |
| combine | If more than one gap, how are they being combined? GAP_COMBINE_NONE, GAP_COMBINE_ADD, GAP_COMBINE_MAX, GAP_COMBINE_MIN |
| gdrs | The global data structure for the GDRs calculation |
Set gdrs.lux_emiss, gdrs.lux_emiss_applied
| void calcallocs | ( | struct gdrs_struct * | gdrs | ) |
| void calcybar | ( | struct gdrs_struct * | gdrs | ) |
| double capbetween | ( | double | za, |
| double | zb, | ||
| double | zl, | ||
| double | zu, | ||
| double | yl, | ||
| double | yu_ppp, | ||
| double | ybar, | ||
| double | sigma, | ||
| double | pi, | ||
| double | luxmult | ||
| ) |
Calculate capacity per capita between two income limits.
| za | Lower income limit (transformed variable) |
| zb | Upper income limit (transformed variable) |
| zl | Development threshold (transformed variable) |
| zu | Luxury threshold (transformed variable) |
| yl | Development threshold |
| yu_ppp | Luxury threshold in PPP terms |
| ybar | Mean income for the country |
| sigma | Standard deviation of log income for the country |
| pi | Inverse of ppp2mer ratio |
| luxmult | Tax multiplier on high incomes |
| void cleargdrs | ( | struct gdrs_struct | gdrs | ) |
| void combine_gap | ( | struct fixedfactor * | gap, |
| int | i, | ||
| double | newgap, | ||
| int | combine | ||
| ) |
Calculate and store luxury emissions.
| gap | Difference between nominal baseline and luxury-adjusted baseline (if doing luxury-capping) |
| i | Value in gap to set |
| newgap | New value for entry i |
| combine | If more than one gap, how are they being combined? GAP_COMBINE_NONE, GAP_COMBINE_ADD, GAP_COMBINE_MAX, GAP_COMBINE_MIN |
| int dump2sql3 | ( | const char * | fname, |
| struct gdrs_struct | gdrs | ||
| ) |
| double globaldist | ( | double | y, |
| int | year, | ||
| struct gdrs_struct * | gdrs, | ||
| int | ppp_or_mer, | ||
| double * | dist_deriv | ||
| ) |
Calculate the fraction of global population below a specified income level in the given year.
| y | Income level below which to calculate the share of the global population |
| year | Year to report population share |
| gdrs | The global data structure for the GDRs calculation |
| ppp_or_mer | Whether using PPP or MER conversion rates |
| dist_deriv | Pointer to a variable to store the derivative of the function (for finding quintiles) or NULL |
| double globalquintile | ( | double | q, |
| int | year, | ||
| struct gdrs_struct * | gdrs, | ||
| int | ppp_or_mer | ||
| ) |
Calculate the income at a given quintile for the world as a whole.
| q | The quintile (e.g., 0.5 for the median) |
| year | The year in which to calculate the quintile |
| gdrs | The global data structure for the GDRs calculation |
| ppp_or_mer | Whether using PPP or MER conversion rates |
| void handle_sql3error | ( | sqlite3 * | db, |
| sqlite3_stmt * | stmt | ||
| ) |
| int loadgdrs | ( | struct gdrs_struct * | gdrs, |
| const char * | fname | ||
| ) |
| double luxcap | ( | int | year, |
| struct gdrs_struct * | gdrs | ||
| ) |
If calculating luxury-capped baselines adjust the luxury threshold if needed to stay above emergency pathway.
| year | Year for calculating the adjusted luxury cutoff |
| gdrs | Global data structure containing parameters and data for all calculations |
| double M | ( | double | a, |
| double | zc, | ||
| double | ybar, | ||
| double | sigma | ||
| ) |
Calculate a function \(M_a(y_c,\bar{y},\sigma)\) that is repeatedly used in calculations.
| a | Elasticity |
| zc | Income cutoff, transformed into "z" variable \( z = \frac{1}{\sigma} \ln\left(y/\bar y\right) + \frac{1}{2}\sigma\) |
| ybar | Mean income |
| sigma | Standard deviation of log income |
\[M_a(y_c,\sigma,\bar y) = \bar{y}^a e^{\frac{\sigma^2}{2} a (a - 1)} \left[1 - N(z_c - a \sigma)\right],\]
where \(N(\cdot)\) is the cumulative standardized normal distribution.\[M_a(k y_c,\sigma, k\bar y) = k^aM_a(y_c, \sigma, \bar y)\]
| void nextrci | ( | int | year, |
| struct gdrs_struct * | gdrs | ||
| ) |
Calculate the GDRs Responsibility-Capacity Indicator for a particular year.
| year | Year for which to calculate RCI |
| gdrs | Global data structure containing parameters and data Set gdrs.c, gdrs.r, gdrs.pop_above_dl, gdrs.pop_above_lux, gdrs.rci, gdrs.tax_revenue_mer_dens, tax_revenue_ppp_dens, gdrs.tax_pop_dens, gdrs.tax_income_mer_dens, tax_income_ppp_dens, gdrs.tax_pop_below |
| double r_indiv | ( | double | gamma, |
| double | y, | ||
| double | yl, | ||
| double | yu, | ||
| double | A, | ||
| int | do_interp | ||
| ) |
Calculate individual per capita annual responsibility \(r_i(y)\) at a specified income level.
| gamma | Emissions elasticity |
| y | Income at which to calculate r_indiv |
| yl | Development threshold |
| yu | Luxury threshold |
| A | Overall coefficient (factor \(\hat{r}_i\)) |
Helper function to read a column from the "core" table into a datablock.
| db | Handle for the SQLite3 database |
| column | Name of the column in the core table of the database |
| table | Internal data representation |
| ad | appdata structure with dimensions |
| double respbetween | ( | double | gamma, |
| double | za, | ||
| double | zb, | ||
| double | zl, | ||
| double | zu, | ||
| double | yl, | ||
| double | yu_ppp, | ||
| double | ybar, | ||
| double | sigma, | ||
| double | A | ||
| ) |
Calculate responsibility between two income limits.
| gamma | Emissions elasticity |
| za | Lower income limit (transformed variable) |
| zb | Upper income limit (transformed variable) |
| zl | Development threshold (transformed variable) |
| zu | Luxury threshold (transformed variable) |
| yl | Development threshold |
| yu_ppp | Luxury threshold in PPP terms |
| ybar | Mean income for the country |
| sigma | Standard deviation of log income for the country |
| A | Overall multiplicative constant to convert to emissions |
| double rhat | ( | double | E, |
| double | gamma, | ||
| double | sigma, | ||
| double | ybar | ||
| ) |
Calculate the factor \(\hat{r}_i\) for a country.
| E | Annual emissions |
| gamma | Emissions elasticity |
| sigma | Standard deviation of the log of income |
| ybar | Mean income |
\[\hat{r}_i=\frac{E_{i}}{{\bar{y}_{i}}^{\gamma }}e^{-{\frac{\sigma _{i}^{2}}{\;2}}\gamma (\gamma -1)}\]
| struct datablock z | ( | double | y, |
| struct gdrs_struct * | gdrs, | ||
| int | ppp_or_mer | ||
| ) |
Calculate the "z" transformed version of an income level for all countries and years.
| y | The income at which to calculate z |
| gdrs | Global data structure with variables and parameters |
| ppp_or_mer | Whether using PPP or MER conversion rates |
1.8.14