simulate contribution option

Jun 25, 2014 at 3:58 PM
I'm trying to use simulate command with "contribution" options. I have to run the simulation twice as I have unanticipated shocks over the first period of my total simulation date range, and anticipated shocks over the second period. I used the output database from my first simulation as input to my second simulation. See examples below, the input database db_shk (in first simulation) is a zero database with all shocks data defined over my total simulation range.
db_contr1 = simulate(my_model, db_shk, dateRng1, 'anticipate=', false, ...
     'deviation=',true, 'dbOverlay=',true, 'contributions=', true);

db_contr2 = simulate(my_model, db_contr1, dateRng2, 'anticipate=', true, ...
      'deviation=',true, 'dbOverlay=',true, 'contributions=', true);
The first simulation is ok, but when I do the second simulation, it seems IRIS didn't take lags of my transitional variables as exogenous values passed in from db_contr1; instead, it initializes them as 0. I was trying to use plan object, but it seems the plan cannot exist with 'contribution' options. I'm wondering how I can define those lags to use the data existing in my input database to do my second simulation. Thank you for you help.
Coordinator
Jun 25, 2014 at 4:40 PM
Hi

I supposed you meant "lags" = initial conditions for the second simulations, correct? Can you please post the files so that I can look into the issue?

Thanks,
Jaromir
Jun 25, 2014 at 7:48 PM
Yes, you are right Jaromir. It is the initial conditions for the second simulations don't seem correct. However, if you don't set 'contribution', everything seems fine.

Here is my code:
db_shk = zerodb(my_model, dateRng); 
shkList = get(my_model, 'eVector');

for i = 1:length(shkList)
    db_shk.(shkList{i}) = db_fore.(shkList{i});
end

dateRng1 = qq(1973, 1):qq(2013,4);
dateRng2 = qq(2014,1):qq(2014,1) +400;

db_contr1 = simulate(my_model, db_shk, dateRng1 , 'anticipate=', false, ...
          'deviation=',true,  'dbOverlay=',true,'contributions=', true);
     
db_contr2 = simulate(my_model, db_contr1, dateRng2 , 'anticipate=', true, ...
          'deviation=',true,  'dbOverlay=',true,'contributions=', true);

shkGrp = grouping(my_model, 'shock');
shkGrp = addgroup(shkGrp, 'all shock', shkList);
db_decomp = eval(shkGrp, db_contr2);
Supposedly db_decomp (all shocks contributions) should be the same as my db_fore, however, here is an example result of what I got:
>> disp(resize([db_decomp.lc db_fore.lc], qq(2012,1):qq(2015,4)))
    tseries object: 16-by-4

    2012Q1:    0.0057558     0     0   0.0057558
    2012Q2:    0.0041305     0     0   0.0041305
    2012Q3:     0.005802     0     0    0.005802
    2012Q4:    0.0068459     0     0   0.0068459
    2013Q1:            0     0     0   0.0048488
    2013Q2:            0     0     0   0.0087644
    2013Q3:            0     0     0   0.0093717
    2013Q4:            0     0     0     0.01053
    2014Q1:   -0.0024575     0     0    0.011137
    2014Q2:   -0.0028711     0     0    0.013186
    2014Q3:   -0.0030139     0     0    0.015032
    2014Q4:   -0.0030066     0     0    0.016594
    2015Q1:   -0.0030308     0     0    0.017756
    2015Q2:   -0.0021045     0     0    0.019553
    2015Q3:  -0.00050198     0     0     0.02174
    2015Q4:    0.0015545     0     0    0.024112

    'lc <--[+] all shock'    'lc <--[+] Init+Const'    'lc <--[+] Nonlinear'    'Consumption'

    user data: empty
From the result above, you can see from 2013q1 to 2013q4, all values for lc are 0s. Coincidentally, the max lag for this variable in my model is -4, so I was wondering my initial values for this variable are not taken.

As I'm writing, I noticed all my tseries in my input database for the second simulation (db_contr1) are size (dateRng*numAllShks), however, for my first simulation, all series of input database (db_shk) are size (dateRng*1). Is that where my problem is?

Thanks for your help.
Coordinator
Jun 25, 2014 at 8:27 PM
I can't reproduce the behavior -- on my computer, the init values are correctly displayed as the contributions of "Init+Const" (i.e. in the second column in your table). Could you please upload the files and also tell me what version of IRIS you use?

Thanks,
Jaromir
Coordinator
Jun 25, 2014 at 8:29 PM
And regarding the question in the last paragraph -- no, that's not the problem, that's how it is supposed to be...

J.
Jun 25, 2014 at 8:45 PM
I'm using version 20140606. I'm afraid I cannot share my model and db_fore with you. :-( I'll try to build a simple model to mimic the behavior I got.
Coordinator
Jun 25, 2014 at 8:46 PM
Sorry, now I see the problem. You actually cannot use db_contr1 as the input database into the second simulation. You must use some database that only has one single column with the proper initial conditions. For example, you can sum up the contributions in db_contr1.
Coordinator
Jun 25, 2014 at 8:49 PM
Also, the simulate command is supposed to throw an error in that case, but there was a typo, that's why it didn't complain.
Jun 25, 2014 at 8:52 PM
Thanks Jaromir. I was trying to sum up my db_contr1 and use it as input, but the result is still not as what I expected. I haven't figure out why, but I will try more.

Thank you for your help
Coordinator
Jun 25, 2014 at 8:53 PM
Try to briefly describe what the results are and what you expect. I might be able to help you understand what's going on inside the simulate command.
Jun 26, 2014 at 2:50 PM
Sorry for the delay Jaromir. I made a mistake in my code so I got result not as expected. Now everything fixed, here is my result that makes sense.
>> disp(resize([db_decomp.lc db_fore.lc], qq(2012,1):qq(2015,4)))
    tseries object: 16-by-4

    2012Q1:    0.0057558           0     0   0.0057558
    2012Q2:    0.0041305           0     0   0.0041305
     2012Q3:     0.005802           0     0    0.005802
    2012Q4:    0.0068459           0     0   0.0068459
    2013Q1:    0          0.0048488     0   0.0048488
    2013Q2:    0           0.0087644     0   0.0087644
    2013Q3:    0          0.0093717     0   0.0093717
    2013Q4:     0         0.01053     0     0.01053
    2014Q1:   -0.0024575    0.013594     0    0.011137
    2014Q2:   -0.0028711    0.016057     0    0.013186
    2014Q3:   -0.0030139    0.018046     0    0.015032
    2014Q4:   -0.0030066      0.0196     0    0.016594
    2015Q1:   -0.0030308    0.020787     0    0.017756
    2015Q2:   -0.0021045    0.021657     0    0.019553
    2015Q3:  -0.00050198    0.022242     0     0.02174
    2015Q4:    0.0015545    0.022557     0    0.024112

    'lc <--[+] all shocks'    'lc <--[+] Init+Const'    'lc <--[+] Nonlinear'    'Consumption'

    user data: empty
I'm trying to do shock decompositions, although the result above makes sense, I won't be able to have a complete picture of my shocks contributions for my whole date range as some of them became the initial conditions contributions after second simulation. The result I really want to see is as follows. Is there a way somehow to turn off initial condition contributions? Thanks.
>> disp(resize([db_decomp.lc db_fore.lc], qq(2012,1):qq(2015,4)))
    tseries object: 16-by-4

    2012Q1:    0.0057558           0     0   0.0057558
    2012Q2:    0.0041305           0     0   0.0041305
     2012Q3:     0.005802           0     0    0.005802
    2012Q4:    0.0068459           0     0   0.0068459
    2013Q1:    0.0048488          0     0   0.0048488
    2013Q2:    0.0087644           0     0   0.0087644
    2013Q3:    0.0093717          0     0   0.0093717
    2013Q4:      0.01053         0     0     0.01053
    2014Q1:    0.011137    0     0    0.011137
    2014Q2:    0.013186    0     0    0.013186
    2014Q3:   0.015032    0     0    0.015032
    2014Q4:  0.016594      0     0    0.016594
    2015Q1:    0.017756    0     0    0.017756
    2015Q2:   0.019553    0     0    0.019553
    2015Q3:  0.02174    0     0     0.02174
    2015Q4:     0.024112    0     0    0.024112

    'lc <--[+] all shocks'    'lc <--[+] Init+Const'    'lc <--[+] Nonlinear'    'Consumption'

    user data: empty
Coordinator
Jun 26, 2014 at 2:56 PM
Why don't you simply splice the db_contr1 and db_contr2 databases together, after removing the initial observations from db_contr2?
db_contr2 = dbclip(db_contr2,dateRng2);
db_contr = dboverlay(db_contr1,db_contr2);
Marked as answer by jaromirbenes on 6/26/2014 at 8:04 AM
Jun 26, 2014 at 9:15 PM
Jaromir, I'm definitely not a good explainer. :(

I'm trying to explain how much each shock contribute to my variable, say 'lc', for my whole simulation periods. For the first simulation, I can clearly explain this for dateRng1; however, after the second simulation, I cannot explain this any more, as some contributions come from 'initial conditions', which are not decomposed into shocks.

I wrote some code to do what I need, which doesn't use 'contribution' option any more. In my code, you can see db_decomp stores the contributions of each shock over the complete simulation date range, and db_allshk is the sum up of all shock contributions. Hope this will help you to understand what I'm trying to do.
dateRng = qq(1973,1):qq(2014,1) +400;
dateRng1 = qq(1973, 1):qq(2013,4);
dateRng2 = qq(2014,1):qq(2014,1) +400;

shkList = get(my_model, 'eVector');

% initialize db_allshk
db_allshk = zerodb(my_model, dateRng); 

db_decomp = struct();

for i = 1:length(shkList)

    % make a zero db
    db_shk = zerodb(my_model, dateRng); 
    % get shock from db_fore
    db_shk.(shkList{i}) = db_fore.(shkList{i});
    
    db_decomp.(shkList{i}) = ...
        simulate(my_model, db_shk, dateRng1, 'anticipate=', false, ...
          'deviation=',true, 'dboverlay=', true);
    
    db_decomp.(shkList{i}) = ...
        simulate(my_model, db_decomp.(shkList{i}), dateRng2, 'anticipate=', true, ...
          'deviation=',true, 'dboverlay=', true);   
    
    db_allshk = dbfun(@(x,y) x+y, db_allshk, db_decomp.(shkList{i}));
end