Loading...
Searching...
No Matches
nordhausdice.py
Go to the documentation of this file.
18
19if __name__ == "__main__":
20
21 # [1]
22 from gams.magic import GamsInteractive
23 gams = GamsInteractive()
24
25 # [2]
26 gams.gams('''
27# This is the beta version of DICE-2016R. The major changes are outlined in Nordhaus,
28# Revisiting the social cost of carbon: Estimates from the DICE-2016R model,"
29# September 30, 2016," available from the author.
30
31# Version is DICE-2016R-091916ap.gms
32
33# DICE-2016R September 2016 (adapted from DICE-2016R-091216a.gms)
34
35
36Set t 'Time periods (5 years per period)' / 1*100 / ;
37
38Parameters
39
40 fosslim 'Maximum cumulative extraction fossil fuels (GtC)' / 6000 /
41
42 tstep 'Years per Period' / 5 /
43
44 ifopt 'Indicator where optimized is 1 and base is 0' / 0 /
45
46 elasmu 'Elasticity of marginal utility of consumption' / 1.45 /
47 prstp 'Initial rate of social time preference per year' / .015 /
48
49 gama 'Capital elasticity in production function' / .300 /
50 pop0 'Initial world population 2015 (millions)' / 7403 /
51 popadj 'Growth rate to calibrate to 2050 pop projection' / 0.134 /
52 popasym 'Asymptotic population (millions)' / 11500 /
53 dk 'Depreciation rate on capital (per year)' / .100 /
54 q0 'Initial world gross output 2015 (trill 2010 USD)' / 105.5 /
55 k0 'Initial capital value 2015 (trill 2010 USD)' / 223 /
56 a0 'Initial level of total factor productivity' / 5.115 /
57 ga0 'Initial growth rate for TFP per 5 years' / 0.076 /
58 dela 'Decline rate of TFP per 5 years' / 0.005 /
59
60 gsigma1 'Initial growth of sigma (per year)' / -0.0152 /
61 dsig 'Decline rate of decarbonization (per period)' / -0.001 /
62 eland0 'Carbon emissions from land 2015 (GtCO2 per year)' / 2.6 /
63 deland 'Decline rate of land emissions (per period)' / .115 /
64 e0 'Industrial emissions 2015 (GtCO2 per year)' / 35.85 /
65 miu0 'Initial emissions control rate for base case 2015' / .03 /
66
68 mat0 'Initial Concentration in atmosphere 2015 (GtC)' / 851 /
69 mu0 'Initial Concentration in upper strata 2015 (GtC)' / 460 /
70 ml0 'Initial Concentration in lower strata 2015 (GtC)' / 1740 /
71 mateq 'Equilibrium concentration atmosphere (GtC)' / 588 /
72 mueq 'Equilibrium concentration in upper strata (GtC)' / 360 /
73 mleq 'Equilibrium concentration in lower strata (GtC)' / 1720 /
74# Flow paramaters
75 b12 'Carbon cycle transition matrix' / .12 /
76 b23 'Carbon cycle transition matrix' / 0.007 /
77# These are for declaration and are defined later
78 b11 'Carbon cycle transition matrix'
79 b21 'Carbon cycle transition matrix'
80 b22 'Carbon cycle transition matrix'
81 b32 'Carbon cycle transition matrix'
82 b33 'Carbon cycle transition matrix'
83 sig0 'Carbon intensity 2010 (kgCO2 per output 2005 USD 2010)'
84
85 t2xco2 'Equilibrium temp impact (oC per doubling CO2)' / 3.1 /
86 fex0 '2015 forcings of non-CO2 GHG (Wm-2)' / 0.5 /
87 fex1 '2100 forcings of non-CO2 GHG (Wm-2)' / 1.0 /
88 tocean0 'Initial lower stratum temp change (C from 1900)' / .0068 /
89 tatm0 'Initial atmospheric temp change (C from 1900)' / 0.85 /
90 c1 'Climate equation coefficient for upper level' / 0.1005 /
91 c3 'Transfer coefficient upper to lower stratum' / 0.088 /
92 c4 'Transfer coefficient for lower level' / 0.025 /
93 fco22x 'Forcings of equilibrium CO2 doubling (Wm-2)' / 3.6813 /
94
95 a10 'Initial damage intercept' / 0 /
96 a20 'Initial damage quadratic term'
97 a1 'Damage intercept' / 0 /
98 a2 'Damage quadratic term' / 0.00236 /
99 a3 'Damage exponent' / 2.00 /
100
101 expcost2 'Exponent of control cost function' / 2.6 /
102 pback 'Cost of backstop 2010$ per tCO2 2015' / 550 /
103 gback 'Initial cost decline backstop cost per period' / .025 /
104 limmiu 'Upper limit on control rate after 2150' / 1.2 /
105 tnopol 'Period before which no emissions controls base' / 45 /
106 cprice0 'Initial base carbon price (2010$ per tCO2)' / 2 /
107 gcprice 'Growth rate of base carbon price per year' / .02 /
108
109
112 scale1 'Multiplicative scaling coefficient' / 0.0302455265681763 /
113 scale2 'Additive scaling coefficient' / -10993.704 /
114;
115
116# Program control variables
117Sets tfirst(t), tlast(t), tearly(t), tlate(t) ;
118
119Parameters
120 l(t) 'Level of population and labor'
121 al(t) 'Level of total factor productivity'
122 sigma(t) 'CO2-equivalent-emissions output ratio'
123 rr(t) 'Average utility social discount rate'
124 ga(t) 'Growth rate of productivity from'
125 forcoth(t) 'Exogenous forcing for other greenhouse gases'
126 gl(t) 'Growth rate of labor'
127 gcost1 'Growth of cost factor'
128 gsig(t) 'Change in sigma (cumulative improvement of energy efficiency)'
129 etree(t) 'Emissions from deforestation'
130 cumetree(t) 'Cumulative from land'
131 cost1(t) 'Adjusted cost for backstop'
132 lam 'Climate model parameter'
133 gfacpop(t) 'Growth factor population'
134 pbacktime(t) 'Backstop price'
135 optlrsav 'Optimal long-run savings rate used for transversality'
136 scc(t) 'Social cost of carbon'
137 cpricebase(t) 'Carbon price in base case'
138 photel(t) 'Carbon Price under no damages (Hotelling rent condition)'
139 ppm(t) 'Atmospheric concentrations parts per million'
140 atfrac(t) 'Atmospheric share since 1850'
141 atfrac2010(t) 'Atmospheric share since 2010'
142;
143
144# Program control definitions
145tfirst(t) = yes$(t.val eq 1);
146tlast(t) = yes$(t.val eq card(t));
147# Parameters for long-run consistency of carbon cycle
148b11 = 1 - b12;
149b21 = b12*MATEQ/MUEQ;
150b22 = 1 - b21 - b23;
151b32 = b23*mueq/mleq;
152b33 = 1 - b32;
153# Further definitions of parameters
154a20 = a2;
155sig0 = e0/(q0*(1-miu0));
156lam = fco22x/ t2xco2;
157l("1") = pop0;
158loop(t, l(t+1)=l(t););
159loop(t, l(t+1)=l(t)*(popasym/L(t))**popadj ;);
160
161ga(t) = ga0*exp(-dela*5*((t.val-1)));
162al("1") = a0; loop(t, al(t+1)=al(t)/((1-ga(t))););
163gsig("1") = gsigma1; loop(t,gsig(t+1)=gsig(t)*((1+dsig)**tstep) ;);
164sigma("1") = sig0; loop(t,sigma(t+1)=(sigma(t)*exp(gsig(t)*tstep)););
165
166pbacktime(t) = pback*(1-gback)**(t.val-1);
167cost1(t) = pbacktime(t)*sigma(t)/expcost2/1000;
168
169etree(t) = eland0*(1-deland)**(t.val-1);
170cumetree("1") = 100; loop(t,cumetree(t+1)=cumetree(t)+etree(t)*(5/3.666););
171
172rr(t) = 1/((1+prstp)**(tstep*(t.val-1)));
173forcoth(t) = fex0+ (1/17)*(fex1-fex0)*(t.val-1)$(t.val lt 18) + (fex1-fex0)$(t.val ge 18);
174optlrsav = (dk + .004)/(dk + .004*elasmu + prstp)*gama;
175
176# Base Case Carbon Price
177cpricebase(t) = cprice0*(1+gcprice)**(5*(t.val-1));
178
179
180Variables
181 MIU(t) 'Emission control rate GHGs'
182 FORC(t) 'Increase in radiative forcing (watts per m2 from 1900)'
183 TATM(t) 'Increase temperature of atmosphere (degrees C from 1900)'
184 TOCEAN(t) 'Increase temperatureof lower oceans (degrees C from 1900)'
185 MAT(t) 'Carbon concentration increase in atmosphere (GtC from 1750)'
186 MU(t) 'Carbon concentration increase in shallow oceans (GtC from 1750)'
187 ML(t) 'Carbon concentration increase in lower oceans (GtC from 1750)'
188 E(t) 'Total CO2 emissions (GtCO2 per year)'
189 EIND(t) 'Industrial emissions (GtCO2 per year)'
190 C(t) 'Consumption (trillions 2005 US dollars per year)'
191 K(t) 'Capital stock (trillions 2005 US dollars)'
192 CPC(t) 'Per capital consumption (thousands 2005 USD per year)'
193 I(t) 'Investment (trillions 2005 USD per year)'
194 S(t) 'Gross savings rate as fraction of gross world product'
195 RI(t) 'Real interest rate (per annum)'
196 Y(t) 'Gross world product net of abatement and damages (trillions 2005 USD per year)'
197 YGROSS(t) 'Gross world product GROSS of abatement and damages (trillions 2005 USD per year)'
198 YNET(t) 'Output net of damages equation (trillions 2005 USD per year)'
199 DAMAGES(t) 'Damages (trillions 2005 USD per year)'
200 DAMFRAC(t) 'Damages as fraction of gross output'
201 ABATECOST(t) 'Cost of emissions reductions (trillions 2005 USD per year)'
202 MCABATE(t) 'Marginal cost of abatement (2005$ per ton CO2)'
203 CCA(t) 'Cumulative industrial carbon emissions (GTC)'
204 CCATOT(t) 'Total carbon emissions (GtC)'
205 PERIODU(t) 'One period utility function'
206 CPRICE(t) 'Carbon price (2005$ per ton of CO2)'
207 CEMUTOTPER(t) 'Period utility'
208 UTILITY 'Welfare function'
209;
210
211NonNegative Variables MIU, TATM, MAT, MU, ML, Y, YGROSS, C, K, I ;
212
213
214Equations
215# Emissions and Damages
216 EEQ(t) 'Emissions equation'
217 EINDEQ(t) 'Industrial emissions'
218 CCACCA(t) 'Cumulative industrial carbon emissions'
219 CCATOTEQ(t) 'Cumulative total carbon emissions'
220 FORCE(t) 'Radiative forcing equation'
221 DAMFRACEQ(t) 'Equation for damage fraction'
222 DAMEQ(t) 'Damage equation'
223 ABATEEQ(t) 'Cost of emissions reductions equation'
224 MCABATEEQ(t) 'Equation for MC abatement'
225 CARBPRICEEQ(t) 'Carbon price equation from abatement'
226
227# Climate and carbon cycle
228 MMAT(t) 'Atmospheric concentration equation'
229 MMU(t) 'Shallow ocean concentration'
230 MML(t) 'Lower ocean concentration'
231 TATMEQ(t) 'Temperature-climate equation for atmosphere'
232 TOCEANEQ(t) 'Temperature-climate equation for lower oceans'
233
234# Economic variables
235 YGROSSEQ(t) 'Output gross equation'
236 YNETEQ(t) 'Output net of damages equation'
237 YY(t) 'Output net equation'
238 CC(t) 'Consumption equation'
239 CPCE(t) 'Per capita consumption definition'
240 SEQ(t) 'Savings rate equation'
241 KK(t) 'Capital balance equation'
242 RIEQ(t) 'Interest rate equation'
243
244# Utility
245 CEMUTOTPEREQ(t) 'Period utility'
246 PERIODUEQ(t) 'Instantaneous utility function equation'
247 UTIL 'Objective function'
248;
249
250
252eeq(t).. E(t) =E= EIND(t) + etree(t);
253eindeq(t).. EIND(t) =E= sigma(t) * YGROSS(t) * (1-(MIU(t)));
254ccacca(t+1).. CCA(t+1) =E= CCA(t) + EIND(t)*5/3.666;
255ccatoteq(t).. CCATOT(t) =E= CCA(t) + cumetree(t);
256force(t).. FORC(t) =E= fco22x * ((log((MAT(t)/588.000))/log(2))) + forcoth(t);
257damfraceq(t) .. DAMFRAC(t) =E= (a1*TATM(t)) + (a2*TATM(t)**a3) ;
258dameq(t).. DAMAGES(t) =E= YGROSS(t) * DAMFRAC(t);
259abateeq(t).. ABATECOST(t) =E= YGROSS(t) * cost1(t) * (MIU(t)**expcost2);
260mcabateeq(t).. MCABATE(t) =E= pbacktime(t) * MIU(t)**(expcost2-1);
261carbpriceeq(t).. CPRICE(t) =E= pbacktime(t) * (MIU(t))**(expcost2-1);
262
263# Climate and carbon cycle
264mmat(t+1).. MAT(t+1) =E= MAT(t)*b11 + MU(t)*b21 + (E(t)*(5/3.666));
265mml(t+1).. ML(t+1) =E= ML(t) *b33 + MU(t)*b23;
266mmu(t+1).. MU(t+1) =E= MAT(t)*b12 + MU(t)*b22 + ML(t)*b32;
267tatmeq(t+1).. TATM(t+1) =E= TATM(t) + c1*((FORC(t+1)-(fco22x/t2xco2)*TATM(t))-(c3*(TATM(t)-TOCEAN(t))));
268toceaneq(t+1).. TOCEAN(t+1) =E= TOCEAN(t) + c4*(TATM(t)-TOCEAN(t));
269
270# Economic variables
271ygrosseq(t).. YGROSS(t) =E= (al(t)*(L(t)/1000)**(1-GAMA))*(K(t)**GAMA);
272yneteq(t).. YNET(t) =E= YGROSS(t)*(1-damfrac(t));
273yy(t).. Y(t) =E= YNET(t) - ABATECOST(t);
274cc(t).. C(t) =E= Y(t) - I(t);
275cpce(t).. CPC(t) =E= 1000 * C(t) / L(t);
276seq(t).. I(t) =E= S(t) * Y(t);
277kk(t+1).. K(t+1) =L= (1-dk)**tstep * K(t) + tstep * I(t);
278rieq(t+1).. RI(t) =E= (1+prstp) * (CPC(t+1)/CPC(t))**(elasmu/tstep) - 1;
279
280# Utility
281cemutotpereq(t).. CEMUTOTPER(t) =E= PERIODU(t) * L(t) * rr(t);
282periodueq(t).. PERIODU(t) =E= ((C(T)*1000/L(T))**(1-elasmu)-1)/(1-elasmu)-1;
283util.. UTILITY =E= tstep * scale1 * sum(t, CEMUTOTPER(t)) + scale2;
284
285
286# Resource limit
287CCA.up(t) = fosslim;
288
289# Control rate limits
290MIU.up(t) = limmiu;
291MIU.up(t)$(t.val<30) = 1;
292
293
294K.LO(t) = 1;
295MAT.LO(t) = 10;
296MU.LO(t) = 100;
297ML.LO(t) = 1000;
298C.LO(t) = 2;
299TOCEAN.UP(t) = 20;
300TOCEAN.LO(t) = -1;
301TATM.UP(t) = 20;
302CPC.LO(t) = .01;
303TATM.UP(t) = 12;
304
305# Control variables
306set lag10(t);
307lag10(t) = yes$(t.val gt card(t)-10);
308S.FX(lag10(t)) = optlrsav;
309
310# Initial conditions
311CCA.FX(tfirst) = 400;
312K.FX(tfirst) = k0;
313MAT.FX(tfirst) = mat0;
314MU.FX(tfirst) = mu0;
315ML.FX(tfirst) = ml0;
316TATM.FX(tfirst) = tatm0;
317TOCEAN.FX(tfirst) = tocean0;
318
319
320
321model CO2 / all /;''')
322
323 # [3]
324 gams.gams('''
325MIU.FX('1') = miu0;
326solve CO2 maximizing UTILITY using nlp;''')
327
328 # [4]
329 import pandas as pd
330 m = gams.exchange_container
331 results = {}
332 for d in ['TATM','RI','EIND','CPRICE']:
333 results[d] = pd.DataFrame(columns=['opt','bas'])
334 results[d]['opt'] = m[d].records['level'].copy()
335
336 # [5]
337 gams.gams('''
338# For base run, this subroutine calculates Hotelling rents
339# Carbon price is maximum of Hotelling rent or baseline price
340# The cprice equation is different from 2013R. Not sure what went wrong.
341option bRatio = 1; MIU.LO('1') = 0; MIU.UP('1') = inf; # Reset fixing from opt run and discard basis
342a2 = 0;
343solve CO2 maximizing UTILITY using nlp;
344photel(t) = CPRICE.L(t);
345a2 = a20;
346CPRICE.UP(t)$(t.val<tnopol+1) = max(photel(t),cpricebase(t));
347option bRatio=0.25;
348solve CO2 maximizing UTILITY using nlp;''')
349
350
353
354 # [6]
355 tstep = int(m['tstep'].toValue())
356 l = [ 2010 + tstep*n for n in range(len(m['t'].records))]
357 for d in ['TATM','RI','EIND','CPRICE']:
358 results[d]['bas'] = m[d].records['level'].copy()
359 # remap index from 1*100 to 2010,2015,2020,...,2505
360 results[d].set_index(pd.Index(l[:len(m[d].records['level'])]), inplace=True)
361
362
365
366 # [7] - [10] - skipped
367
368
371
372 # [11]
373 gams.gams('''
374## POST-SOLVE
375# Calculate social cost of carbon and other variables
376scc(t) = -1000*eeq.m(t)/(.00001+cc.m(t));
377atfrac(t) = ((MAT.L(t)-588)/(CCATOT.L(t)+.000001 ));
378atfrac2010(t) = ((MAT.L(t)-mat0)/(.00001+CCATOT.L(t)-CCATOT.L('1') ));
379ppm(t) = MAT.L(t)/2.13;
380
381Parameter rep(*,t);
382rep("Industrial Emissions GTCO2 per year", t) = EIND.L(t);
383rep("Atmospheric concentration C (ppm)", t) = MAT.L(t)/2.13;
384rep("Atmospheric Temperature", t) = TATM.L(t);
385rep("Output Net Net)", t) = Y.L(t);
386rep("Climate Damages fraction output", t) = DAMFRAC.L(t);
387rep("Consumption Per Capita", t) = CPC.L(t);
388rep("Carbon Price (per t CO2)", t) = CPRICE.L(t);
389rep("Emissions Control Rate", t) = MIU.L(t);
390rep("Social cost of carbon", t) = scc(t);
391rep("Interest Rate", t) = RI.L(t);
392rep("Population", t) = l(t);
393rep("TFP", t) = al(t);
394rep("Output gross,gross", t) = YGROSS.L(t);
395rep("Change tfp", t) = ga(t);
396rep("Capital", t) = K.L(t);
397rep("s", t) = S.L(t);
398rep("I", t) = I.L(t);
399rep("Y gross net", t) = YNET.L(t);
400rep("damages", t) = DAMAGES.L(t);
401rep("damfrac", t) = DAMFRAC.L(t);
402rep("abatement", t) = ABATECOST.L(t);
403rep("sigma", t) = sigma(t);
404rep("Forcings", t) = FORC.L(t);
405rep("Other Forcings", t) = forcoth(t);
406rep("Period utilty", t) = PERIODU.L(t);
407rep("Consumption", t) = C.L(t);
408rep("Land emissions", t) = etree(t);
409rep("Cumulative ind emissions", t) = CCA.L(t);
410rep("Cumulative total emissions", t) = CCATOT.L(t);
411rep("Atmospheric concentrations Gt", t) = MAT.L(t);
412rep("Atmospheric concentrations ppm", t) = ppm(t);
413rep("Total Emissions GTCO2 per year", t) = E.L(t);
414rep("Atmospheric concentrations upper", t) = MU.L(t);
415rep("Atmospheric concentrations lower", t) = ML.L(t);
416rep("Atmospheric fraction since 1850", t) = atfrac(t);
417rep("Atmospheric fraction since 2010", t) = atfrac2010(t);''')
418
419 # [12]
420 import copy
421
422 rep = copy.deepcopy(m['rep'])
423 rep.records['t'] = rep.records['t'].map({s:2010+tstep*int(s) for s in m['t'].records['uni']})
424 print(rep.pivot(index='t', columns='uni'))
425
426 # [13]
427 gams.gams_cleanup(closedown=True)