Page 1 of 1

Modeling of uncertainty through scenarios and storing in xlsx files

Posted: Wed Apr 17, 2019 6:32 pm
by KarolineSH
Dear community,

I am modeling with the DICE2016 model of Nordhaus, which code is publicly available here; ... 916ap.gms.
and I desperately need help as I am very inexperienced in GAMS (and time constrained).

Here are 2 (somewhat related) questions;
  • I wish to model uncertainty in an altered version of the DICE model, (initially) through one parameter at the time, such as the initial growth rate of TFP, "ga0". I believe the best way to do this is to import an Excel sheet with 10,000 MC-drawn values of ga0 to GAMS, before looping over these scenarios.
    Here is my code;

    Code: Select all

    **Karo tries random generation of ga0
    set sc scenarios ;
    * scenario set implicitly defined via parameter ga0_s
    parameter ga0_s(sc<);
    $onecho > file.1.txt
    dset=sc rng=a1   rdim=1
    par=ga0_s rng=Sheet2!a1 rdim=0 cdim=1
    * read data from excel and store in GDX file
    $call GDXXRW Indata.xlsx trace=3 @file.1.txt 
    $ife errorlevel<>0 $abort Problem with GDXXRW
    * load data from gdx file
    $gdxin Indata
    $load ga0_s
    display sc, ga0_s;
    parameter report(*,*,*) report parameter
    * loop over scenarios and updata data as needed
      ga0 = ga0_s(sc);
    * update other symbols if there are any in the model that depend ga0
        al("1") = a0; loop(t, al(t+1)=al(t)/((1-ga(t))););
      solve co2 maximizing utility using nlp;  
        report('scc',t,sc) = -1000*eeq.m(t)/(.00001+cc.m(t));
    execute_unload 'try1.2.gdx' report;
    execute 'gdxxrw try1.2.gdx  par=report rdim=2 cdim=1'  ;
    abort$(errorlevel<>0) 'problems wirth GDXXRW';

    Could someone kindly help me how to specify this, as my output seem to report all the scenarios as one run, and I get several error codes?
  • Assuming that I am able to run the model 10,000 times with the different ga0-parameters, I then want to report the output in Excel-format (SCC(t), consumption per capita (t) etc.). Since the runs are so many I wish to tell GAMS to report the output in 100 (smaller) xlsx-files, showing 100 scenarios each, and then compiling them to one additional large one with all the scenarios. I would preferably have both csv- and xlsx-files.
    How can I do that?
Please find my attached code, input and output.

Thank you so much in advance!

Kind regards!

Re: Modeling of uncertainty through scenarios and storing in xlsx files

Posted: Sat Jun 15, 2019 6:23 pm
by bussieck
If you look at the GDX file symbol sc generated by the gdxxw call you see what is going on (the set labels are your scenario parameters). You need to supply in Excel a column with scenario label names. I also had to modify the the gdxxrw command.

The put_utility allows you to manage the writing of results into different files. I have added code that solves 20 scenarios and puts 5 scenarios each in a separate Excel and csv file (I used gdxdump to create the csv files).

Please find the modified Excel and GAMS file attached.


PS If you are in a rush and hold a valid GAMS license you can contact to get help in a more timely fashion. The forum is great but sometimes not a replacement for commercial support.