How to create a second loop?

Hi guys, I have the following problem. I have the following code:

_shock=2;
Names=MakeStrMat(9,1);
Names[1]="Capital Stock";
Names[2]="Growth";
Names[3]="Output";
Names[4]="Taxable income";
Names[5]="Consumption";
Names[6]="Investment";
Names[7]="Hours worked";
Names[8]="Real wages";
Names[9]="Rent rate of capital";
Legend=MakeStrMat(2,1);
Legend[1]="Variable marginal tax rate";
Legend[2]="Constant marginal tax rate";

struct PlotControl myPlot;
myPlot=PlotGetDefaults("XY");
PlotOpenWindow();
PlotSetLegend(&myPlot,Legend);

te=seqa(0,1,T.nirf);
for i (1,9,1);
    plotlayout(3,3,i);
    plotSetTitle(&myPlot,Names[i]);
    temp=arraytomat(T.irf[_shock,.,i])~arraytomat(T1.irf[_shock,.,i]);
    plotxy(myPlot,te,temp);
endfor;

_shock can take the values 1 and 2. How can I complete or adapt the loop so that the code runs over both values of _schock, so that the plots are created twice, so to speak? Thanks in advance

1 Answer



0



If I am understanding you correctly, I think this will do what you want:

_all_shocks= {1, 2};

Names=MakeStrMat(9,1);
Names[1]="Capital Stock";
Names[2]="Growth";
Names[3]="Output";
Names[4]="Taxable income";
Names[5]="Consumption";
Names[6]="Investment";
Names[7]="Hours worked";
Names[8]="Real wages";
Names[9]="Rent rate of capital";

Legend=MakeStrMat(2,1);
Legend[1]="Variable marginal tax rate";
Legend[2]="Constant marginal tax rate";

struct plotControl myPlot;
myPlot=plotGetDefaults("XY");

plotSetLegend(&myPlot,Legend);

for j(1, rows(all_shocks), 1); 
    _shock = all_shocks[j];

    // Open new graph window for
    // each shock
    plotOpenWindow(); 

    te=seqa(0,1,T.nirf);

    for i (1,9,1);
        plotlayout(3,3,i);
        plotSetTitle(&myPlot,Names[i]);
        temp=arraytomat(T.irf[_shock,.,i])~arraytomat(T1.irf[_shock,.,i]);
        plotxy(myPlot,te,temp);
    endfor;

endfor;

aptech

1,773

Your Answer

1 Answer

0

If I am understanding you correctly, I think this will do what you want:

_all_shocks= {1, 2};

Names=MakeStrMat(9,1);
Names[1]="Capital Stock";
Names[2]="Growth";
Names[3]="Output";
Names[4]="Taxable income";
Names[5]="Consumption";
Names[6]="Investment";
Names[7]="Hours worked";
Names[8]="Real wages";
Names[9]="Rent rate of capital";

Legend=MakeStrMat(2,1);
Legend[1]="Variable marginal tax rate";
Legend[2]="Constant marginal tax rate";

struct plotControl myPlot;
myPlot=plotGetDefaults("XY");

plotSetLegend(&myPlot,Legend);

for j(1, rows(all_shocks), 1); 
    _shock = all_shocks[j];

    // Open new graph window for
    // each shock
    plotOpenWindow(); 

    te=seqa(0,1,T.nirf);

    for i (1,9,1);
        plotlayout(3,3,i);
        plotSetTitle(&myPlot,Names[i]);
        temp=arraytomat(T.irf[_shock,.,i])~arraytomat(T1.irf[_shock,.,i]);
        plotxy(myPlot,te,temp);
    endfor;

endfor;


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy