Q: I am solving a model for several levels in one parameter (comparative statics) and would like to store the results in excel. I would like to store the results for a particular variable in the same worksheet, having just one spreadsheet for the whole solution. The problem is that I do not know how to tell the program to go to the next line after each solution!
Have a look at the example below using the trnsport model from our library. We prepare an area for a report. After the first solve, we clear the report area before merging. Subsequent solves just merge the data in the report area.
$offtext $call'=gamslib trnsport' $offlisting $include trnsport.gms $onlisting set pv /pv1*pv7/; set flds /seattle, san-diego, obj/; execute_unload 'pv.gdx', pv, flds; execute 'gdxxrw pv.gdx set=pv rng=a2 rdim=1 cdim=0 set=flds rng=b1 rdim=0 cdim=1'; execute 'shellexecute pv.xls'; parameter report(pv, flds); loop(pv, Solve transport using lp minimizing z ; report(pv, 'obj') = z.L; report(pv, 'seattle') = a('seattle'); report(pv, 'san-diego') = a('san-diego'); display report; execute_unload 'pv.gdx', report; if(ord(pv)=1, * we clear the data the first time execute 'gdxxrw pv.gdx par=report rng=a1 rdim=1 cdim=1 clear'; else * other times e merge the data without overwriting existing data execute 'gdxxrw pv.gdx par=report rng=a1 rdim=1 cdim=1 merge'; ); * clear the row report(pv, flds) = 0; * change the capacities a('seattle') = a('seattle') - 50.0; a('san-diego') = a('san-diego') + 50.0; ); execute 'shellexecute pv.xls';