Commit ·
ed7d493
1
Parent(s): 2704016
105
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- 105/paper.pdf +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/CentralBank_gov_bonds.csv +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/CentralBank_liabilities.csv +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/Financial_Asset_Details.csv +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/Financial_Safe_Liabilities.csv +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/Government_Safe_Liabilities.csv +3 -0
- 105/replication_package/Financial balance sheets non consolidated SNA 2008/Total liabilities.csv +3 -0
- 105/replication_package/GDP/GDP_current_prices.csv +3 -0
- 105/replication_package/GENERAL_IES/Parameters.m +22 -0
- 105/replication_package/GENERAL_IES/Table_6_theta_half.m +100 -0
- 105/replication_package/GENERAL_IES/Table_6_theta_two.m +100 -0
- 105/replication_package/GENERAL_IES/correct_params.m +45 -0
- 105/replication_package/GENERAL_IES/define_model.m +152 -0
- 105/replication_package/GENERAL_IES/make_Table_6_part_1.m +44 -0
- 105/replication_package/GENERAL_IES/simulate_with_disasters.m +19 -0
- 105/replication_package/GENERAL_IES/solve_and_simulate.m +84 -0
- 105/replication_package/GENERAL_IES/summarize_results.m +61 -0
- 105/replication_package/Make_OECD_data.do +684 -0
- 105/replication_package/ReadMe.pdf +3 -0
- 105/replication_package/Replicate_Empirical_Results.do +16 -0
- 105/replication_package/Replicate_Simulation_Results.m +40 -0
- 105/replication_package/UNIT_IES/Disaster_IRF.m +46 -0
- 105/replication_package/UNIT_IES/Parameters.m +22 -0
- 105/replication_package/UNIT_IES/Table_6_MU.m +94 -0
- 105/replication_package/UNIT_IES/Table_6_NU.m +94 -0
- 105/replication_package/UNIT_IES/Table_6_P.m +94 -0
- 105/replication_package/UNIT_IES/Tranquility.m +51 -0
- 105/replication_package/UNIT_IES/correct_params.m +45 -0
- 105/replication_package/UNIT_IES/define_model.m +139 -0
- 105/replication_package/UNIT_IES/make_Table_5.m +210 -0
- 105/replication_package/UNIT_IES/make_Table_6_part_2.m +60 -0
- 105/replication_package/UNIT_IES/rep_agent.m +66 -0
- 105/replication_package/UNIT_IES/simulate_with_disasters.m +19 -0
- 105/replication_package/UNIT_IES/solve_and_simulate.m +84 -0
- 105/replication_package/UNIT_IES/summarize_results.m +56 -0
- 105/replication_package/User Guide.pdf +3 -0
- 105/replication_package/Variable_Disaster_Size/Parameters.m +46 -0
- 105/replication_package/Variable_Disaster_Size/correct_params.m +45 -0
- 105/replication_package/Variable_Disaster_Size/define_model.m +142 -0
- 105/replication_package/Variable_Disaster_Size/make_Table_7.m +200 -0
- 105/replication_package/Variable_Disaster_Size/simulate_with_disasters.m +19 -0
- 105/replication_package/Variable_Disaster_Size/solve_and_simulate.m +84 -0
- 105/replication_package/Variable_Disaster_Size/summarize_results.m +55 -0
- 105/replication_package/examples/rbc/prepare_model.m +69 -0
- 105/replication_package/examples/rbc/prepare_model_auxiliary_functions.m +127 -0
- 105/replication_package/examples/rbc/solve_continuation.m +102 -0
- 105/replication_package/examples/rbc/solve_model.m +160 -0
- 105/replication_package/examples/rbc_EZ/prepare_model.m +88 -0
- 105/replication_package/examples/rbc_EZ/prepare_model_auxiliary_functions.m +106 -0
- 105/replication_package/examples/rbc_EZ/solve_model.m +104 -0
105/paper.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f400ea5e7ad9695850fedeb786911509bc15785d2f93f9c5077b3a67df043325
|
| 3 |
+
size 881387
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/CentralBank_gov_bonds.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:847836042b8c20655ccefa8b019995882e1407948b594372a66b0056aadea271
|
| 3 |
+
size 502130
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/CentralBank_liabilities.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e64747220749fe3eae333298ff678591438ae19a9f08a1aa651c306bc9158853
|
| 3 |
+
size 1153426
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/Financial_Asset_Details.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:447da03cd373c357bdca599308266247fbe3a3115951d965cb6679dcce8a2df5
|
| 3 |
+
size 1092238
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/Financial_Safe_Liabilities.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8df4d6cfbfc9415b11754089a1e9a6278d0da1dbeb76ab85e09e8ddfda1572ac
|
| 3 |
+
size 1996412
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/Government_Safe_Liabilities.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f230d212c89375d7252466681a17d53e570673cd976d3e36dfc755d65ff4c431
|
| 3 |
+
size 1268435
|
105/replication_package/Financial balance sheets non consolidated SNA 2008/Total liabilities.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ea484dee1a87689447c1987f5b337acc86f23a02197c833105c8aa49ffe96393
|
| 3 |
+
size 6614345
|
105/replication_package/GDP/GDP_current_prices.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cea81d95092d1b07bfa92d0b08aa4c802192558d27c10848f3fc24b9cc9ae6d1
|
| 3 |
+
size 803870
|
105/replication_package/GENERAL_IES/Parameters.m
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
period_length = 0.25;
|
| 2 |
+
|
| 3 |
+
P = 1 - exp(-.04*period_length); % disaster probability
|
| 4 |
+
|
| 5 |
+
B = -log(1 - .32); % disaster size
|
| 6 |
+
|
| 7 |
+
meanB = B;
|
| 8 |
+
|
| 9 |
+
G = 0.025*period_length; % drift of log output
|
| 10 |
+
|
| 11 |
+
RHO = 0.04*period_length; % time preference rate
|
| 12 |
+
|
| 13 |
+
NU = 0.02*period_length; % replacement rate
|
| 14 |
+
|
| 15 |
+
MU = 0.05; % popoulation share of agent 1
|
| 16 |
+
|
| 17 |
+
ALPHA = 1/3; % capital share in output
|
| 18 |
+
|
| 19 |
+
TAU = 0; % bond duration - short-term bonds
|
| 20 |
+
|
| 21 |
+
GAMMA1 = 1.000001; % start with unit risk aversion
|
| 22 |
+
GAMMA2 = GAMMA1;
|
105/replication_package/GENERAL_IES/Table_6_theta_half.m
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% THETA = 0.5
|
| 2 |
+
|
| 3 |
+
load('model')
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
Parameters;
|
| 7 |
+
THETA = 0.9999; % start with THETA close to 1, for which we have a good initial guess
|
| 8 |
+
|
| 9 |
+
% make the vector of parameters
|
| 10 |
+
params = eval(symparams);
|
| 11 |
+
|
| 12 |
+
% distribution of hatyp
|
| 13 |
+
nodes = exp([G,G-B]); % hatyp
|
| 14 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 15 |
+
|
| 16 |
+
T = 2000/period_length; % simulate 2000 years
|
| 17 |
+
|
| 18 |
+
% disaster shock
|
| 19 |
+
rng('default')
|
| 20 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 21 |
+
|
| 22 |
+
GAMMA1 = 2.6;
|
| 23 |
+
GAMMA2 = GAMMA1;
|
| 24 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 26 |
+
|
| 27 |
+
% tolerance for the Newton solver
|
| 28 |
+
tolX=1e-7; tolF=1e-7; maxiter=10; testF=1e-5;
|
| 29 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 30 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 31 |
+
|
| 32 |
+
solve_and_simulate;
|
| 33 |
+
|
| 34 |
+
%% Change THETA to 0.5
|
| 35 |
+
|
| 36 |
+
THETA = 0.5;
|
| 37 |
+
newparams = params;
|
| 38 |
+
newparams(logical(symparams==sym('THETA'))) = THETA;
|
| 39 |
+
burn=1;
|
| 40 |
+
|
| 41 |
+
correct_params;
|
| 42 |
+
|
| 43 |
+
%%
|
| 44 |
+
|
| 45 |
+
GAMMA1 = 2.6;
|
| 46 |
+
GAMMA2 = 4.15;
|
| 47 |
+
|
| 48 |
+
newparams = params;
|
| 49 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 50 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 51 |
+
|
| 52 |
+
burn=1;
|
| 53 |
+
|
| 54 |
+
correct_params;
|
| 55 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 56 |
+
summarize_results;
|
| 57 |
+
|
| 58 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 59 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 60 |
+
Table_vol = [vol_roe,vol_rb];
|
| 61 |
+
|
| 62 |
+
%%%%%%%%%%%%%%%%%%%%%%%%
|
| 63 |
+
|
| 64 |
+
GAMMA1=2.5;
|
| 65 |
+
GAMMA2=4.29;
|
| 66 |
+
|
| 67 |
+
burn=1;
|
| 68 |
+
newparams=params;
|
| 69 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 70 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 71 |
+
|
| 72 |
+
correct_params;
|
| 73 |
+
|
| 74 |
+
simulate_with_disasters;
|
| 75 |
+
|
| 76 |
+
summarize_results;
|
| 77 |
+
|
| 78 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 79 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 80 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 81 |
+
|
| 82 |
+
%%%%%%%%%%%%%%%%%%%%%
|
| 83 |
+
GAMMA1=2.4;
|
| 84 |
+
GAMMA2=4.54;
|
| 85 |
+
|
| 86 |
+
newparams=params;
|
| 87 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 88 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 89 |
+
|
| 90 |
+
correct_params;
|
| 91 |
+
|
| 92 |
+
simulate_with_disasters;
|
| 93 |
+
|
| 94 |
+
summarize_results;
|
| 95 |
+
|
| 96 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 97 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 98 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 99 |
+
|
| 100 |
+
save('Table_6_theta_half','Table*')
|
105/replication_package/GENERAL_IES/Table_6_theta_two.m
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% THETA = 0.5
|
| 2 |
+
|
| 3 |
+
load('model')
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
Parameters;
|
| 7 |
+
THETA = 0.9999; % start with THETA close to 1, for which we have a good initial guess
|
| 8 |
+
|
| 9 |
+
% make the vector of parameters
|
| 10 |
+
params = eval(symparams);
|
| 11 |
+
|
| 12 |
+
% distribution of hatyp
|
| 13 |
+
nodes = exp([G,G-B]); % hatyp
|
| 14 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 15 |
+
|
| 16 |
+
T = 2000/period_length; % simulate 2000 years
|
| 17 |
+
|
| 18 |
+
% disaster shock
|
| 19 |
+
rng('default')
|
| 20 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 21 |
+
|
| 22 |
+
GAMMA1 = 2.6;
|
| 23 |
+
GAMMA2 = GAMMA1;
|
| 24 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 26 |
+
|
| 27 |
+
% tolerance for the Newton solver
|
| 28 |
+
tolX=1e-7; tolF=1e-7; maxiter=10; testF=1e-5;
|
| 29 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 30 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 31 |
+
|
| 32 |
+
solve_and_simulate;
|
| 33 |
+
|
| 34 |
+
%% Change THETA to 0.5
|
| 35 |
+
|
| 36 |
+
THETA = 2;
|
| 37 |
+
newparams = params;
|
| 38 |
+
newparams(logical(symparams==sym('THETA'))) = THETA;
|
| 39 |
+
burn=1;
|
| 40 |
+
|
| 41 |
+
correct_params;
|
| 42 |
+
|
| 43 |
+
%%
|
| 44 |
+
|
| 45 |
+
GAMMA1 = 2.6;
|
| 46 |
+
GAMMA2 = 4.15;
|
| 47 |
+
|
| 48 |
+
newparams = params;
|
| 49 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 50 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 51 |
+
|
| 52 |
+
burn=1;
|
| 53 |
+
|
| 54 |
+
correct_params;
|
| 55 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 56 |
+
summarize_results;
|
| 57 |
+
|
| 58 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 59 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 60 |
+
Table_vol = [vol_roe,vol_rb];
|
| 61 |
+
|
| 62 |
+
%%%%%%%%%%%%%%%%%%%%%%%%
|
| 63 |
+
|
| 64 |
+
GAMMA1=2.5;
|
| 65 |
+
GAMMA2=4.29;
|
| 66 |
+
|
| 67 |
+
burn=1;
|
| 68 |
+
newparams=params;
|
| 69 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 70 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 71 |
+
|
| 72 |
+
correct_params;
|
| 73 |
+
|
| 74 |
+
simulate_with_disasters;
|
| 75 |
+
|
| 76 |
+
summarize_results;
|
| 77 |
+
|
| 78 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 79 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 80 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 81 |
+
|
| 82 |
+
%%%%%%%%%%%%%%%%%%%%%
|
| 83 |
+
GAMMA1=2.4;
|
| 84 |
+
GAMMA2=4.54;
|
| 85 |
+
|
| 86 |
+
newparams=params;
|
| 87 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 88 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 89 |
+
|
| 90 |
+
correct_params;
|
| 91 |
+
|
| 92 |
+
simulate_with_disasters;
|
| 93 |
+
|
| 94 |
+
summarize_results;
|
| 95 |
+
|
| 96 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 97 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 98 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 99 |
+
|
| 100 |
+
save('Table_6_theta_two','Table*')
|
105/replication_package/GENERAL_IES/correct_params.m
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file changes the parameters gradually from their initival value to
|
| 2 |
+
% the target value
|
| 3 |
+
|
| 4 |
+
solve = 1;
|
| 5 |
+
stop = 0;
|
| 6 |
+
t = 0;
|
| 7 |
+
|
| 8 |
+
xt = state0;
|
| 9 |
+
params0 = params;
|
| 10 |
+
while stop==0
|
| 11 |
+
t = t + 1;
|
| 12 |
+
|
| 13 |
+
if t<=burn
|
| 14 |
+
factor = t/burn;
|
| 15 |
+
params = (1 - factor)*params0 + factor*newparams;
|
| 16 |
+
end
|
| 17 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 18 |
+
|
| 19 |
+
% if residuals are too large solve again
|
| 20 |
+
if norm(R(:))>testF && solve==1
|
| 21 |
+
t
|
| 22 |
+
[coeffs,model] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 23 |
+
|
| 24 |
+
% evaluate the new solution
|
| 25 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 26 |
+
end
|
| 27 |
+
|
| 28 |
+
newxt = nPhi(:,1); % assume no realized disasters
|
| 29 |
+
|
| 30 |
+
if t>burn+10 % after 10 periods start checking for convergence
|
| 31 |
+
if max(abs(newxt-xt))<1e-7
|
| 32 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 33 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 34 |
+
|
| 35 |
+
newxt = nPhi(:,1);
|
| 36 |
+
if max(abs(newxt-xt))<1e-7
|
| 37 |
+
stop = 1;
|
| 38 |
+
state0 = xt; % solution point
|
| 39 |
+
coeffs0 = coeffs;
|
| 40 |
+
end
|
| 41 |
+
end
|
| 42 |
+
end
|
| 43 |
+
xt = newxt;
|
| 44 |
+
end
|
| 45 |
+
|
105/replication_package/GENERAL_IES/define_model.m
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%-------------------------------------------------------------------------
|
| 2 |
+
% The model: Safe Assets - the case of general IES (THETA not equal 1)
|
| 3 |
+
%
|
| 4 |
+
% This file defines the model (see Appendix for the full derivation).
|
| 5 |
+
% Bonds are perfectly safe short-term assets.
|
| 6 |
+
%
|
| 7 |
+
% Variables are denoted by small letters and
|
| 8 |
+
% parameters by capital letters. Future values are denoted by suffix p.
|
| 9 |
+
%-------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
clear,clc
|
| 12 |
+
|
| 13 |
+
%% Symbolic variables
|
| 14 |
+
|
| 15 |
+
syms RHO GAMMA1 GAMMA2 NU MU THETA real
|
| 16 |
+
syms f1 f2 f1p f2p x1 x2 x1p x2p real
|
| 17 |
+
syms logq logqp tilp tilpp real
|
| 18 |
+
syms state1 state1p state2 state2p hatyp k1 tilb1 real
|
| 19 |
+
syms tila1 tila2 invtila1 invtila2 invtilp rbp rep c1 c2 c1p c2p q qp real
|
| 20 |
+
syms invc1 invc1p invc2 invc2p invf1 invf2 r1p r2p u1p_power u2p_power u1p u2p logf1 logf1p logf2 logf2p real
|
| 21 |
+
syms term1p term2p invr1p invr2p real
|
| 22 |
+
|
| 23 |
+
%% Parameters
|
| 24 |
+
|
| 25 |
+
symparams = [RHO,GAMMA1,GAMMA2,NU,MU,THETA];
|
| 26 |
+
|
| 27 |
+
%% State variables
|
| 28 |
+
|
| 29 |
+
state = [state1,state2]; % current period
|
| 30 |
+
statep = [state1p,state2p]; % future period
|
| 31 |
+
|
| 32 |
+
%% Control variables
|
| 33 |
+
|
| 34 |
+
control = [f1,f2,x1,x2,logq,tilp]; % current period
|
| 35 |
+
controlp = [f1p,f2p,x1p,x2p,logqp,tilpp]; % future period
|
| 36 |
+
|
| 37 |
+
%% shocks
|
| 38 |
+
|
| 39 |
+
shocks = hatyp;
|
| 40 |
+
|
| 41 |
+
%% auxiliary variables
|
| 42 |
+
|
| 43 |
+
logc1p = log(c1p);
|
| 44 |
+
logc2p = log(c2p);
|
| 45 |
+
|
| 46 |
+
invf1_ = 1/f1;
|
| 47 |
+
invf2_ = 1/f2;
|
| 48 |
+
|
| 49 |
+
logf1p_ = log(f1p);
|
| 50 |
+
logf2p_ = log(f2p);
|
| 51 |
+
|
| 52 |
+
invr1p_ = 1/r1p;
|
| 53 |
+
invr2p_ = 1/r2p;
|
| 54 |
+
|
| 55 |
+
q_ = exp(logq);
|
| 56 |
+
qp_ = exp(logqp);
|
| 57 |
+
|
| 58 |
+
invtila1_ = 1/tila1;
|
| 59 |
+
invtila2_ = 1/tila2;
|
| 60 |
+
|
| 61 |
+
rep_ = (1 + tilpp)/tilp*hatyp; % return on equity
|
| 62 |
+
rbp_ = 1/q; % return on bond
|
| 63 |
+
|
| 64 |
+
%% MODEL CONDITIONS
|
| 65 |
+
|
| 66 |
+
invc1_ = 1 + 1/RHO*f1^(1 - THETA);
|
| 67 |
+
|
| 68 |
+
c1_ = 1/invc1;
|
| 69 |
+
|
| 70 |
+
invc1p_ = 1 + 1/RHO*f1p^(1 - THETA);
|
| 71 |
+
|
| 72 |
+
c1p_ = 1/invc1p;
|
| 73 |
+
|
| 74 |
+
invc2_ = 1 + 1/RHO*f2^(1-THETA);
|
| 75 |
+
|
| 76 |
+
c2_ = 1/invc2;
|
| 77 |
+
|
| 78 |
+
invc2p_ = 1 + 1/RHO*f2p^(1 - THETA);
|
| 79 |
+
|
| 80 |
+
c2p_ = 1/invc2p;
|
| 81 |
+
|
| 82 |
+
tila1_ = (1 + tilp)*state1 + state2;
|
| 83 |
+
|
| 84 |
+
tila2_ = tilp + 1 - tila1;
|
| 85 |
+
|
| 86 |
+
k1_ = x1*(1 - c1)*tila1/tilp;
|
| 87 |
+
|
| 88 |
+
eq0 = -(1 - k1) + x2*(1 - c2)*tila2/tilp;
|
| 89 |
+
|
| 90 |
+
tilb1_ = (1 - x1)*(1 - c1)*tila1;
|
| 91 |
+
|
| 92 |
+
eq1 = tilb1*invtila2 + (1 - x2)*(1 - c2);
|
| 93 |
+
|
| 94 |
+
r1p_ = x1*rep + (1 - x1)*rbp;
|
| 95 |
+
|
| 96 |
+
r2p_ = x2*rep + (1 - x2)*rbp;
|
| 97 |
+
|
| 98 |
+
term1p_ = ((invc1 - 1)*r1p*invf1)^(1 - GAMMA1)*((1 - NU*(1 - MU))*u1p^(1 - GAMMA1)...
|
| 99 |
+
+ NU*(1 - MU)*u2p^(1 - GAMMA1));
|
| 100 |
+
|
| 101 |
+
term2p_ = ((invc2 - 1)*r2p*invf2)^(1 - GAMMA2)*((1 - NU*MU)*u2p^(1 - GAMMA2)...
|
| 102 |
+
+ NU*MU*u1p^(1 - GAMMA2));
|
| 103 |
+
|
| 104 |
+
eq2 = -1 + term1p;
|
| 105 |
+
|
| 106 |
+
eq3 = -1 + term2p;
|
| 107 |
+
|
| 108 |
+
u1p_power_ = RHO/(1 + RHO)*c1p^(1 - THETA) + 1/(1 + RHO)*c1p^(1 - THETA)*f1p^(1 - THETA);
|
| 109 |
+
|
| 110 |
+
u2p_power_ = RHO/(1 + RHO)*c2p^(1 - THETA) + 1/(1 + RHO)*c2p^(1 - THETA)*f2p^(1 - THETA);
|
| 111 |
+
|
| 112 |
+
u1p_ = u1p_power^(1/(1 - THETA));
|
| 113 |
+
|
| 114 |
+
u2p_ = u2p_power^(1/(1 - THETA));
|
| 115 |
+
|
| 116 |
+
eq4 = (rep - rbp)*term1p*invr1p;
|
| 117 |
+
|
| 118 |
+
eq5 = (rep - rbp)*term2p*invr2p;
|
| 119 |
+
|
| 120 |
+
%% Function f (Ef = 0 imposes model conditions)
|
| 121 |
+
|
| 122 |
+
f_fun = [eq0;eq1;eq2;eq3;eq4;eq5];
|
| 123 |
+
|
| 124 |
+
%% law of motion of state variables
|
| 125 |
+
|
| 126 |
+
Phi_fun = [k1 - NU*(k1 - MU); % law of motion of state1p
|
| 127 |
+
(1 - NU)*tilb1/(hatyp*q)]; % law of motion of state2p
|
| 128 |
+
|
| 129 |
+
%% collect auxiliary variables and functions
|
| 130 |
+
|
| 131 |
+
allvars=who;
|
| 132 |
+
auxfuns=[];
|
| 133 |
+
auxvars=[];
|
| 134 |
+
for i=1:length(allvars)
|
| 135 |
+
if strcmp(allvars{i}(end),'_')
|
| 136 |
+
eval(['tempfun=' allvars{i} ';'])
|
| 137 |
+
eval(['tempvar=' allvars{i}(1:end-1) ';'])
|
| 138 |
+
auxfuns=[auxfuns;tempfun];
|
| 139 |
+
auxvars=[auxvars;tempvar];
|
| 140 |
+
end
|
| 141 |
+
end
|
| 142 |
+
|
| 143 |
+
%% Approximation order (<=4)
|
| 144 |
+
|
| 145 |
+
order = 4;
|
| 146 |
+
|
| 147 |
+
%% Preprocess model and save
|
| 148 |
+
|
| 149 |
+
model = prepare_tp(f_fun,Phi_fun,controlp,control,statep,state,shocks,symparams,order,auxfuns,auxvars);
|
| 150 |
+
|
| 151 |
+
save('model')
|
| 152 |
+
|
105/replication_package/GENERAL_IES/make_Table_6_part_1.m
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Table_6_theta_half;
|
| 2 |
+
Table_6_theta_two;
|
| 3 |
+
|
| 4 |
+
%% Display Table 6 (part 1)
|
| 5 |
+
clc
|
| 6 |
+
homefolder = pwd;
|
| 7 |
+
cd ..
|
| 8 |
+
|
| 9 |
+
diary on
|
| 10 |
+
|
| 11 |
+
disp('********** Table 6 **********')
|
| 12 |
+
|
| 13 |
+
load([homefolder '\Table_6_theta_half'])
|
| 14 |
+
|
| 15 |
+
Table_6 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)];
|
| 16 |
+
|
| 17 |
+
disp('THETA = 0.5')
|
| 18 |
+
disp(Table_6(3,:))
|
| 19 |
+
|
| 20 |
+
load([homefolder '\Table_6_theta_two'])
|
| 21 |
+
|
| 22 |
+
Table_6 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)];
|
| 23 |
+
|
| 24 |
+
disp('THETA = 2')
|
| 25 |
+
disp(Table_6(3,:))
|
| 26 |
+
|
| 27 |
+
%% Accuracy Measures
|
| 28 |
+
disp('Appendix Table 2: Accuracy Measures for Table 6')
|
| 29 |
+
|
| 30 |
+
load([homefolder '\Table_6_theta_half'])
|
| 31 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 32 |
+
|
| 33 |
+
disp('THETA = 0.5')
|
| 34 |
+
disp(Accuarcy(3,2:end))
|
| 35 |
+
|
| 36 |
+
load([homefolder '\Table_6_theta_two'])
|
| 37 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 38 |
+
|
| 39 |
+
disp('THETA = 2')
|
| 40 |
+
disp(Accuarcy(3,2:end))
|
| 41 |
+
|
| 42 |
+
diary off
|
| 43 |
+
|
| 44 |
+
cd(homefolder)
|
105/replication_package/GENERAL_IES/simulate_with_disasters.m
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Simulate with disasters
|
| 2 |
+
y_results = zeros(model.n_y,T+1);
|
| 3 |
+
x_results = zeros(model.n_x,T+1);
|
| 4 |
+
R_results = zeros(model.n_f,T+1);
|
| 5 |
+
|
| 6 |
+
x_results(:,1) = state0;
|
| 7 |
+
|
| 8 |
+
for t = 1:T
|
| 9 |
+
t
|
| 10 |
+
xt = x_results(:,t);
|
| 11 |
+
|
| 12 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 13 |
+
|
| 14 |
+
% store results
|
| 15 |
+
R_results(:,t) = R;
|
| 16 |
+
y_results(:,t) = g;
|
| 17 |
+
|
| 18 |
+
x_results(:,t+1) = nPhi(:,disaster(t+1));
|
| 19 |
+
end
|
105/replication_package/GENERAL_IES/solve_and_simulate.m
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file performs the following:
|
| 2 |
+
% 1. Solve the model by Taylor projection at the initial state.
|
| 3 |
+
% 2. Simulate the model without realized disasters.
|
| 4 |
+
|
| 5 |
+
%% make initial guess for a deterministic version of the model
|
| 6 |
+
|
| 7 |
+
% in a deterministic economy, the following variables are constant:
|
| 8 |
+
|
| 9 |
+
x1 = 1; % agents invests only in equity
|
| 10 |
+
x2 = 1;
|
| 11 |
+
tilp = 1/RHO; % price/earning ratio
|
| 12 |
+
hatyp = exp(G-meanB*P); % average growth
|
| 13 |
+
haty = hatyp;
|
| 14 |
+
rep = (1+tilp)/tilp*hatyp; % asset return
|
| 15 |
+
logq = log(1/rep); % price of bond
|
| 16 |
+
c1 = RHO/(1+RHO); % consumption/wealth ratio
|
| 17 |
+
c2 = c1;
|
| 18 |
+
logu1 = (RHO*log(c1)+log(1-c1)+log(rep))/RHO;
|
| 19 |
+
u1 = exp(logu1);
|
| 20 |
+
logu2 = (RHO*log(c2)+log(1-c2)+log(rep))/RHO;
|
| 21 |
+
u2 = exp(logu2);
|
| 22 |
+
f1 = (rep*u1);
|
| 23 |
+
f2 = (rep*u2);
|
| 24 |
+
|
| 25 |
+
k1 = MU;
|
| 26 |
+
|
| 27 |
+
tila1 = k1*(1+tilp);
|
| 28 |
+
|
| 29 |
+
state0 = [k1;0];
|
| 30 |
+
c0 = state0;
|
| 31 |
+
|
| 32 |
+
derivs0 = [f1;f2;x1;x2;logq;tilp];
|
| 33 |
+
|
| 34 |
+
derivs1 = zeros(model.n_f,model.n_x);
|
| 35 |
+
derivs2 = zeros(model.n_f,model.n_x^2);
|
| 36 |
+
derivs3 = zeros(model.n_f,model.n_x^3);
|
| 37 |
+
derivs4 = zeros(model.n_f,model.n_x^4);
|
| 38 |
+
|
| 39 |
+
if order==1
|
| 40 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1 );
|
| 41 |
+
elseif order==2
|
| 42 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2);
|
| 43 |
+
elseif order==3
|
| 44 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3 );
|
| 45 |
+
elseif order==4
|
| 46 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3,derivs4 );
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
%% solve the model
|
| 50 |
+
|
| 51 |
+
[coeffs,model] = tpsolve(initial_guess,state0,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 52 |
+
|
| 53 |
+
%% simulate the model
|
| 54 |
+
|
| 55 |
+
solve = 1;
|
| 56 |
+
stop = 0;
|
| 57 |
+
t = 0;
|
| 58 |
+
xt = state0;
|
| 59 |
+
while stop==0
|
| 60 |
+
t = t+1;
|
| 61 |
+
% evaluate the previous solution at the new point xt
|
| 62 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 63 |
+
|
| 64 |
+
% if residuals are too large solve again
|
| 65 |
+
if norm(R(:))>testF && solve==1
|
| 66 |
+
t
|
| 67 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 68 |
+
|
| 69 |
+
% evaluate the new solution
|
| 70 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 71 |
+
end
|
| 72 |
+
|
| 73 |
+
newxt = nPhi(:,disaster(t+1)); % new state
|
| 74 |
+
|
| 75 |
+
if t>=10 % after 10 periods start checking for convergence
|
| 76 |
+
if max(abs(newxt-xt))<1e-7
|
| 77 |
+
stop = 1;
|
| 78 |
+
state0 = xt;
|
| 79 |
+
coeffs0 = coeffs;
|
| 80 |
+
end
|
| 81 |
+
end
|
| 82 |
+
xt = newxt;
|
| 83 |
+
end
|
| 84 |
+
|
105/replication_package/GENERAL_IES/summarize_results.m
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
normal = logical(disaster==1); % normal periods
|
| 3 |
+
d = logical(disaster>1); % disaster periods
|
| 4 |
+
|
| 5 |
+
state1 = x_results(1,1:T);
|
| 6 |
+
state2 = x_results(2,1:T);
|
| 7 |
+
|
| 8 |
+
f1 = y_results(1,1:T);
|
| 9 |
+
x1 = y_results(3,1:T);
|
| 10 |
+
logq = y_results(5,1:T);
|
| 11 |
+
tilp=y_results(6,1:T);
|
| 12 |
+
|
| 13 |
+
invc1 = 1 + 1/RHO*f1.^(1 - THETA);
|
| 14 |
+
c1 = 1./invc1;
|
| 15 |
+
|
| 16 |
+
q = exp(logq);
|
| 17 |
+
|
| 18 |
+
tila1 = (1 + tilp).*state1(1:T) + state2(1:T);
|
| 19 |
+
|
| 20 |
+
k1 = x1.*(1 - c1).*tila1./tilp;
|
| 21 |
+
tilb1 = (1 - x1).*(1 - c1).*tila1;
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
W1_share = k1 - NU*(k1 - MU) + (1 - NU)*tilb1./tilp; % wealth share after type changes
|
| 25 |
+
equity = k1 - NU*(k1 - MU);
|
| 26 |
+
|
| 27 |
+
debt_to_assets = -(1 - NU)*tilb1./tilp; % debt ratio (after type changes)
|
| 28 |
+
debt_to_GDP = -(1 - NU)*tilb1*period_length;
|
| 29 |
+
|
| 30 |
+
haty = nodes(1,double(disaster(1:T)));
|
| 31 |
+
|
| 32 |
+
% compute means by iterated expectations
|
| 33 |
+
|
| 34 |
+
roe = ((1 + tilp(2:T))./tilp(1:T-1).*haty(2:T)); % this is actual return from t to t+1.
|
| 35 |
+
mean_roe = 1/period_length*log((1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)))); % mean return
|
| 36 |
+
|
| 37 |
+
period_mean_roe = (1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)));
|
| 38 |
+
period_var_roe = (1-P)*mean((roe(normal(2:T)) - period_mean_roe).^2)+P*mean((roe(d(2:T)) - period_mean_roe).^2);
|
| 39 |
+
vol_roe = sqrt(period_var_roe/period_length);
|
| 40 |
+
|
| 41 |
+
rb = log(1./q(1:T-1))/period_length; % this is log return on bonds
|
| 42 |
+
mean_rb = (1-P)*mean(rb(normal(1:T-1)))+P*mean(rb(d(1:T-1)));
|
| 43 |
+
|
| 44 |
+
Rb = 1./q(2:T-1);
|
| 45 |
+
period_mean_rb = (1-P)*mean(Rb(normal(2:T-1)))+P*mean(Rb(d(2:T-1)));
|
| 46 |
+
period_var_rb = (1-P)*mean((Rb(normal(2:T-1)) - period_mean_rb).^2)+P*mean((Rb(d(2:T-1)) - period_mean_rb).^2);
|
| 47 |
+
vol_rb = sqrt(period_var_rb/period_length);
|
| 48 |
+
|
| 49 |
+
mean_equity = (1-P)*mean(equity(normal(1:T))) + P*mean(equity(d(1:T)));
|
| 50 |
+
mean_debt_to_assets = (1-P)*mean(debt_to_assets(normal(1:T))) + P*mean(debt_to_assets(d(1:T)));
|
| 51 |
+
mean_debt_to_GDP = (1-P)*mean(debt_to_GDP(normal(1:T))) + P*mean(debt_to_GDP(d(1:T)));
|
| 52 |
+
mean_W1_share = (1-P)*mean(W1_share(normal(1:T))) + P*mean(W1_share(d(1:T)));
|
| 53 |
+
|
| 54 |
+
% mean_W1_share_excluding_labor = mean_W1_share*(1+L) - MU*L;
|
| 55 |
+
% mean_debt_to_assets_excluding_labor = mean_debt_to_assets*(1+L);
|
| 56 |
+
% mean_debt_to_GDP_including_labor = mean_debt_to_GDP/(1+L);
|
| 57 |
+
% mean_equity_excluding_labor = mean_equity*(1+L) - MU*L;
|
| 58 |
+
|
| 59 |
+
mean_equity_excluding_labor = mean_equity/ALPHA - MU*(1 - ALPHA)/ALPHA;
|
| 60 |
+
mean_debt_to_assets_excluding_labor = mean_debt_to_assets/ALPHA;
|
| 61 |
+
mean_W1_share_excluding_labor = mean_equity_excluding_labor - mean_debt_to_assets_excluding_labor;
|
105/replication_package/Make_OECD_data.do
ADDED
|
@@ -0,0 +1,684 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
clear
|
| 2 |
+
|
| 3 |
+
*set matsize 3000
|
| 4 |
+
set matsize 800
|
| 5 |
+
clear mata
|
| 6 |
+
set mem 500m
|
| 7 |
+
set more off
|
| 8 |
+
set logtype text
|
| 9 |
+
capture log close
|
| 10 |
+
*set linesize 255
|
| 11 |
+
|
| 12 |
+
// IMPORTANT!!! change working directory to the folder of this file
|
| 13 |
+
|
| 14 |
+
* cd "folder name"
|
| 15 |
+
|
| 16 |
+
// GDP current prices
|
| 17 |
+
clear
|
| 18 |
+
|
| 19 |
+
local folder="GDP"
|
| 20 |
+
|
| 21 |
+
insheet using "`folder'\GDP_current_prices.csv", n c case
|
| 22 |
+
|
| 23 |
+
des
|
| 24 |
+
|
| 25 |
+
tab PowerCode /* all number in millions */
|
| 26 |
+
tab Measure /* two types of measures - current price and ppp */
|
| 27 |
+
tab Transaction
|
| 28 |
+
|
| 29 |
+
keep if Measure=="Current prices"
|
| 30 |
+
|
| 31 |
+
keep Country Year Value
|
| 32 |
+
|
| 33 |
+
rename Value GDP
|
| 34 |
+
|
| 35 |
+
rename Country country
|
| 36 |
+
rename Year year
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
label var GDP "GDP current prices, Million of national currency"
|
| 40 |
+
|
| 41 |
+
save GDP, replace
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
// Step 1: make dataset.dta
|
| 45 |
+
|
| 46 |
+
clear
|
| 47 |
+
|
| 48 |
+
local folder="Financial balance sheets non consolidated SNA 2008"
|
| 49 |
+
|
| 50 |
+
* Total liabilities - all sectors
|
| 51 |
+
|
| 52 |
+
insheet using "`folder'\Total liabilities.csv", n c case
|
| 53 |
+
|
| 54 |
+
des
|
| 55 |
+
|
| 56 |
+
tab PowerCode /* all number in millions */
|
| 57 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 58 |
+
tab Transaction
|
| 59 |
+
|
| 60 |
+
keep if Measure=="National currency, current prices"
|
| 61 |
+
|
| 62 |
+
keep Country Sector Time Value
|
| 63 |
+
|
| 64 |
+
rename Time Year
|
| 65 |
+
rename Value totliab
|
| 66 |
+
|
| 67 |
+
gen Sec=""
|
| 68 |
+
|
| 69 |
+
replace Sec="Total" if Sector=="Total economy"
|
| 70 |
+
replace Sec="World" if Sector=="Rest of the world"
|
| 71 |
+
replace Sec="Households" if Sector=="Households and NPISH"
|
| 72 |
+
replace Sec="Financials" if Sector=="Financial corporations"
|
| 73 |
+
replace Sec="nonFinancials" if Sector=="Non-financial corporations"
|
| 74 |
+
replace Sec="Gov" if Sector=="General Government"
|
| 75 |
+
|
| 76 |
+
keep if Sec~=""
|
| 77 |
+
|
| 78 |
+
keep Country Year Sec totliab
|
| 79 |
+
|
| 80 |
+
rename Country country
|
| 81 |
+
rename Year year
|
| 82 |
+
rename Sec sector
|
| 83 |
+
rename totliab totliab_
|
| 84 |
+
|
| 85 |
+
reshape wide totliab_, i(country year) j(sector) string
|
| 86 |
+
|
| 87 |
+
label var totliab_Total "Tota Liabilities - Total Economy"
|
| 88 |
+
label var totliab_World "Tota Liabilities - Rest of the World"
|
| 89 |
+
label var totliab_Households "Tota Liabilities - Households and NPISH"
|
| 90 |
+
label var totliab_Financials "Tota Liabilities - Financial corporations"
|
| 91 |
+
label var totliab_nonFinancials "Tota Liabilities - Non-financial corporations"
|
| 92 |
+
|
| 93 |
+
save total_liabilities, replace
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
//* Financial Corporations - safe liabilities
|
| 97 |
+
clear
|
| 98 |
+
|
| 99 |
+
insheet using "`folder'\Financial_Safe_Liabilities.csv", n c case
|
| 100 |
+
|
| 101 |
+
des
|
| 102 |
+
|
| 103 |
+
tab PowerCode /* all number in millions */
|
| 104 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 105 |
+
tab Transaction
|
| 106 |
+
tab Sector /* only financial corporations */
|
| 107 |
+
|
| 108 |
+
keep if Measure=="National currency, current prices" & Sector=="Financial corporations"
|
| 109 |
+
|
| 110 |
+
keep Country Time Transaction Value
|
| 111 |
+
|
| 112 |
+
gen tran=""
|
| 113 |
+
|
| 114 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 115 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 116 |
+
replace tran="loan" if Transaction=="Loans"
|
| 117 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 118 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 119 |
+
|
| 120 |
+
drop if tran==""
|
| 121 |
+
|
| 122 |
+
keep Country Time tran Value
|
| 123 |
+
rename Country country
|
| 124 |
+
rename Time year
|
| 125 |
+
rename Value fin_
|
| 126 |
+
|
| 127 |
+
reshape wide fin_, i(country year) j(tran) string
|
| 128 |
+
|
| 129 |
+
label var fin_dep "Currency and deposits - Financial corporations"
|
| 130 |
+
label var fin_secur "Debt securities - Financial corporations"
|
| 131 |
+
label var fin_loan "Loans - Financial corporations"
|
| 132 |
+
label var fin_mmf "Money market fund shares /units - Financial corporations"
|
| 133 |
+
label var fin_trade "Trade credits and advances - Financial corporations"
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
save financials_safe_items, replace
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
//* General Government - safe liabilities
|
| 140 |
+
|
| 141 |
+
clear
|
| 142 |
+
|
| 143 |
+
insheet using "`folder'\Government_Safe_Liabilities.csv", n c case
|
| 144 |
+
|
| 145 |
+
des
|
| 146 |
+
|
| 147 |
+
tab PowerCode /* all number in millions */
|
| 148 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 149 |
+
tab Transaction
|
| 150 |
+
tab Sector /* only general government */
|
| 151 |
+
|
| 152 |
+
keep if Measure=="National currency, current prices" & Sector=="General Government"
|
| 153 |
+
|
| 154 |
+
keep Country Time Transaction Value
|
| 155 |
+
|
| 156 |
+
gen tran=""
|
| 157 |
+
|
| 158 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 159 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 160 |
+
replace tran="loan" if Transaction=="Loans"
|
| 161 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 162 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 163 |
+
|
| 164 |
+
drop if tran==""
|
| 165 |
+
|
| 166 |
+
keep Country Time tran Value
|
| 167 |
+
rename Country country
|
| 168 |
+
rename Time year
|
| 169 |
+
rename Value gov_
|
| 170 |
+
|
| 171 |
+
reshape wide gov_, i(country year) j(tran) string
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
label var gov_dep "Currency and deposits - General Government"
|
| 175 |
+
label var gov_secur "Debt securities - General Government"
|
| 176 |
+
label var gov_loan "Loans - General Government"
|
| 177 |
+
label var gov_mmf "Money market fund shares /units - General Government"
|
| 178 |
+
label var gov_trade "Trade credits and advances - General Government"
|
| 179 |
+
|
| 180 |
+
save government_safe_items, replace
|
| 181 |
+
|
| 182 |
+
//* Central bank holdings of bonds (assume most of these holdings are government bonds)
|
| 183 |
+
|
| 184 |
+
clear
|
| 185 |
+
|
| 186 |
+
insheet using "`folder'\CentralBank_gov_bonds.csv", n c case
|
| 187 |
+
|
| 188 |
+
des
|
| 189 |
+
|
| 190 |
+
tab PowerCode /* all number in millions */
|
| 191 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 192 |
+
tab Transaction
|
| 193 |
+
tab Sector /* only general government */
|
| 194 |
+
|
| 195 |
+
keep if Measure=="National currency, current prices" & Sector=="Central Bank"
|
| 196 |
+
|
| 197 |
+
keep Country Time Transaction Value
|
| 198 |
+
|
| 199 |
+
gen tran=""
|
| 200 |
+
|
| 201 |
+
replace tran="lbond" if Transaction=="Long-term debt securities"
|
| 202 |
+
replace tran="sbond" if Transaction=="Short-term debt securities"
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
drop if tran==""
|
| 206 |
+
|
| 207 |
+
keep Country Time tran Value
|
| 208 |
+
rename Country country
|
| 209 |
+
rename Time year
|
| 210 |
+
rename Value cb_
|
| 211 |
+
|
| 212 |
+
reshape wide cb_, i(country year) j(tran) string
|
| 213 |
+
|
| 214 |
+
save central_bank_bonds, replace
|
| 215 |
+
|
| 216 |
+
//* Central bank - safe and total liabilities
|
| 217 |
+
|
| 218 |
+
clear
|
| 219 |
+
|
| 220 |
+
insheet using "`folder'\CentralBank_liabilities.csv", n c case
|
| 221 |
+
|
| 222 |
+
des
|
| 223 |
+
|
| 224 |
+
tab PowerCode /* all number in millions */
|
| 225 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 226 |
+
tab Transaction
|
| 227 |
+
tab Sector /* only Central Bank */
|
| 228 |
+
|
| 229 |
+
keep if Measure=="National currency, current prices" & Sector=="Central Bank"
|
| 230 |
+
|
| 231 |
+
keep Country Time Transaction Value
|
| 232 |
+
|
| 233 |
+
gen tran=""
|
| 234 |
+
|
| 235 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 236 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 237 |
+
replace tran="loan" if Transaction=="Loans"
|
| 238 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 239 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 240 |
+
replace tran="totliab_Total" if Transaction=="Financial liabilities"
|
| 241 |
+
|
| 242 |
+
drop if tran==""
|
| 243 |
+
|
| 244 |
+
keep Country Time tran Value
|
| 245 |
+
rename Country country
|
| 246 |
+
rename Time year
|
| 247 |
+
rename Value cb_
|
| 248 |
+
|
| 249 |
+
reshape wide cb_, i(country year) j(tran) string
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
label var cb_dep "Currency and deposits - Central Bank"
|
| 253 |
+
label var cb_secur "Debt securities - Central Bank"
|
| 254 |
+
label var cb_loan "Loans - Central Bank"
|
| 255 |
+
label var cb_mmf "Money market fund shares /units - Central Bank"
|
| 256 |
+
label var cb_trade "Trade credits and advances - Central Bank"
|
| 257 |
+
label var cb_totliab_Total "Financial liabilities - Central Bank"
|
| 258 |
+
|
| 259 |
+
save cb_safe_items, replace
|
| 260 |
+
|
| 261 |
+
clear
|
| 262 |
+
|
| 263 |
+
use total_liabilities, replace
|
| 264 |
+
|
| 265 |
+
joinby country year using financials_safe_items, unmatched(both)
|
| 266 |
+
cap drop _merge
|
| 267 |
+
|
| 268 |
+
joinby country year using government_safe_items, unmatched(both)
|
| 269 |
+
cap drop _merge
|
| 270 |
+
|
| 271 |
+
joinby country year using central_bank_bonds, unmatched(both)
|
| 272 |
+
cap drop _merge
|
| 273 |
+
|
| 274 |
+
joinby country year using GDP, unmatched(master)
|
| 275 |
+
cap drop _merge
|
| 276 |
+
|
| 277 |
+
joinby country year using cb_safe_items, unmatched(master)
|
| 278 |
+
cap drop _merge
|
| 279 |
+
|
| 280 |
+
* replace missing values with zeros
|
| 281 |
+
foreach var of varlist fin_* gov_* cb_* {
|
| 282 |
+
replace `var'=0 if `var'==.
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
label var cb_lbond "Long-term debt securities held by the central bank"
|
| 286 |
+
label var cb_sbond "Short-term debt securities held by the central bank"
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
encode country, gen(countrys)
|
| 290 |
+
|
| 291 |
+
drop country
|
| 292 |
+
rename countrys country
|
| 293 |
+
|
| 294 |
+
tsset country year
|
| 295 |
+
|
| 296 |
+
save dataset, replace
|
| 297 |
+
|
| 298 |
+
//* Compute variables in USD
|
| 299 |
+
* Total liabilities - all sectors
|
| 300 |
+
|
| 301 |
+
clear
|
| 302 |
+
|
| 303 |
+
insheet using "`folder'\Total liabilities.csv", n c case
|
| 304 |
+
|
| 305 |
+
des
|
| 306 |
+
|
| 307 |
+
tab PowerCode /* all number in millions */
|
| 308 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 309 |
+
tab Transaction
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
*keep if Measure=="National currency, current prices"
|
| 313 |
+
keep if Measure=="US $, current prices, current exchange rates, end of period"
|
| 314 |
+
|
| 315 |
+
keep Country Sector Time Value
|
| 316 |
+
|
| 317 |
+
rename Time Year
|
| 318 |
+
rename Value totliab
|
| 319 |
+
|
| 320 |
+
gen Sec=""
|
| 321 |
+
|
| 322 |
+
replace Sec="Total" if Sector=="Total economy"
|
| 323 |
+
replace Sec="World" if Sector=="Rest of the world"
|
| 324 |
+
replace Sec="Households" if Sector=="Households and NPISH"
|
| 325 |
+
replace Sec="Financials" if Sector=="Financial corporations"
|
| 326 |
+
replace Sec="nonFinancials" if Sector=="Non-financial corporations"
|
| 327 |
+
replace Sec="Gov" if Sector=="General Government"
|
| 328 |
+
|
| 329 |
+
keep if Sec~=""
|
| 330 |
+
|
| 331 |
+
keep Country Year Sec totliab
|
| 332 |
+
|
| 333 |
+
rename Country country
|
| 334 |
+
rename Year year
|
| 335 |
+
rename Sec sector
|
| 336 |
+
rename totliab totliab_
|
| 337 |
+
|
| 338 |
+
reshape wide totliab_, i(country year) j(sector) string
|
| 339 |
+
|
| 340 |
+
label var totliab_Total "Tota Liabilities - Total Economy"
|
| 341 |
+
label var totliab_World "Tota Liabilities - Rest of the World"
|
| 342 |
+
label var totliab_Households "Tota Liabilities - Households and NPISH"
|
| 343 |
+
label var totliab_Financials "Tota Liabilities - Financial corporations"
|
| 344 |
+
label var totliab_nonFinancials "Tota Liabilities - Non-financial corporations"
|
| 345 |
+
|
| 346 |
+
save total_liabilitiesUSD, replace
|
| 347 |
+
|
| 348 |
+
*/
|
| 349 |
+
|
| 350 |
+
//* Financial Corporations - safe liabilities
|
| 351 |
+
clear
|
| 352 |
+
|
| 353 |
+
insheet using "`folder'\Financial_Safe_Liabilities.csv", n c case
|
| 354 |
+
|
| 355 |
+
des
|
| 356 |
+
|
| 357 |
+
tab PowerCode /* all number in millions */
|
| 358 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 359 |
+
tab Transaction
|
| 360 |
+
tab Sector /* only financial corporations */
|
| 361 |
+
|
| 362 |
+
*keep if Measure=="National currency, current prices" & Sector=="Financial corporations"
|
| 363 |
+
keep if Measure=="US $, current prices, current exchange rates, end of period"
|
| 364 |
+
|
| 365 |
+
keep Country Time Transaction Value
|
| 366 |
+
|
| 367 |
+
gen tran=""
|
| 368 |
+
|
| 369 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 370 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 371 |
+
replace tran="loan" if Transaction=="Loans"
|
| 372 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 373 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 374 |
+
|
| 375 |
+
drop if tran==""
|
| 376 |
+
|
| 377 |
+
keep Country Time tran Value
|
| 378 |
+
rename Country country
|
| 379 |
+
rename Time year
|
| 380 |
+
rename Value fin_
|
| 381 |
+
|
| 382 |
+
reshape wide fin_, i(country year) j(tran) string
|
| 383 |
+
|
| 384 |
+
label var fin_dep "Currency and deposits - Financial corporations"
|
| 385 |
+
label var fin_secur "Debt securities - Financial corporations"
|
| 386 |
+
label var fin_loan "Loans - Financial corporations"
|
| 387 |
+
label var fin_mmf "Money market fund shares /units - Financial corporations"
|
| 388 |
+
label var fin_trade "Trade credits and advances - Financial corporations"
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
save financials_safe_itemsUSD, replace
|
| 392 |
+
|
| 393 |
+
//* General Government - safe liabilities
|
| 394 |
+
|
| 395 |
+
clear
|
| 396 |
+
|
| 397 |
+
insheet using "`folder'\Government_Safe_Liabilities.csv", n c case
|
| 398 |
+
|
| 399 |
+
des
|
| 400 |
+
|
| 401 |
+
tab PowerCode /* all number in millions */
|
| 402 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 403 |
+
tab Transaction
|
| 404 |
+
tab Sector /* only general government */
|
| 405 |
+
|
| 406 |
+
*keep if Measure=="National currency, current prices" & Sector=="General Government"
|
| 407 |
+
keep if Measure=="US $, current prices, current exchange rates, end of period"
|
| 408 |
+
|
| 409 |
+
keep Country Time Transaction Value
|
| 410 |
+
|
| 411 |
+
gen tran=""
|
| 412 |
+
|
| 413 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 414 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 415 |
+
replace tran="loan" if Transaction=="Loans"
|
| 416 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 417 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 418 |
+
|
| 419 |
+
drop if tran==""
|
| 420 |
+
|
| 421 |
+
keep Country Time tran Value
|
| 422 |
+
rename Country country
|
| 423 |
+
rename Time year
|
| 424 |
+
rename Value gov_
|
| 425 |
+
|
| 426 |
+
reshape wide gov_, i(country year) j(tran) string
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
label var gov_dep "Currency and deposits - General Government"
|
| 430 |
+
label var gov_secur "Debt securities - General Government"
|
| 431 |
+
label var gov_loan "Loans - General Government"
|
| 432 |
+
label var gov_mmf "Money market fund shares /units - General Government"
|
| 433 |
+
label var gov_trade "Trade credits and advances - General Government"
|
| 434 |
+
|
| 435 |
+
save government_safe_itemsUSD, replace
|
| 436 |
+
|
| 437 |
+
|
| 438 |
+
//* Central bank holdings of bonds (assume most of these holdings are government bonds)
|
| 439 |
+
|
| 440 |
+
clear
|
| 441 |
+
|
| 442 |
+
insheet using "`folder'\CentralBank_gov_bonds.csv", n c case
|
| 443 |
+
|
| 444 |
+
des
|
| 445 |
+
|
| 446 |
+
tab PowerCode /* all number in millions */
|
| 447 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 448 |
+
tab Transaction
|
| 449 |
+
tab Sector /* only general government */
|
| 450 |
+
|
| 451 |
+
*keep if Measure=="National currency, current prices" & Sector=="Central Bank"
|
| 452 |
+
keep if Measure=="US $, current prices, current exchange rates, end of period"
|
| 453 |
+
|
| 454 |
+
keep Country Time Transaction Value
|
| 455 |
+
|
| 456 |
+
gen tran=""
|
| 457 |
+
|
| 458 |
+
replace tran="lbond" if Transaction=="Long-term debt securities"
|
| 459 |
+
replace tran="sbond" if Transaction=="Short-term debt securities"
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
drop if tran==""
|
| 463 |
+
|
| 464 |
+
keep Country Time tran Value
|
| 465 |
+
rename Country country
|
| 466 |
+
rename Time year
|
| 467 |
+
rename Value cb_
|
| 468 |
+
|
| 469 |
+
reshape wide cb_, i(country year) j(tran) string
|
| 470 |
+
|
| 471 |
+
save central_bank_bondsUSD, replace
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
//* Central bank - safe and total liabilities
|
| 475 |
+
|
| 476 |
+
clear
|
| 477 |
+
|
| 478 |
+
insheet using "`folder'\CentralBank_liabilities.csv", n c case
|
| 479 |
+
|
| 480 |
+
des
|
| 481 |
+
|
| 482 |
+
tab PowerCode /* all number in millions */
|
| 483 |
+
tab Measure /* two types of measures - national currency and USD */
|
| 484 |
+
tab Transaction
|
| 485 |
+
tab Sector /* only Central Bank */
|
| 486 |
+
|
| 487 |
+
*keep if Measure=="National currency, current prices" & Sector=="Central Bank"
|
| 488 |
+
keep if Measure=="US $, current prices, current exchange rates, end of period"
|
| 489 |
+
|
| 490 |
+
keep Country Time Transaction Value
|
| 491 |
+
|
| 492 |
+
gen tran=""
|
| 493 |
+
|
| 494 |
+
replace tran="dep" if Transaction=="Currency and deposits"
|
| 495 |
+
replace tran="secur" if Transaction=="Debt securities"
|
| 496 |
+
replace tran="loan" if Transaction=="Loans"
|
| 497 |
+
replace tran="mmf" if Transaction=="Money market fund shares /units"
|
| 498 |
+
replace tran="trade" if Transaction=="Trade credits and advances"
|
| 499 |
+
replace tran="totliab_Total" if Transaction=="Financial liabilities"
|
| 500 |
+
|
| 501 |
+
drop if tran==""
|
| 502 |
+
|
| 503 |
+
keep Country Time tran Value
|
| 504 |
+
rename Country country
|
| 505 |
+
rename Time year
|
| 506 |
+
rename Value cb_
|
| 507 |
+
|
| 508 |
+
reshape wide cb_, i(country year) j(tran) string
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
label var cb_dep "Currency and deposits - Central Bank"
|
| 512 |
+
label var cb_secur "Debt securities - Central Bank"
|
| 513 |
+
label var cb_loan "Loans - Central Bank"
|
| 514 |
+
label var cb_mmf "Money market fund shares /units - Central Bank"
|
| 515 |
+
label var cb_trade "Trade credits and advances - Central Bank"
|
| 516 |
+
label var cb_totliab_Total "Financial liabilities - Central Bank"
|
| 517 |
+
|
| 518 |
+
save cb_safe_itemsUSD, replace
|
| 519 |
+
|
| 520 |
+
***
|
| 521 |
+
|
| 522 |
+
clear
|
| 523 |
+
|
| 524 |
+
use total_liabilitiesUSD, replace
|
| 525 |
+
|
| 526 |
+
joinby country year using financials_safe_itemsUSD, unmatched(both)
|
| 527 |
+
cap drop _merge
|
| 528 |
+
|
| 529 |
+
joinby country year using government_safe_itemsUSD, unmatched(both)
|
| 530 |
+
cap drop _merge
|
| 531 |
+
|
| 532 |
+
joinby country year using central_bank_bondsUSD, unmatched(both)
|
| 533 |
+
cap drop _merge
|
| 534 |
+
|
| 535 |
+
joinby country year using cb_safe_itemsUSD, unmatched(both)
|
| 536 |
+
cap drop _merge
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
* replace missing values with zeros
|
| 540 |
+
foreach var of varlist fin_* gov_* cb_* {
|
| 541 |
+
replace `var'=0 if `var'==.
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
label var cb_lbond "Long-term debt securities held by the central bank"
|
| 545 |
+
label var cb_sbond "Short-term debt securities held by the central bank"
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
encode country, gen(countrys)
|
| 549 |
+
|
| 550 |
+
drop country
|
| 551 |
+
rename countrys country
|
| 552 |
+
|
| 553 |
+
tsset country year
|
| 554 |
+
|
| 555 |
+
save datasetUSD, replace
|
| 556 |
+
|
| 557 |
+
*** do USD aggregates
|
| 558 |
+
|
| 559 |
+
use datasetUSD, clear
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
gen fin_safeUSD=fin_dep+fin_loan+fin_mmf+fin_secur // remove trade credit and advances - it's a small part of financial debt and seems unrelated
|
| 563 |
+
gen cb_safeUSD=cb_dep+cb_loan+cb_mmf+cb_secur // remove trade credit and advances - it's a small part of financial debt and seems unrelated
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
gen gov_safeUSD=gov_dep+gov_loan+gov_mmf+gov_secur // remove trade credit and advnaces
|
| 567 |
+
|
| 568 |
+
|
| 569 |
+
rename totliab_Total totliab_TotalUSD
|
| 570 |
+
|
| 571 |
+
keep country year fin_safeUSD gov_safeUSD cb_safeUSD totliab_TotalUSD
|
| 572 |
+
|
| 573 |
+
sort country year
|
| 574 |
+
tsset country year
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
save safeUSD, replace
|
| 578 |
+
|
| 579 |
+
// Make world table
|
| 580 |
+
|
| 581 |
+
use safeUSD, clear
|
| 582 |
+
|
| 583 |
+
gen tempvar=fin_safeUSD+gov_safeUSD+totliab_TotalUSD
|
| 584 |
+
|
| 585 |
+
bysort country: egen minyear=min(year) if tempvar<.
|
| 586 |
+
bysort country: egen maxyear=max(year) if tempvar<.
|
| 587 |
+
|
| 588 |
+
keep if minyear<=1995
|
| 589 |
+
keep if year>=1995
|
| 590 |
+
|
| 591 |
+
keep if maxyear>=2017
|
| 592 |
+
keep if year<=2017
|
| 593 |
+
|
| 594 |
+
sort country year
|
| 595 |
+
tsset country year // panel is balanced
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
if r(balanced)!="strongly balanced" {
|
| 599 |
+
di "WARNING!!!! panel is not balanced"
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
preserve
|
| 603 |
+
|
| 604 |
+
keep if year==2017
|
| 605 |
+
|
| 606 |
+
keep country
|
| 607 |
+
|
| 608 |
+
gen OECD=1
|
| 609 |
+
|
| 610 |
+
save OECD, replace
|
| 611 |
+
|
| 612 |
+
restore
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
decode country, g(country_name)
|
| 616 |
+
|
| 617 |
+
bysort year: egen fin_safeWorld=total(fin_safeUSD)
|
| 618 |
+
bysort year: egen gov_safeWorld=total(gov_safeUSD)
|
| 619 |
+
bysort year: egen new_totalWorld=total(totliab_TotalUSD)
|
| 620 |
+
|
| 621 |
+
bysort year: egen cb_safeWorld=total(cb_safeUSD)
|
| 622 |
+
|
| 623 |
+
gen fin_shareWorld=fin_safeWorld/new_totalWorld
|
| 624 |
+
gen gov_shareWorld=gov_safeWorld/new_totalWorld
|
| 625 |
+
gen shareWorld=fin_shareWorld+gov_shareWorld
|
| 626 |
+
|
| 627 |
+
gen cb_shareWorld=cb_safeWorld/new_totalWorld
|
| 628 |
+
|
| 629 |
+
bysort year: egen fin_safeNonUS=total(fin_safeUSD) if country_name!="United States"
|
| 630 |
+
bysort year: egen gov_safeNonUS=total(gov_safeUSD) if country_name!="United States"
|
| 631 |
+
bysort year: egen new_totalNonUS=total(totliab_TotalUSD) if country_name!="United States"
|
| 632 |
+
|
| 633 |
+
bysort year: egen cb_safeNonUS=total(cb_safeUSD) if country_name!="United States"
|
| 634 |
+
|
| 635 |
+
gen fin_shareNonUS=fin_safeNonUS/new_totalNonUS
|
| 636 |
+
gen gov_shareNonUS=gov_safeNonUS/new_totalNonUS
|
| 637 |
+
gen shareNonUS=fin_shareNonUS+gov_shareNonUS
|
| 638 |
+
|
| 639 |
+
gen cb_shareNonUS=cb_safeNonUS/new_totalNonUS
|
| 640 |
+
|
| 641 |
+
sort country year
|
| 642 |
+
|
| 643 |
+
keep if country==country[1]
|
| 644 |
+
|
| 645 |
+
keep fin_shareWorld gov_shareWorld shareWorld cb_shareWorld fin_shareNonUS gov_shareNonUS shareNonUS cb_shareNonUS year
|
| 646 |
+
|
| 647 |
+
|
| 648 |
+
keep year fin_shareWorld gov_shareWorld shareWorld cb_shareWorld fin_shareNonUS gov_shareNonUS shareNonUS cb_shareNonUS
|
| 649 |
+
|
| 650 |
+
save World, replace
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
// Make final dataset
|
| 654 |
+
|
| 655 |
+
use dataset // non-consolidated data
|
| 656 |
+
|
| 657 |
+
joinby country year using safeUSD, unmatched(both)
|
| 658 |
+
cap drop _merge
|
| 659 |
+
|
| 660 |
+
joinby year using World, unmatched(both)
|
| 661 |
+
cap drop _merge
|
| 662 |
+
|
| 663 |
+
joinby country using OECD, unmatched(both)
|
| 664 |
+
cap drop _merge
|
| 665 |
+
|
| 666 |
+
cap drop fin_safe
|
| 667 |
+
cap drop cb_safe
|
| 668 |
+
|
| 669 |
+
label var gov_safeUSD "government safe liabilities in USD"
|
| 670 |
+
label var fin_shareWorld "financial liabilities (as share of total assets) for the whole world"
|
| 671 |
+
label var gov_shareWorld "government liabilities (as share of total assets) for the whole world"
|
| 672 |
+
label var cb_shareWorld "central bank liabilities (as share of total assets) for the whole world"
|
| 673 |
+
label var shareWorld "safe liabilities (as share of total assets) for the whole world"
|
| 674 |
+
|
| 675 |
+
label var fin_shareNonUS "financial liabilities (as share of total assets) for non-US sample"
|
| 676 |
+
label var gov_shareNonUS "government liabilities (as share of total assets) for non-US sample"
|
| 677 |
+
label var cb_shareNonUS "central bank liabilities (as share of total assets) for non-US sample"
|
| 678 |
+
label var shareNonUS "safe liabilities (as share of total assets) for non-US sample"
|
| 679 |
+
|
| 680 |
+
label var totliab_Gov "Tota Liabilities - Government"
|
| 681 |
+
label var OECD "dummy for OECD countries"
|
| 682 |
+
|
| 683 |
+
save OECD_data, replace
|
| 684 |
+
|
105/replication_package/ReadMe.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9068400c5ca91682b0dd81943ea676402c4cd3e4a0083709b46a65c0d502af1f
|
| 3 |
+
size 42724
|
105/replication_package/Replicate_Empirical_Results.do
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*************************************************************************************************************
|
| 2 |
+
* Replicate Tables 1-4 and Figures 1-2 of "Safe Assets" by Barro, Fernandez-Villaverde, Levintal and Mollerus
|
| 3 |
+
*************************************************************************************************************
|
| 4 |
+
|
| 5 |
+
clear all
|
| 6 |
+
|
| 7 |
+
clear mata
|
| 8 |
+
set mem 500m
|
| 9 |
+
set maxvar 32767
|
| 10 |
+
set more off
|
| 11 |
+
set linesize 255
|
| 12 |
+
cap log close
|
| 13 |
+
|
| 14 |
+
do make_Tables_1_to_3_Figures_1_and_2
|
| 15 |
+
|
| 16 |
+
do make_Table_4
|
105/replication_package/Replicate_Simulation_Results.m
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 2 |
+
% Replicate Tables 5-7 and Figure 3 of "Safe Assets" by Barro, Fernandez-Villaverde, Levintal and Mollerus
|
| 3 |
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
| 4 |
+
|
| 5 |
+
clear
|
| 6 |
+
|
| 7 |
+
%% open diary file
|
| 8 |
+
|
| 9 |
+
FID = fopen('Tables_5_to_7.txt','w');
|
| 10 |
+
fclose(FID);
|
| 11 |
+
|
| 12 |
+
diary Tables_5_to_7.txt
|
| 13 |
+
diary off
|
| 14 |
+
|
| 15 |
+
%% add folders to search path
|
| 16 |
+
homefolder = pwd;
|
| 17 |
+
|
| 18 |
+
addpath(genpath([homefolder '\solution_methods']));
|
| 19 |
+
|
| 20 |
+
%% define models
|
| 21 |
+
|
| 22 |
+
run('UNIT_IES\define_model'); % THETA = 1
|
| 23 |
+
run('GENERAL_IES\define_model'); % THETA ~= 1
|
| 24 |
+
run('Variable_Disaster_Size\define_model'); % THETA = 1, variable disaster size, defaultable long-term bonds
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
%% replicate Table 5
|
| 28 |
+
run('UNIT_IES\make_Table_5.m')
|
| 29 |
+
|
| 30 |
+
%% replicate Table 6
|
| 31 |
+
run('GENERAL_IES\make_Table_6_part_1.m')
|
| 32 |
+
run('UNIT_IES\make_Table_6_part_2.m')
|
| 33 |
+
|
| 34 |
+
%% replicate Table 7
|
| 35 |
+
run('Variable_Disaster_Size\make_Table_7.m')
|
| 36 |
+
|
| 37 |
+
%% replicate Figure 3
|
| 38 |
+
run('UNIT_IES\Disaster_IRF.m')
|
| 39 |
+
|
| 40 |
+
|
105/replication_package/UNIT_IES/Disaster_IRF.m
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Disaster Impulse response function
|
| 2 |
+
|
| 3 |
+
clear,clc,close all
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
load('benchmark')
|
| 7 |
+
|
| 8 |
+
state0 = mean(tila1);
|
| 9 |
+
mean_W1_share0 = mean_W1_share;
|
| 10 |
+
|
| 11 |
+
T = 10/period_length + 1;
|
| 12 |
+
|
| 13 |
+
disaster = ones(1,T+1);
|
| 14 |
+
disaster(2) = 2;
|
| 15 |
+
|
| 16 |
+
simulate_with_disasters;
|
| 17 |
+
summarize_results;
|
| 18 |
+
|
| 19 |
+
W1_share = [mean_W1_share0;W1_share(:)];
|
| 20 |
+
|
| 21 |
+
% adjust for human capital
|
| 22 |
+
equity = equity/ALPHA - MU*(1 - ALPHA)/ALPHA;
|
| 23 |
+
debt_to_assets = debt_to_assets/ALPHA;
|
| 24 |
+
W1_share = W1_share/ALPHA - (1 - ALPHA)/ALPHA*MU;
|
| 25 |
+
|
| 26 |
+
set(0, 'defaultFigurePaperPosition', [0 0 20 21.5]*30);
|
| 27 |
+
h = figure('color', [1 1 1], 'PaperType', 'A4');
|
| 28 |
+
|
| 29 |
+
subplot(2,2,1);
|
| 30 |
+
plot(W1_share);
|
| 31 |
+
title('W1/W')
|
| 32 |
+
|
| 33 |
+
subplot(2,2,2)
|
| 34 |
+
plot(rb);
|
| 35 |
+
title('rf')
|
| 36 |
+
|
| 37 |
+
subplot(2,2,3)
|
| 38 |
+
plot(equity);
|
| 39 |
+
title('K1')
|
| 40 |
+
|
| 41 |
+
subplot(2,2,4)
|
| 42 |
+
plot(debt_to_assets);
|
| 43 |
+
title('B1/assets')
|
| 44 |
+
|
| 45 |
+
cd ..
|
| 46 |
+
saveas(h,'Figure_3','jpg')
|
105/replication_package/UNIT_IES/Parameters.m
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
period_length = 0.25;
|
| 2 |
+
|
| 3 |
+
P = 1 - exp(-.04*period_length); % disaster probability
|
| 4 |
+
|
| 5 |
+
B = -log(1 - .32); % disaster size
|
| 6 |
+
|
| 7 |
+
meanB = B;
|
| 8 |
+
|
| 9 |
+
G = 0.025*period_length; % drift of log output
|
| 10 |
+
|
| 11 |
+
RHO = 0.04*period_length; % time preference rate
|
| 12 |
+
|
| 13 |
+
NU = 0.02*period_length; % replacement rate
|
| 14 |
+
|
| 15 |
+
MU = 0.05; % popoulation share of agent 1
|
| 16 |
+
|
| 17 |
+
ALPHA = 1/3; % capital share in output
|
| 18 |
+
|
| 19 |
+
TAU = 0; % bond duration - short-term bonds
|
| 20 |
+
|
| 21 |
+
GAMMA1 = 1.000001; % start with unit risk aversion
|
| 22 |
+
GAMMA2 = GAMMA1;
|
105/replication_package/UNIT_IES/Table_6_MU.m
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% MU = 0.1
|
| 2 |
+
|
| 3 |
+
load('model')
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
Parameters;
|
| 7 |
+
MU = 0.1; % popoulation share of agent 1
|
| 8 |
+
|
| 9 |
+
% make the vector of parameters
|
| 10 |
+
params = eval(symparams);
|
| 11 |
+
|
| 12 |
+
% distribution of hatyp
|
| 13 |
+
nodes = exp([G,G-B]); % hatyp
|
| 14 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 15 |
+
|
| 16 |
+
T = 2000/period_length; % simulate 2000 years
|
| 17 |
+
|
| 18 |
+
% disaster shock
|
| 19 |
+
rng('default')
|
| 20 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 21 |
+
|
| 22 |
+
GAMMA1 = 2.6;
|
| 23 |
+
GAMMA2 = GAMMA1;
|
| 24 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 26 |
+
|
| 27 |
+
% tolerance for the Newton solver
|
| 28 |
+
tolX=1e-7; tolF=1e-7; maxiter=10; testF=1e-5;
|
| 29 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 30 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 31 |
+
|
| 32 |
+
solve_and_simulate;
|
| 33 |
+
|
| 34 |
+
%%%%%%%%%%%%%%%%%
|
| 35 |
+
|
| 36 |
+
GAMMA1 = 2.6;
|
| 37 |
+
GAMMA2 = 4.15;
|
| 38 |
+
|
| 39 |
+
newparams = params;
|
| 40 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 41 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 42 |
+
|
| 43 |
+
burn=1;
|
| 44 |
+
|
| 45 |
+
correct_params;
|
| 46 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 47 |
+
summarize_results;
|
| 48 |
+
|
| 49 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 50 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 51 |
+
Table_vol = [vol_roe,vol_rb];
|
| 52 |
+
|
| 53 |
+
%%%%%%%%%%%%%%%%%%%%%%%%
|
| 54 |
+
|
| 55 |
+
GAMMA1=2.5;
|
| 56 |
+
GAMMA2=4.29;
|
| 57 |
+
|
| 58 |
+
burn=1;
|
| 59 |
+
newparams=params;
|
| 60 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 61 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 62 |
+
|
| 63 |
+
correct_params;
|
| 64 |
+
|
| 65 |
+
simulate_with_disasters;
|
| 66 |
+
|
| 67 |
+
summarize_results;
|
| 68 |
+
|
| 69 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 70 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 71 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 72 |
+
|
| 73 |
+
%%%%%%%%%%%%%%%%%%%%%
|
| 74 |
+
GAMMA1=2.4;
|
| 75 |
+
GAMMA2=4.54;
|
| 76 |
+
|
| 77 |
+
newparams=params;
|
| 78 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 79 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 80 |
+
|
| 81 |
+
params=newparams;
|
| 82 |
+
xt=max(x_results);
|
| 83 |
+
[coeffs,model]=tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 84 |
+
|
| 85 |
+
simulate_with_disasters;
|
| 86 |
+
|
| 87 |
+
summarize_results;
|
| 88 |
+
|
| 89 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 90 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 91 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 92 |
+
|
| 93 |
+
save('Table_6_MU','Table*')
|
| 94 |
+
|
105/replication_package/UNIT_IES/Table_6_NU.m
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% NU = .03
|
| 2 |
+
|
| 3 |
+
load('model')
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
Parameters;
|
| 7 |
+
NU = 0.03*period_length; % replacement rate
|
| 8 |
+
|
| 9 |
+
% make the vector of parameters
|
| 10 |
+
params = eval(symparams);
|
| 11 |
+
|
| 12 |
+
% distribution of hatyp
|
| 13 |
+
nodes = exp([G,G-B]); % hatyp
|
| 14 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 15 |
+
|
| 16 |
+
T = 2000/period_length; % simulate 2000 years
|
| 17 |
+
|
| 18 |
+
% disaster shock
|
| 19 |
+
rng('default')
|
| 20 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 21 |
+
|
| 22 |
+
GAMMA1 = 2.6;
|
| 23 |
+
GAMMA2 = GAMMA1;
|
| 24 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 26 |
+
|
| 27 |
+
% tolerance for the Newton solver
|
| 28 |
+
tolX=1e-7; tolF=1e-7; maxiter=10; testF=1e-5;
|
| 29 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 30 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 31 |
+
|
| 32 |
+
solve_and_simulate;
|
| 33 |
+
|
| 34 |
+
%%%%%%%%%%%%%%%%%
|
| 35 |
+
|
| 36 |
+
GAMMA1 = 2.6;
|
| 37 |
+
GAMMA2 = 4.15;
|
| 38 |
+
|
| 39 |
+
newparams = params;
|
| 40 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 41 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 42 |
+
|
| 43 |
+
burn=1;
|
| 44 |
+
|
| 45 |
+
correct_params;
|
| 46 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 47 |
+
summarize_results;
|
| 48 |
+
|
| 49 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 50 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 51 |
+
Table_vol = [vol_roe,vol_rb];
|
| 52 |
+
|
| 53 |
+
%%%%%%%%%%%%%%%%%%%%%%%%
|
| 54 |
+
|
| 55 |
+
GAMMA1=2.5;
|
| 56 |
+
GAMMA2=4.29;
|
| 57 |
+
|
| 58 |
+
burn=1;
|
| 59 |
+
newparams=params;
|
| 60 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 61 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 62 |
+
|
| 63 |
+
correct_params;
|
| 64 |
+
|
| 65 |
+
simulate_with_disasters;
|
| 66 |
+
|
| 67 |
+
summarize_results;
|
| 68 |
+
|
| 69 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 70 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 71 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 72 |
+
|
| 73 |
+
%%%%%%%%%%%%%%%%%%%%%
|
| 74 |
+
GAMMA1=2.4;
|
| 75 |
+
GAMMA2=4.54;
|
| 76 |
+
|
| 77 |
+
newparams=params;
|
| 78 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 79 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 80 |
+
|
| 81 |
+
params=newparams;
|
| 82 |
+
xt=max(x_results);
|
| 83 |
+
[coeffs,model]=tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 84 |
+
|
| 85 |
+
simulate_with_disasters;
|
| 86 |
+
|
| 87 |
+
summarize_results;
|
| 88 |
+
|
| 89 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 90 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 91 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
save('Table_6_NU','Table*')
|
105/replication_package/UNIT_IES/Table_6_P.m
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% P = .02
|
| 2 |
+
|
| 3 |
+
load('model')
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
Parameters;
|
| 7 |
+
P = 1 - exp(-.02*period_length); % disaster probability
|
| 8 |
+
|
| 9 |
+
% make the vector of parameters
|
| 10 |
+
params = eval(symparams);
|
| 11 |
+
|
| 12 |
+
% distribution of hatyp
|
| 13 |
+
nodes = exp([G,G-B]); % hatyp
|
| 14 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 15 |
+
|
| 16 |
+
T = 2000/period_length; % simulate 2000 years
|
| 17 |
+
|
| 18 |
+
% disaster shock
|
| 19 |
+
rng('default')
|
| 20 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 21 |
+
|
| 22 |
+
GAMMA1 = 2.6;
|
| 23 |
+
GAMMA2 = GAMMA1;
|
| 24 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 26 |
+
|
| 27 |
+
% tolerance for the Newton solver
|
| 28 |
+
tolX=1e-7; tolF=1e-7; maxiter=10; testF=1e-5;
|
| 29 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 30 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 31 |
+
|
| 32 |
+
solve_and_simulate;
|
| 33 |
+
|
| 34 |
+
%%%%%%%%%%%%%%%%%
|
| 35 |
+
|
| 36 |
+
GAMMA1 = 2.6;
|
| 37 |
+
GAMMA2 = 4.15;
|
| 38 |
+
|
| 39 |
+
newparams = params;
|
| 40 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 41 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 42 |
+
|
| 43 |
+
burn=1;
|
| 44 |
+
|
| 45 |
+
correct_params;
|
| 46 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 47 |
+
summarize_results;
|
| 48 |
+
|
| 49 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 50 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 51 |
+
Table_vol = [vol_roe,vol_rb];
|
| 52 |
+
|
| 53 |
+
%%%%%%%%%%%%%%%%%%%%%%%%
|
| 54 |
+
|
| 55 |
+
GAMMA1=2.5;
|
| 56 |
+
GAMMA2=4.29;
|
| 57 |
+
|
| 58 |
+
burn=1;
|
| 59 |
+
newparams=params;
|
| 60 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 61 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 62 |
+
|
| 63 |
+
correct_params;
|
| 64 |
+
|
| 65 |
+
simulate_with_disasters;
|
| 66 |
+
|
| 67 |
+
summarize_results;
|
| 68 |
+
|
| 69 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 70 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 71 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 72 |
+
|
| 73 |
+
%%%%%%%%%%%%%%%%%%%%%
|
| 74 |
+
GAMMA1=2.4;
|
| 75 |
+
GAMMA2=4.54;
|
| 76 |
+
|
| 77 |
+
newparams=params;
|
| 78 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 79 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 80 |
+
|
| 81 |
+
params=newparams;
|
| 82 |
+
xt=max(x_results);
|
| 83 |
+
[coeffs,model]=tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 84 |
+
|
| 85 |
+
simulate_with_disasters;
|
| 86 |
+
|
| 87 |
+
summarize_results;
|
| 88 |
+
|
| 89 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 90 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 91 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 92 |
+
|
| 93 |
+
save('Table_6_P','Table*')
|
| 94 |
+
|
105/replication_package/UNIT_IES/Tranquility.m
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% 40 years of tranquility
|
| 2 |
+
|
| 3 |
+
clear,clc,close all
|
| 4 |
+
addpath('files')
|
| 5 |
+
|
| 6 |
+
load('benchmark')
|
| 7 |
+
|
| 8 |
+
state0 = mean(tila1);
|
| 9 |
+
mean_W1_share0 = mean_W1_share;
|
| 10 |
+
|
| 11 |
+
T40 = 40/period_length+1;
|
| 12 |
+
T = 2000;
|
| 13 |
+
|
| 14 |
+
disaster = ones(1,T+1);
|
| 15 |
+
|
| 16 |
+
simulate_with_disasters;
|
| 17 |
+
summarize_results;
|
| 18 |
+
|
| 19 |
+
W1_share = [mean_W1_share0;W1_share(:)];
|
| 20 |
+
|
| 21 |
+
% adjust for human capital
|
| 22 |
+
equity = equity/ALPHA - MU*(1 - ALPHA)/ALPHA;
|
| 23 |
+
debt_to_assets = debt_to_assets/ALPHA;
|
| 24 |
+
W1_share = W1_share/ALPHA - (1 - ALPHA)/ALPHA*MU;
|
| 25 |
+
|
| 26 |
+
[W1_share(end),rb(end),equity(end),debt_to_assets(end)]
|
| 27 |
+
|
| 28 |
+
W1_share = W1_share(1:T40);
|
| 29 |
+
rf = rb(1:T40);
|
| 30 |
+
equity = equity(1:T40);
|
| 31 |
+
debt_to_assets = debt_to_assets(1:T40);
|
| 32 |
+
|
| 33 |
+
set(0, 'defaultFigurePaperPosition', [0 0 20 21.5]*30);
|
| 34 |
+
h = figure('color', [1 1 1], 'PaperType', 'A4');
|
| 35 |
+
|
| 36 |
+
subplot(2,2,1);
|
| 37 |
+
plot(W1_share);
|
| 38 |
+
title('W1/W')
|
| 39 |
+
|
| 40 |
+
subplot(2,2,2)
|
| 41 |
+
plot(rf);
|
| 42 |
+
title('rf')
|
| 43 |
+
|
| 44 |
+
subplot(2,2,3)
|
| 45 |
+
plot(equity);
|
| 46 |
+
title('K1')
|
| 47 |
+
|
| 48 |
+
subplot(2,2,4)
|
| 49 |
+
plot(debt_to_assets);
|
| 50 |
+
title('B1/assets')
|
| 51 |
+
|
105/replication_package/UNIT_IES/correct_params.m
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file changes the parameters gradually from their initival value to
|
| 2 |
+
% the target value
|
| 3 |
+
|
| 4 |
+
solve = 1;
|
| 5 |
+
stop = 0;
|
| 6 |
+
t = 0;
|
| 7 |
+
|
| 8 |
+
xt = state0;
|
| 9 |
+
params0 = params;
|
| 10 |
+
while stop==0
|
| 11 |
+
t = t + 1;
|
| 12 |
+
|
| 13 |
+
if t<=burn
|
| 14 |
+
factor = t/burn;
|
| 15 |
+
params = (1 - factor)*params0 + factor*newparams;
|
| 16 |
+
end
|
| 17 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 18 |
+
|
| 19 |
+
% if residuals are too large solve again
|
| 20 |
+
if norm(R(:))>testF && solve==1
|
| 21 |
+
t
|
| 22 |
+
[coeffs,model] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 23 |
+
|
| 24 |
+
% evaluate the new solution
|
| 25 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 26 |
+
end
|
| 27 |
+
|
| 28 |
+
newxt = nPhi(:,1); % assume no realized disasters
|
| 29 |
+
|
| 30 |
+
if t>burn+10 % after 10 periods start checking for convergence
|
| 31 |
+
if max(abs(newxt-xt))<1e-7
|
| 32 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 33 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 34 |
+
|
| 35 |
+
newxt = nPhi(:,1);
|
| 36 |
+
if max(abs(newxt-xt))<1e-7
|
| 37 |
+
stop = 1;
|
| 38 |
+
state0 = xt; % solution point
|
| 39 |
+
coeffs0 = coeffs;
|
| 40 |
+
end
|
| 41 |
+
end
|
| 42 |
+
end
|
| 43 |
+
xt = newxt;
|
| 44 |
+
end
|
| 45 |
+
|
105/replication_package/UNIT_IES/define_model.m
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%-------------------------------------------------------------------------
|
| 2 |
+
% The model: Safe Assets - the case of unit IES (THETA = 1)
|
| 3 |
+
%
|
| 4 |
+
% This file defines the baseline model (see Appendix for the full derivation).
|
| 5 |
+
% Bonds are short term perfectly safe.
|
| 6 |
+
%
|
| 7 |
+
% Variables are denoted by small letters and
|
| 8 |
+
% parameters by capital letters. Future values are denoted by suffix p.
|
| 9 |
+
%-------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
clear,clc
|
| 12 |
+
|
| 13 |
+
%% Symbolic variables
|
| 14 |
+
|
| 15 |
+
syms RHO GAMMA1 GAMMA2 NU MU TAU real
|
| 16 |
+
syms f1 f2 f1p f2p x1 x2 x1p x2p real
|
| 17 |
+
syms logq logqp tilp tilpp real
|
| 18 |
+
syms state1 state1p state2 state2p hatyp deltap k1 tilb1 real
|
| 19 |
+
syms tila1 tila1p tila2 invtila1 invtila2 invtilp rbp rep c1 c2 c1p c2p q qp real
|
| 20 |
+
syms invc1 invc1p invc2 invc2p invf1 invf2 r1p r2p logu1p logu2p u1p u2p logf1 logf1p logf2 logf2p real
|
| 21 |
+
syms term1p term2p invr1p invr2p real
|
| 22 |
+
|
| 23 |
+
%% Parameters
|
| 24 |
+
|
| 25 |
+
symparams = [RHO,GAMMA1,GAMMA2,NU,MU];
|
| 26 |
+
|
| 27 |
+
%% State variables
|
| 28 |
+
|
| 29 |
+
state = [tila1]; % current period
|
| 30 |
+
statep = [tila1p]; % future period
|
| 31 |
+
|
| 32 |
+
%% Control variables
|
| 33 |
+
|
| 34 |
+
control = [f1,f2,x1,x2,logq]; % current period
|
| 35 |
+
controlp = [f1p,f2p,x1p,x2p,logqp]; % future period
|
| 36 |
+
|
| 37 |
+
%% shocks
|
| 38 |
+
|
| 39 |
+
shocks = [hatyp];
|
| 40 |
+
|
| 41 |
+
%% auxiliary variables
|
| 42 |
+
|
| 43 |
+
tilp = 1/RHO; % price-dividend ratio for unit IES
|
| 44 |
+
tilpp = tilp; % next period
|
| 45 |
+
|
| 46 |
+
c1 = RHO/(1 + RHO); % consumption/wealth ratio of agent 1 for unit IES
|
| 47 |
+
c1p = c1; % next period
|
| 48 |
+
|
| 49 |
+
c2 = c1; % consumption/wealth ratio of agent 2 for unit IES
|
| 50 |
+
c2p = c2; % next period
|
| 51 |
+
|
| 52 |
+
logc1p = log(c1p);
|
| 53 |
+
logc2p = log(c2p);
|
| 54 |
+
|
| 55 |
+
invf1_ = 1/f1;
|
| 56 |
+
invf2_ = 1/f2;
|
| 57 |
+
|
| 58 |
+
logf1p_ = log(f1p);
|
| 59 |
+
logf2p_ = log(f2p);
|
| 60 |
+
|
| 61 |
+
invr1p_ = 1/r1p;
|
| 62 |
+
invr2p_ = 1/r2p;
|
| 63 |
+
|
| 64 |
+
q_ = exp(logq);
|
| 65 |
+
qp_ = exp(logqp);
|
| 66 |
+
|
| 67 |
+
invtila1_ = 1/tila1;
|
| 68 |
+
invtila2_ = 1/tila2;
|
| 69 |
+
|
| 70 |
+
rep_ = (1 + tilpp)/tilp*hatyp; % return on equity
|
| 71 |
+
rbp_ = 1/q; % return on bond
|
| 72 |
+
|
| 73 |
+
u1p_ = exp(logu1p);
|
| 74 |
+
u2p_ = exp(logu2p);
|
| 75 |
+
|
| 76 |
+
%% MODEL CONDITIONS
|
| 77 |
+
|
| 78 |
+
tila2_ = tilp + 1 - tila1;
|
| 79 |
+
|
| 80 |
+
k1_ = x1*(1 - c1)*tila1/tilp;
|
| 81 |
+
|
| 82 |
+
tilb1_ = (1 - x1)*(1 - c1)*tila1;
|
| 83 |
+
|
| 84 |
+
eq1 = tilb1*invtila2 + (1 - x2)*(1 - c2);
|
| 85 |
+
|
| 86 |
+
r1p_ = x1*rep + (1 - x1)*rbp;
|
| 87 |
+
|
| 88 |
+
r2p_ = x2*rep + (1 - x2)*rbp;
|
| 89 |
+
|
| 90 |
+
term1p_ = r1p^(1 - GAMMA1)*((1 - NU*(1 - MU))*u1p^(1 - GAMMA1)...
|
| 91 |
+
+ NU*(1 - MU)*u2p^(1 - GAMMA1))*invf1^(1 - GAMMA1);
|
| 92 |
+
|
| 93 |
+
term2p_ = r2p^(1 - GAMMA2)*((1 - NU*MU)*u2p^(1 - GAMMA2)...
|
| 94 |
+
+NU*MU*u1p^(1 - GAMMA2))*invf2^(1 - GAMMA2);
|
| 95 |
+
|
| 96 |
+
eq2 = -1 + term1p; % define f1 = (E(r1p*u1p)^(1-GAMMA1))^(1/(1-GAMMA1))
|
| 97 |
+
|
| 98 |
+
eq3 = -1 + term2p; % define f2 similarly
|
| 99 |
+
|
| 100 |
+
logu1p_ = RHO/(1 + RHO)*logc1p + 1/(1 + RHO)*log(1 - c1p) + 1/(1 + RHO)*logf1p;
|
| 101 |
+
|
| 102 |
+
logu2p_ = RHO/(1 + RHO)*logc2p + 1/(1 + RHO)*log(1 - c2p) + 1/(1 + RHO)*logf2p;
|
| 103 |
+
|
| 104 |
+
eq4 = (rep - rbp)*term1p*invr1p;
|
| 105 |
+
|
| 106 |
+
eq5 = (rep - rbp)*term2p*invr2p;
|
| 107 |
+
|
| 108 |
+
%% Function f (Ef = 0 imposes model conditions)
|
| 109 |
+
|
| 110 |
+
f_fun = [eq1;eq2;eq3;eq4;eq5];
|
| 111 |
+
|
| 112 |
+
%% law of motion of state variables
|
| 113 |
+
|
| 114 |
+
Phi_fun = (1 + tilp)*(k1 - NU*(k1 - MU)) + (1 - NU)*tilb1/(hatyp*q); % law of motion of tila1
|
| 115 |
+
|
| 116 |
+
%% collect auxiliary variables and functions
|
| 117 |
+
|
| 118 |
+
allvars=who;
|
| 119 |
+
auxfuns=[];
|
| 120 |
+
auxvars=[];
|
| 121 |
+
for i=1:length(allvars)
|
| 122 |
+
if strcmp(allvars{i}(end),'_')
|
| 123 |
+
eval(['tempfun=' allvars{i} ';'])
|
| 124 |
+
eval(['tempvar=' allvars{i}(1:end-1) ';'])
|
| 125 |
+
auxfuns=[auxfuns;tempfun];
|
| 126 |
+
auxvars=[auxvars;tempvar];
|
| 127 |
+
end
|
| 128 |
+
end
|
| 129 |
+
|
| 130 |
+
%% Approximation order (<=4)
|
| 131 |
+
|
| 132 |
+
order = 4;
|
| 133 |
+
|
| 134 |
+
%% Preprocess model and save
|
| 135 |
+
|
| 136 |
+
model = prepare_tp(f_fun,Phi_fun,controlp,control,statep,state,shocks,symparams,order,auxfuns,auxvars);
|
| 137 |
+
|
| 138 |
+
save('model')
|
| 139 |
+
|
105/replication_package/UNIT_IES/make_Table_5.m
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Table 5
|
| 2 |
+
|
| 3 |
+
clear,clc
|
| 4 |
+
|
| 5 |
+
load('model')
|
| 6 |
+
addpath('files')
|
| 7 |
+
|
| 8 |
+
Parameters;
|
| 9 |
+
|
| 10 |
+
% make the vector of parameters
|
| 11 |
+
params = eval(symparams);
|
| 12 |
+
|
| 13 |
+
% distribution of hatyp
|
| 14 |
+
nodes = exp([G,G-B]); % hatyp
|
| 15 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 16 |
+
|
| 17 |
+
T = 2000/period_length; % simulate 2000 years
|
| 18 |
+
|
| 19 |
+
% disaster shock
|
| 20 |
+
rng('default')
|
| 21 |
+
disaster = double(rand(1,T+1)<P) + 1; % 1 for normal, 2 for disaster
|
| 22 |
+
|
| 23 |
+
GAMMA1 = 3.85;
|
| 24 |
+
GAMMA2 = GAMMA1;
|
| 25 |
+
params(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 26 |
+
params(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 27 |
+
|
| 28 |
+
step_size=1;
|
| 29 |
+
|
| 30 |
+
% tolerance for the Newton solver
|
| 31 |
+
tolX = 1e-5; tolF = 1e-5; maxiter = 10; testF = 1e-5;
|
| 32 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 33 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 34 |
+
|
| 35 |
+
solve_and_simulate;
|
| 36 |
+
|
| 37 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 38 |
+
|
| 39 |
+
summarize_results;
|
| 40 |
+
|
| 41 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 42 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 43 |
+
Table_vol = [vol_roe,vol_rb];
|
| 44 |
+
|
| 45 |
+
%%
|
| 46 |
+
GAMMA1 = 3.3;
|
| 47 |
+
GAMMA2 = 3.89;
|
| 48 |
+
|
| 49 |
+
burn=1;
|
| 50 |
+
newparams = params;
|
| 51 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 52 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 53 |
+
|
| 54 |
+
correct_params;
|
| 55 |
+
simulate_with_disasters;
|
| 56 |
+
summarize_results;
|
| 57 |
+
|
| 58 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 59 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 60 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 61 |
+
|
| 62 |
+
%%
|
| 63 |
+
GAMMA1 = 2.9;
|
| 64 |
+
GAMMA2 = 3.98;
|
| 65 |
+
|
| 66 |
+
burn=5;
|
| 67 |
+
|
| 68 |
+
newparams = params;
|
| 69 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 70 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 71 |
+
|
| 72 |
+
correct_params;
|
| 73 |
+
simulate_with_disasters;
|
| 74 |
+
summarize_results;
|
| 75 |
+
|
| 76 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 77 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 78 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 79 |
+
|
| 80 |
+
%%
|
| 81 |
+
GAMMA1 = 2.8;
|
| 82 |
+
GAMMA2 = 4.02;
|
| 83 |
+
|
| 84 |
+
burn = 5;
|
| 85 |
+
|
| 86 |
+
newparams = params;
|
| 87 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 88 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 89 |
+
|
| 90 |
+
correct_params;
|
| 91 |
+
simulate_with_disasters;
|
| 92 |
+
summarize_results;
|
| 93 |
+
|
| 94 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 95 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 96 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 97 |
+
|
| 98 |
+
%%
|
| 99 |
+
GAMMA1 = 2.7;
|
| 100 |
+
GAMMA2 = 4.07;
|
| 101 |
+
|
| 102 |
+
burn = 5;
|
| 103 |
+
|
| 104 |
+
newparams = params;
|
| 105 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 106 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 107 |
+
|
| 108 |
+
correct_params;
|
| 109 |
+
simulate_with_disasters;
|
| 110 |
+
summarize_results;
|
| 111 |
+
|
| 112 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 113 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 114 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 115 |
+
|
| 116 |
+
%%
|
| 117 |
+
GAMMA1 = 2.6;
|
| 118 |
+
GAMMA2 = 4.15;
|
| 119 |
+
|
| 120 |
+
burn = 5;
|
| 121 |
+
|
| 122 |
+
newparams = params;
|
| 123 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 124 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 125 |
+
|
| 126 |
+
correct_params;
|
| 127 |
+
simulate_with_disasters;
|
| 128 |
+
summarize_results;
|
| 129 |
+
|
| 130 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 131 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 132 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 133 |
+
|
| 134 |
+
%%
|
| 135 |
+
GAMMA1 = 2.5;
|
| 136 |
+
GAMMA2 = 4.29;
|
| 137 |
+
|
| 138 |
+
burn=5;
|
| 139 |
+
|
| 140 |
+
newparams = params;
|
| 141 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 142 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 143 |
+
|
| 144 |
+
correct_params;
|
| 145 |
+
simulate_with_disasters;
|
| 146 |
+
summarize_results;
|
| 147 |
+
|
| 148 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 149 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 150 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 151 |
+
|
| 152 |
+
%%
|
| 153 |
+
|
| 154 |
+
GAMMA1 = 2.4;
|
| 155 |
+
GAMMA2 = 4.54;
|
| 156 |
+
|
| 157 |
+
burn=5;
|
| 158 |
+
|
| 159 |
+
newparams = params;
|
| 160 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 161 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 162 |
+
|
| 163 |
+
correct_params;
|
| 164 |
+
simulate_with_disasters;
|
| 165 |
+
summarize_results;
|
| 166 |
+
|
| 167 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 168 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 169 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 170 |
+
|
| 171 |
+
save('benchmark')
|
| 172 |
+
|
| 173 |
+
%%
|
| 174 |
+
GAMMA1 = 2.3;
|
| 175 |
+
GAMMA2 = 5.50;
|
| 176 |
+
|
| 177 |
+
burn=5;
|
| 178 |
+
|
| 179 |
+
newparams = params;
|
| 180 |
+
newparams(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 181 |
+
newparams(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 182 |
+
|
| 183 |
+
correct_params;
|
| 184 |
+
simulate_with_disasters;
|
| 185 |
+
summarize_results;
|
| 186 |
+
|
| 187 |
+
Table = [Table;GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 188 |
+
Table_labor = [Table_labor;GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 189 |
+
Table_vol = [Table_vol;vol_roe,vol_rb];
|
| 190 |
+
|
| 191 |
+
%% display Table 5
|
| 192 |
+
clc
|
| 193 |
+
|
| 194 |
+
homefolder = pwd;
|
| 195 |
+
cd ..
|
| 196 |
+
diary on
|
| 197 |
+
|
| 198 |
+
disp('********** Table 5 **********')
|
| 199 |
+
|
| 200 |
+
Table_5 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)]
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
%% display accuracy measure
|
| 204 |
+
disp('Appendix Table 1: Accuracy Measures for Table 5')
|
| 205 |
+
|
| 206 |
+
Accuracy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)]
|
| 207 |
+
|
| 208 |
+
diary off
|
| 209 |
+
|
| 210 |
+
cd(homefolder)
|
105/replication_package/UNIT_IES/make_Table_6_part_2.m
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Table_6_NU;
|
| 2 |
+
Table_6_P;
|
| 3 |
+
Table_6_MU;
|
| 4 |
+
|
| 5 |
+
%% Display Table 6 (part 2)
|
| 6 |
+
clc
|
| 7 |
+
homefolder = pwd;
|
| 8 |
+
cd ..
|
| 9 |
+
diary on
|
| 10 |
+
|
| 11 |
+
disp('********** Table 6 (continued) **********')
|
| 12 |
+
|
| 13 |
+
load([homefolder '\Table_6_NU'],'Table*')
|
| 14 |
+
|
| 15 |
+
Table_6 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)];
|
| 16 |
+
|
| 17 |
+
disp('nu = 0.03')
|
| 18 |
+
disp(Table_6(3,:))
|
| 19 |
+
|
| 20 |
+
load([homefolder '\Table_6_P'],'Table*')
|
| 21 |
+
|
| 22 |
+
Table_6 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)];
|
| 23 |
+
|
| 24 |
+
disp('p = 0.02')
|
| 25 |
+
disp(Table_6(3,:))
|
| 26 |
+
|
| 27 |
+
load([homefolder '\Table_6_MU'],'Table*')
|
| 28 |
+
|
| 29 |
+
Table_6 = [round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)];
|
| 30 |
+
|
| 31 |
+
disp('mu = 0.1')
|
| 32 |
+
disp(Table_6(3,:))
|
| 33 |
+
|
| 34 |
+
%% Accuracy Measures
|
| 35 |
+
disp('Appendix Table 2 (continued): Accuarcy Measures for Table 6')
|
| 36 |
+
|
| 37 |
+
load([homefolder '\Table_6_NU'],'Table*')
|
| 38 |
+
|
| 39 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 40 |
+
|
| 41 |
+
disp('nu = 0.03')
|
| 42 |
+
disp(Accuarcy(3,2:end))
|
| 43 |
+
|
| 44 |
+
load([homefolder '\Table_6_P'],'Table*')
|
| 45 |
+
|
| 46 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 47 |
+
|
| 48 |
+
disp('p = 0.02')
|
| 49 |
+
disp(Accuarcy(3,2:end))
|
| 50 |
+
|
| 51 |
+
load([homefolder '\Table_6_MU'],'Table*')
|
| 52 |
+
|
| 53 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 54 |
+
|
| 55 |
+
disp('mu = 0.1')
|
| 56 |
+
disp(Accuarcy(3,2:end))
|
| 57 |
+
|
| 58 |
+
diary off
|
| 59 |
+
|
| 60 |
+
cd(homefolder)
|
105/replication_package/UNIT_IES/rep_agent.m
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Table 5
|
| 2 |
+
|
| 3 |
+
clear,clc
|
| 4 |
+
|
| 5 |
+
load('model')
|
| 6 |
+
|
| 7 |
+
addpath('files')
|
| 8 |
+
|
| 9 |
+
Parameters;
|
| 10 |
+
|
| 11 |
+
% make the vector of parameters
|
| 12 |
+
params = eval(symparams);
|
| 13 |
+
|
| 14 |
+
% distribution of hatyp and deltap
|
| 15 |
+
nodes = exp([G,G-B]); % hatyp
|
| 16 |
+
weights = [1-P,P]; % corresponding probabilities
|
| 17 |
+
|
| 18 |
+
rng('default')
|
| 19 |
+
|
| 20 |
+
T = 10; % for rep agent simulate for 10 periods only
|
| 21 |
+
|
| 22 |
+
% disaster shock
|
| 23 |
+
rng('default')
|
| 24 |
+
|
| 25 |
+
disaster = ones(1,T+1); % 1 for normal
|
| 26 |
+
disaster(ceil(T/2)) = 2; % 2 for disaster
|
| 27 |
+
|
| 28 |
+
% tolerance for the Newton solver
|
| 29 |
+
tolX = 1e-5; tolF = 1e-5; maxiter = 10; testF = 1e-5;
|
| 30 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 31 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 32 |
+
|
| 33 |
+
%%%%%%%%%%%%%%%%%
|
| 34 |
+
|
| 35 |
+
GAMMA1=1.000001;
|
| 36 |
+
GAMMA2=GAMMA1;
|
| 37 |
+
params(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 38 |
+
params(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 39 |
+
|
| 40 |
+
solve_and_simulate;
|
| 41 |
+
|
| 42 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 43 |
+
|
| 44 |
+
summarize_results;
|
| 45 |
+
|
| 46 |
+
Table = [GAMMA1,GAMMA2,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 47 |
+
|
| 48 |
+
%%
|
| 49 |
+
|
| 50 |
+
for GAMMA1 = [1.5,2,2.4,2.5:.5:6]
|
| 51 |
+
GAMMA2 = GAMMA1;
|
| 52 |
+
|
| 53 |
+
% update parameter values and solve the model for the new parameters
|
| 54 |
+
params(logical(symparams==sym('GAMMA1'))) = GAMMA1;
|
| 55 |
+
params(logical(symparams==sym('GAMMA2'))) = GAMMA2;
|
| 56 |
+
[coeffs,model] = tpsolve(coeffs,state0,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 57 |
+
|
| 58 |
+
simulate_with_disasters; % This file simulates the model with disasters.
|
| 59 |
+
|
| 60 |
+
summarize_results;
|
| 61 |
+
|
| 62 |
+
Table = [Table;GAMMA1,GAMMA2,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 63 |
+
end
|
| 64 |
+
|
| 65 |
+
Table_5 = round(Table(:,[1,3,4]),3)
|
| 66 |
+
|
105/replication_package/UNIT_IES/simulate_with_disasters.m
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Simulate with disasters
|
| 2 |
+
y_results = zeros(model.n_y,T+1);
|
| 3 |
+
x_results = zeros(model.n_x,T+1);
|
| 4 |
+
R_results = zeros(model.n_f,T+1);
|
| 5 |
+
|
| 6 |
+
x_results(:,1) = state0;
|
| 7 |
+
|
| 8 |
+
for t = 1:T
|
| 9 |
+
t
|
| 10 |
+
xt = x_results(:,t);
|
| 11 |
+
|
| 12 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 13 |
+
|
| 14 |
+
% store results
|
| 15 |
+
R_results(:,t) = R;
|
| 16 |
+
y_results(:,t) = g;
|
| 17 |
+
|
| 18 |
+
x_results(:,t+1) = nPhi(:,disaster(t+1));
|
| 19 |
+
end
|
105/replication_package/UNIT_IES/solve_and_simulate.m
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file performs the following:
|
| 2 |
+
% 1. Solve the model by Taylor projection at the initial state.
|
| 3 |
+
% 2. Simulate the model without realized disasters.
|
| 4 |
+
|
| 5 |
+
%% make initial guess for a deterministic version of the model
|
| 6 |
+
|
| 7 |
+
% in a deterministic economy, the following variables are constant:
|
| 8 |
+
|
| 9 |
+
x1 = 1; % agents invests only in equity
|
| 10 |
+
x2 = 1;
|
| 11 |
+
tilp = 1/RHO; % price/earning ratio
|
| 12 |
+
hatyp = exp(G-meanB*P); % average growth
|
| 13 |
+
haty = hatyp;
|
| 14 |
+
rep = (1+tilp)/tilp*hatyp; % asset return
|
| 15 |
+
logq = log(1/rep); % price of bond
|
| 16 |
+
c1 = RHO/(1+RHO); % consumption/wealth ratio
|
| 17 |
+
c2 = c1;
|
| 18 |
+
logu1 = (RHO*log(c1)+log(1-c1)+log(rep))/RHO;
|
| 19 |
+
u1 = exp(logu1);
|
| 20 |
+
logu2 = (RHO*log(c2)+log(1-c2)+log(rep))/RHO;
|
| 21 |
+
u2 = exp(logu2);
|
| 22 |
+
f1 = (rep*u1);
|
| 23 |
+
f2 = (rep*u2);
|
| 24 |
+
|
| 25 |
+
k1 = MU;
|
| 26 |
+
|
| 27 |
+
tila1 = k1*(1+tilp);
|
| 28 |
+
|
| 29 |
+
state0 = tila1;
|
| 30 |
+
c0 = state0;
|
| 31 |
+
|
| 32 |
+
derivs0 = [f1;f2;x1;x2;logq];
|
| 33 |
+
|
| 34 |
+
derivs1 = zeros(model.n_f,model.n_x);
|
| 35 |
+
derivs2 = zeros(model.n_f,model.n_x^2);
|
| 36 |
+
derivs3 = zeros(model.n_f,model.n_x^3);
|
| 37 |
+
derivs4 = zeros(model.n_f,model.n_x^4);
|
| 38 |
+
|
| 39 |
+
if order==1
|
| 40 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1 );
|
| 41 |
+
elseif order==2
|
| 42 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2);
|
| 43 |
+
elseif order==3
|
| 44 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3 );
|
| 45 |
+
elseif order==4
|
| 46 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3,derivs4 );
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
%% solve the model
|
| 50 |
+
|
| 51 |
+
[coeffs,model] = tpsolve(initial_guess,state0,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 52 |
+
|
| 53 |
+
%% simulate the model
|
| 54 |
+
|
| 55 |
+
solve = 1;
|
| 56 |
+
stop = 0;
|
| 57 |
+
t = 0;
|
| 58 |
+
xt = state0;
|
| 59 |
+
while stop==0
|
| 60 |
+
t = t+1;
|
| 61 |
+
% evaluate the previous solution at the new point xt
|
| 62 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 63 |
+
|
| 64 |
+
% if residuals are too large solve again
|
| 65 |
+
if norm(R(:))>testF && solve==1
|
| 66 |
+
t
|
| 67 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 68 |
+
|
| 69 |
+
% evaluate the new solution
|
| 70 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 71 |
+
end
|
| 72 |
+
|
| 73 |
+
newxt = nPhi(:,disaster(t+1)); % new state
|
| 74 |
+
|
| 75 |
+
if t>=10 % after 10 periods start checking for convergence
|
| 76 |
+
if max(abs(newxt-xt))<1e-7
|
| 77 |
+
stop = 1;
|
| 78 |
+
state0 = xt;
|
| 79 |
+
coeffs0 = coeffs;
|
| 80 |
+
end
|
| 81 |
+
end
|
| 82 |
+
xt = newxt;
|
| 83 |
+
end
|
| 84 |
+
|
105/replication_package/UNIT_IES/summarize_results.m
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
normal = logical(disaster==1); % normal periods
|
| 3 |
+
d = logical(disaster>1); % disaster periods
|
| 4 |
+
|
| 5 |
+
tila1 = x_results(1,1:T);
|
| 6 |
+
|
| 7 |
+
x1 = y_results(3,1:T);
|
| 8 |
+
logq = y_results(5,1:T);
|
| 9 |
+
|
| 10 |
+
c1 = RHO/(1+RHO);
|
| 11 |
+
tilp = 1/RHO;
|
| 12 |
+
tilp = repmat(tilp,1,T);
|
| 13 |
+
q = exp(logq);
|
| 14 |
+
|
| 15 |
+
k1 = x1.*(1 - c1).*tila1./tilp;
|
| 16 |
+
tilb1 = (1 - x1).*(1 - c1).*tila1;
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
W1_share = k1 - NU*(k1 - MU) + (1 - NU)*tilb1./tilp; % wealth share after type changes
|
| 20 |
+
equity = k1 - NU*(k1 - MU);
|
| 21 |
+
|
| 22 |
+
debt_to_assets = -(1 - NU)*tilb1./tilp; % debt ratio (after type changes)
|
| 23 |
+
debt_to_GDP = -(1 - NU)*tilb1*period_length;
|
| 24 |
+
|
| 25 |
+
haty = nodes(1,double(disaster(1:T)));
|
| 26 |
+
|
| 27 |
+
% compute means by iterated expectations
|
| 28 |
+
|
| 29 |
+
roe = ((1 + tilp(2:T))./tilp(1:T-1).*haty(2:T)); % this is actual return from t to t+1.
|
| 30 |
+
mean_roe = 1/period_length*log((1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)))); % mean return
|
| 31 |
+
|
| 32 |
+
period_mean_roe = (1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)));
|
| 33 |
+
period_var_roe = (1-P)*mean((roe(normal(2:T)) - period_mean_roe).^2)+P*mean((roe(d(2:T)) - period_mean_roe).^2);
|
| 34 |
+
vol_roe = sqrt(period_var_roe/period_length);
|
| 35 |
+
|
| 36 |
+
rb = log(1./q(1:T-1))/period_length; % this is log return on bonds
|
| 37 |
+
mean_rb = (1-P)*mean(rb(normal(1:T-1)))+P*mean(rb(d(1:T-1)));
|
| 38 |
+
|
| 39 |
+
Rb = 1./q(2:T-1);
|
| 40 |
+
period_mean_rb = (1-P)*mean(Rb(normal(2:T-1)))+P*mean(Rb(d(2:T-1)));
|
| 41 |
+
period_var_rb = (1-P)*mean((Rb(normal(2:T-1)) - period_mean_rb).^2)+P*mean((Rb(d(2:T-1)) - period_mean_rb).^2);
|
| 42 |
+
vol_rb = sqrt(period_var_rb/period_length);
|
| 43 |
+
|
| 44 |
+
mean_equity = (1-P)*mean(equity(normal(1:T))) + P*mean(equity(d(1:T)));
|
| 45 |
+
mean_debt_to_assets = (1-P)*mean(debt_to_assets(normal(1:T))) + P*mean(debt_to_assets(d(1:T)));
|
| 46 |
+
mean_debt_to_GDP = (1-P)*mean(debt_to_GDP(normal(1:T))) + P*mean(debt_to_GDP(d(1:T)));
|
| 47 |
+
mean_W1_share = (1-P)*mean(W1_share(normal(1:T))) + P*mean(W1_share(d(1:T)));
|
| 48 |
+
|
| 49 |
+
% mean_W1_share_excluding_labor = mean_W1_share*(1+L) - MU*L;
|
| 50 |
+
% mean_debt_to_assets_excluding_labor = mean_debt_to_assets*(1+L);
|
| 51 |
+
% mean_debt_to_GDP_including_labor = mean_debt_to_GDP/(1+L);
|
| 52 |
+
% mean_equity_excluding_labor = mean_equity*(1+L) - MU*L;
|
| 53 |
+
|
| 54 |
+
mean_equity_excluding_labor = mean_equity/ALPHA - MU*(1 - ALPHA)/ALPHA;
|
| 55 |
+
mean_debt_to_assets_excluding_labor = mean_debt_to_assets/ALPHA;
|
| 56 |
+
mean_W1_share_excluding_labor = mean_equity_excluding_labor - mean_debt_to_assets_excluding_labor;
|
105/replication_package/User Guide.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4ae3ea65d6ead2e1e273aabe94a8a1f913ec926e7b77f7f75784b25d6db4748f
|
| 3 |
+
size 161394
|
105/replication_package/Variable_Disaster_Size/Parameters.m
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
period_length = 0.25;
|
| 2 |
+
|
| 3 |
+
P = 1 - exp(-.04*period_length); % disaster probability
|
| 4 |
+
|
| 5 |
+
% variable disaster size
|
| 6 |
+
B = -log(1 - [0.1384074;
|
| 7 |
+
0.2375926;
|
| 8 |
+
0.335;
|
| 9 |
+
0.4331111;
|
| 10 |
+
0.5516667;
|
| 11 |
+
0.653]);
|
| 12 |
+
|
| 13 |
+
% distribution of disaster size
|
| 14 |
+
probB = [0.6;
|
| 15 |
+
0.2;
|
| 16 |
+
0.088888889;
|
| 17 |
+
0.066666667;
|
| 18 |
+
0.022222222;
|
| 19 |
+
0.022222222];
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
meanB = B(:)'*probB;
|
| 23 |
+
|
| 24 |
+
Size = 1 - exp(-B(:)');
|
| 25 |
+
meanSize = Size*probB;
|
| 26 |
+
sdSize = sqrt((Size - meanSize).^2*probB(:));
|
| 27 |
+
|
| 28 |
+
G = 0.021*period_length; % drift of log output
|
| 29 |
+
|
| 30 |
+
RHO = 0.04*period_length; % time preference rate
|
| 31 |
+
|
| 32 |
+
NU = 0.02*period_length; % replacement rate
|
| 33 |
+
|
| 34 |
+
MU = 0.05; % popoulation share of agent 1
|
| 35 |
+
|
| 36 |
+
ALPHA = 1/3; % capital share in output
|
| 37 |
+
|
| 38 |
+
TAU = 0; % bond duration - start with short-term bonds
|
| 39 |
+
|
| 40 |
+
GAMMA1 = 1.000001; % start with unit risk aversion
|
| 41 |
+
GAMMA2 = GAMMA1;
|
| 42 |
+
|
| 43 |
+
delta_prob = 0.4; % default probability
|
| 44 |
+
delta_size = 0; % default size
|
| 45 |
+
|
| 46 |
+
|
105/replication_package/Variable_Disaster_Size/correct_params.m
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file changes the parameters gradually from their initival value to
|
| 2 |
+
% the target value
|
| 3 |
+
|
| 4 |
+
solve = 1;
|
| 5 |
+
stop = 0;
|
| 6 |
+
t = 0;
|
| 7 |
+
|
| 8 |
+
xt = state0;
|
| 9 |
+
params0 = params;
|
| 10 |
+
while stop==0
|
| 11 |
+
t = t + 1;
|
| 12 |
+
|
| 13 |
+
if t<=burn
|
| 14 |
+
factor = t/burn;
|
| 15 |
+
params = (1 - factor)*params0 + factor*newparams;
|
| 16 |
+
end
|
| 17 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 18 |
+
|
| 19 |
+
% if residuals are too large solve again
|
| 20 |
+
if norm(R(:))>testF && solve==1
|
| 21 |
+
t
|
| 22 |
+
[coeffs,model] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 23 |
+
|
| 24 |
+
% evaluate the new solution
|
| 25 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 26 |
+
end
|
| 27 |
+
|
| 28 |
+
newxt = nPhi(:,1); % assume no realized disasters
|
| 29 |
+
|
| 30 |
+
if t>burn+10 % after 10 periods start checking for convergence
|
| 31 |
+
if max(abs(newxt-xt))<1e-7
|
| 32 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 33 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 34 |
+
|
| 35 |
+
newxt = nPhi(:,1);
|
| 36 |
+
if max(abs(newxt-xt))<1e-7
|
| 37 |
+
stop = 1;
|
| 38 |
+
state0 = xt; % solution point
|
| 39 |
+
coeffs0 = coeffs;
|
| 40 |
+
end
|
| 41 |
+
end
|
| 42 |
+
end
|
| 43 |
+
xt = newxt;
|
| 44 |
+
end
|
| 45 |
+
|
105/replication_package/Variable_Disaster_Size/define_model.m
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%-------------------------------------------------------------------------
|
| 2 |
+
% The model: Safe Assets - the case of unit IES (THETA = 1)
|
| 3 |
+
% Bonds are long term and subject to a default shock deltap
|
| 4 |
+
%
|
| 5 |
+
% This file defines the model (see Appendix for the full derivation).
|
| 6 |
+
%
|
| 7 |
+
% Variables are denoted by small letters and
|
| 8 |
+
% parameters by capital letters. Future values are denoted by suffix p.
|
| 9 |
+
%-------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
clear,clc
|
| 12 |
+
|
| 13 |
+
%% Symbolic variables
|
| 14 |
+
|
| 15 |
+
syms RHO GAMMA1 GAMMA2 NU MU TAU real
|
| 16 |
+
syms f1 f2 f1p f2p x1 x2 x1p x2p real
|
| 17 |
+
syms logq logqp tilp tilpp real
|
| 18 |
+
syms state1 state1p state2 state2p hatyp deltap k1 tilb1 real
|
| 19 |
+
syms tila1 tila2 invtila1 invtila2 invtilp rbp rep c1 c2 c1p c2p q qp real
|
| 20 |
+
syms invc1 invc1p invc2 invc2p invf1 invf2 r1p r2p logu1p logu2p u1p u2p logf1 logf1p logf2 logf2p real
|
| 21 |
+
syms term1p term2p invr1p invr2p real
|
| 22 |
+
|
| 23 |
+
%% Parameters
|
| 24 |
+
|
| 25 |
+
symparams = [RHO,GAMMA1,GAMMA2,NU,MU,TAU];
|
| 26 |
+
|
| 27 |
+
%% State variables
|
| 28 |
+
|
| 29 |
+
state = [state1,state2]; % current period
|
| 30 |
+
statep = [state1p,state2p]; % future period
|
| 31 |
+
|
| 32 |
+
%% Control variables
|
| 33 |
+
|
| 34 |
+
control = [f1,f2,x1,x2,logq]; % current period
|
| 35 |
+
controlp = [f1p,f2p,x1p,x2p,logqp]; % future period
|
| 36 |
+
|
| 37 |
+
%% shocks
|
| 38 |
+
|
| 39 |
+
shocks = [hatyp,deltap];
|
| 40 |
+
|
| 41 |
+
%% auxiliary variables
|
| 42 |
+
|
| 43 |
+
tilp = 1/RHO; % price-dividend ratio for unit IES
|
| 44 |
+
tilpp = tilp; % next period
|
| 45 |
+
|
| 46 |
+
c1 = RHO/(1 + RHO); % consumption/wealth ratio of agent 1 for unit IES
|
| 47 |
+
c1p = c1; % next period
|
| 48 |
+
|
| 49 |
+
c2 = c1; % consumption/wealth ratio of agent 2 for unit IES
|
| 50 |
+
c2p = c2; % next period
|
| 51 |
+
|
| 52 |
+
logc1p = log(c1p);
|
| 53 |
+
logc2p = log(c2p);
|
| 54 |
+
|
| 55 |
+
invf1_ = 1/f1;
|
| 56 |
+
invf2_ = 1/f2;
|
| 57 |
+
|
| 58 |
+
logf1p_ = log(f1p);
|
| 59 |
+
logf2p_ = log(f2p);
|
| 60 |
+
|
| 61 |
+
invr1p_ = 1/r1p;
|
| 62 |
+
invr2p_ = 1/r2p;
|
| 63 |
+
|
| 64 |
+
q_ = exp(logq);
|
| 65 |
+
qp_ = exp(logqp);
|
| 66 |
+
|
| 67 |
+
invtila1_ = 1/tila1;
|
| 68 |
+
invtila2_ = 1/tila2;
|
| 69 |
+
|
| 70 |
+
rep_ = (1 + tilpp)/tilp*hatyp; % return on equity
|
| 71 |
+
rbp_ = (1 + TAU*qp)/q*(1 - deltap); % return on bond
|
| 72 |
+
|
| 73 |
+
u1p_ = exp(logu1p);
|
| 74 |
+
u2p_ = exp(logu2p);
|
| 75 |
+
|
| 76 |
+
%% MODEL CONDITIONS
|
| 77 |
+
|
| 78 |
+
tila1_ = (1 + tilp)*state1 + state2*(1 + TAU*q);
|
| 79 |
+
|
| 80 |
+
tila2_ = tilp + 1 - tila1;
|
| 81 |
+
|
| 82 |
+
k1_ = x1*(1 - c1)*tila1/tilp;
|
| 83 |
+
|
| 84 |
+
tilb1_ = (1 - x1)*(1 - c1)*tila1;
|
| 85 |
+
|
| 86 |
+
eq1 = tilb1*invtila2 + (1 - x2)*(1 - c2);
|
| 87 |
+
|
| 88 |
+
r1p_ = x1*rep + (1 - x1)*rbp;
|
| 89 |
+
|
| 90 |
+
r2p_ = x2*rep + (1 - x2)*rbp;
|
| 91 |
+
|
| 92 |
+
term1p_ = r1p^(1 - GAMMA1)*((1 - NU*(1 - MU))*u1p^(1 - GAMMA1)...
|
| 93 |
+
+ NU*(1 - MU)*u2p^(1 - GAMMA1))*invf1^(1 - GAMMA1);
|
| 94 |
+
|
| 95 |
+
term2p_ = r2p^(1 - GAMMA2)*((1 - NU*MU)*u2p^(1 - GAMMA2)...
|
| 96 |
+
+NU*MU*u1p^(1 - GAMMA2))*invf2^(1 - GAMMA2);
|
| 97 |
+
|
| 98 |
+
eq2 = -1 + term1p; % define f1 = (E(r1p*u1p)^(1-GAMMA1))^(1/(1-GAMMA1))
|
| 99 |
+
|
| 100 |
+
eq3 = -1 + term2p; % define f2 similarly
|
| 101 |
+
|
| 102 |
+
logu1p_ = RHO/(1 + RHO)*logc1p + 1/(1 + RHO)*log(1 - c1p) + 1/(1 + RHO)*logf1p;
|
| 103 |
+
|
| 104 |
+
logu2p_ = RHO/(1 + RHO)*logc2p + 1/(1 + RHO)*log(1 - c2p) + 1/(1 + RHO)*logf2p;
|
| 105 |
+
|
| 106 |
+
eq4 = (rep - rbp)*term1p*invr1p;
|
| 107 |
+
|
| 108 |
+
eq5 = (rep - rbp)*term2p*invr2p;
|
| 109 |
+
|
| 110 |
+
%% Function f (Ef = 0 imposes model conditions)
|
| 111 |
+
|
| 112 |
+
f_fun = [eq1;eq2;eq3;eq4;eq5];
|
| 113 |
+
|
| 114 |
+
%% law of motion of state variables
|
| 115 |
+
|
| 116 |
+
Phi_fun = [k1 - NU*(k1 - MU); % law of motion of state1p
|
| 117 |
+
(1 - NU)*tilb1*(1 - deltap)/(hatyp*q)]; % law of motion of state2p
|
| 118 |
+
|
| 119 |
+
%% collect auxiliary variables and functions
|
| 120 |
+
|
| 121 |
+
allvars=who;
|
| 122 |
+
auxfuns=[];
|
| 123 |
+
auxvars=[];
|
| 124 |
+
for i=1:length(allvars)
|
| 125 |
+
if strcmp(allvars{i}(end),'_')
|
| 126 |
+
eval(['tempfun=' allvars{i} ';'])
|
| 127 |
+
eval(['tempvar=' allvars{i}(1:end-1) ';'])
|
| 128 |
+
auxfuns=[auxfuns;tempfun];
|
| 129 |
+
auxvars=[auxvars;tempvar];
|
| 130 |
+
end
|
| 131 |
+
end
|
| 132 |
+
|
| 133 |
+
%% Approximation order (<=4)
|
| 134 |
+
|
| 135 |
+
order = 4;
|
| 136 |
+
|
| 137 |
+
%% Preprocess model and save
|
| 138 |
+
|
| 139 |
+
model = prepare_tp(f_fun,Phi_fun,controlp,control,statep,state,shocks,symparams,order,auxfuns,auxvars);
|
| 140 |
+
|
| 141 |
+
save('model')
|
| 142 |
+
|
105/replication_package/Variable_Disaster_Size/make_Table_7.m
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Variable disaster size, long-term bonds, default probability
|
| 2 |
+
|
| 3 |
+
clear,clc
|
| 4 |
+
|
| 5 |
+
load('model')
|
| 6 |
+
addpath('files')
|
| 7 |
+
|
| 8 |
+
Parameters;
|
| 9 |
+
|
| 10 |
+
% make the vector of parameters
|
| 11 |
+
params = eval(symparams);
|
| 12 |
+
|
| 13 |
+
% distribution of hatyp and deltap
|
| 14 |
+
nodes = [exp([G,kron(G-B(:)',ones(1,2))]);
|
| 15 |
+
0,kron(ones(1,numel(B)),[0,delta_size])];% realizations
|
| 16 |
+
|
| 17 |
+
weights = [1-P,P*kron(probB(:)',[1-delta_prob,delta_prob])]; % corresponding probabilities
|
| 18 |
+
|
| 19 |
+
rng('default')
|
| 20 |
+
|
| 21 |
+
T = 1e5;
|
| 22 |
+
|
| 23 |
+
N_disasters = ceil(T*P);
|
| 24 |
+
ptr = 1 + round(cumsum([0;probB(:)])*N_disasters);
|
| 25 |
+
disaster_state = zeros(1,N_disasters);
|
| 26 |
+
for i = 1:numel(probB)
|
| 27 |
+
disaster_state(ptr(i):ptr(i+1)-1) = i;
|
| 28 |
+
end
|
| 29 |
+
randorder = rand(1,N_disasters);
|
| 30 |
+
[~,I] = sort(randorder);
|
| 31 |
+
disaster_state = disaster_state(I);
|
| 32 |
+
|
| 33 |
+
% disaster shock (normal = 1, disaster>1)
|
| 34 |
+
|
| 35 |
+
disaster = zeros(1,T+1);
|
| 36 |
+
disaster(randperm(T,N_disasters)) = 1;
|
| 37 |
+
|
| 38 |
+
default = double(rand(1,T+1)<delta_prob);
|
| 39 |
+
|
| 40 |
+
n = 1;
|
| 41 |
+
for t = 1:T+1
|
| 42 |
+
if disaster(t)==1
|
| 43 |
+
disaster(t) = 1 + 2*disaster_state(n) - (1 - default(t));
|
| 44 |
+
n = n + 1;
|
| 45 |
+
end
|
| 46 |
+
end
|
| 47 |
+
disaster(disaster==0) = 1;
|
| 48 |
+
|
| 49 |
+
GAMMA1=1.46;
|
| 50 |
+
GAMMA2=GAMMA1;
|
| 51 |
+
params(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 52 |
+
params(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 53 |
+
|
| 54 |
+
step_size=1;
|
| 55 |
+
|
| 56 |
+
% tolerance for the Newton solver
|
| 57 |
+
tolX=1e-5; tolF=1e-5; maxiter=10; testF=1e-5;
|
| 58 |
+
% tolerance for the least squares solver (if a simple Newton fails)
|
| 59 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',100,'display','iter-detailed'); % use lsqnonlin if a simple Newton algorithm fails
|
| 60 |
+
|
| 61 |
+
solve_and_simulate;
|
| 62 |
+
simulate_with_disasters;
|
| 63 |
+
summarize_results;
|
| 64 |
+
|
| 65 |
+
%%
|
| 66 |
+
GAMMA1=1.46;
|
| 67 |
+
GAMMA2=4.13;
|
| 68 |
+
|
| 69 |
+
burn=10;
|
| 70 |
+
newparams=params;
|
| 71 |
+
newparams(logical(symparams==sym('GAMMA1')))=GAMMA1;
|
| 72 |
+
newparams(logical(symparams==sym('GAMMA2')))=GAMMA2;
|
| 73 |
+
|
| 74 |
+
correct_params;
|
| 75 |
+
simulate_with_disasters;
|
| 76 |
+
summarize_results;
|
| 77 |
+
|
| 78 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 79 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 80 |
+
Table_vol = [vol_roe,vol_rb];
|
| 81 |
+
|
| 82 |
+
save('VariableDisasterSize')
|
| 83 |
+
|
| 84 |
+
%% add default
|
| 85 |
+
|
| 86 |
+
for delta_size = .05:.05:.2
|
| 87 |
+
nodes(2,:) = [0,kron(ones(1,numel(B)),[0,delta_size])];
|
| 88 |
+
|
| 89 |
+
correct_params;
|
| 90 |
+
simulate_with_disasters;
|
| 91 |
+
summarize_results;
|
| 92 |
+
|
| 93 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 94 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 95 |
+
Table_vol = [vol_roe,vol_rb];
|
| 96 |
+
end
|
| 97 |
+
|
| 98 |
+
save('ShortDefault')
|
| 99 |
+
|
| 100 |
+
%% change duration
|
| 101 |
+
|
| 102 |
+
load('VariableDisasterSize')
|
| 103 |
+
|
| 104 |
+
for TAU = [0.1:.1:.85,.9,.91:.01:.97,.975]
|
| 105 |
+
|
| 106 |
+
burn=5;
|
| 107 |
+
|
| 108 |
+
newparams = params;
|
| 109 |
+
newparams(logical(symparams==sym('TAU'))) = TAU;
|
| 110 |
+
|
| 111 |
+
correct_params;
|
| 112 |
+
simulate_with_disasters;
|
| 113 |
+
summarize_results;
|
| 114 |
+
|
| 115 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 116 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 117 |
+
Table_vol = [vol_roe,vol_rb];
|
| 118 |
+
|
| 119 |
+
if TAU==.95
|
| 120 |
+
save('Duration5')
|
| 121 |
+
end
|
| 122 |
+
|
| 123 |
+
end
|
| 124 |
+
|
| 125 |
+
%% add default
|
| 126 |
+
|
| 127 |
+
load('Duration5')
|
| 128 |
+
for delta_size = .05:.05:.2
|
| 129 |
+
nodes(2,:) = [0,kron(ones(1,numel(B)),[0,delta_size])];
|
| 130 |
+
|
| 131 |
+
correct_params;
|
| 132 |
+
simulate_with_disasters;
|
| 133 |
+
summarize_results;
|
| 134 |
+
|
| 135 |
+
Table = [GAMMA1,GAMMA2,RHO,mean_roe,mean_rb,mean_equity,mean_W1_share,mean_debt_to_assets,mean_debt_to_GDP,mean(abs(R_results(:))),max(abs(R_results(:)))];
|
| 136 |
+
Table_labor = [GAMMA1,GAMMA2,mean_equity_excluding_labor,mean_W1_share_excluding_labor,mean_debt_to_assets_excluding_labor,mean_debt_to_GDP];
|
| 137 |
+
Table_vol = [vol_roe,vol_rb];
|
| 138 |
+
end
|
| 139 |
+
|
| 140 |
+
save('LongDefault')
|
| 141 |
+
|
| 142 |
+
%% show results
|
| 143 |
+
clc
|
| 144 |
+
|
| 145 |
+
homefolder = pwd;
|
| 146 |
+
cd ..
|
| 147 |
+
diary on
|
| 148 |
+
|
| 149 |
+
disp('********** Table 7 **********')
|
| 150 |
+
|
| 151 |
+
load([homefolder '\VariableDisasterSize'])
|
| 152 |
+
|
| 153 |
+
disp('variable disaster size')
|
| 154 |
+
disp([round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)])
|
| 155 |
+
|
| 156 |
+
load([homefolder '\ShortDefault'])
|
| 157 |
+
|
| 158 |
+
disp('default probability')
|
| 159 |
+
disp([round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)])
|
| 160 |
+
|
| 161 |
+
load([homefolder '\Duration5'])
|
| 162 |
+
|
| 163 |
+
disp('long term bonds, no default')
|
| 164 |
+
disp([round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)])
|
| 165 |
+
|
| 166 |
+
load([homefolder '\LongDefault'])
|
| 167 |
+
|
| 168 |
+
disp('long term bonds with default')
|
| 169 |
+
disp([round(Table(:,[1,2,4,5]),3),Table_vol,round(Table_labor(:,[3,4,5]),3),round(Table_labor(:,[6]),2)])
|
| 170 |
+
|
| 171 |
+
%% accuracy measures
|
| 172 |
+
disp('Appendix Table 3: Accuracy Measures for Table 7')
|
| 173 |
+
|
| 174 |
+
load([homefolder '\VariableDisasterSize'])
|
| 175 |
+
|
| 176 |
+
disp('variable disaster size')
|
| 177 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 178 |
+
disp(Accuarcy)
|
| 179 |
+
|
| 180 |
+
load([homefolder '\ShortDefault'])
|
| 181 |
+
|
| 182 |
+
disp('default probability')
|
| 183 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 184 |
+
disp(Accuarcy)
|
| 185 |
+
|
| 186 |
+
load([homefolder '\Duration5'])
|
| 187 |
+
|
| 188 |
+
disp('long term bonds, no default')
|
| 189 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 190 |
+
disp(Accuarcy)
|
| 191 |
+
|
| 192 |
+
load([homefolder '\LongDefault'])
|
| 193 |
+
|
| 194 |
+
disp('long term bonds with default')
|
| 195 |
+
Accuarcy = [round(Table(:,1),3),round(log10(Table(:,end-1:end)),1)];
|
| 196 |
+
disp(Accuarcy)
|
| 197 |
+
|
| 198 |
+
diary off
|
| 199 |
+
|
| 200 |
+
cd(homefolder)
|
105/replication_package/Variable_Disaster_Size/simulate_with_disasters.m
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% Simulate with disasters
|
| 2 |
+
y_results = zeros(model.n_y,T+1);
|
| 3 |
+
x_results = zeros(model.n_x,T+1);
|
| 4 |
+
R_results = zeros(model.n_f,T+1);
|
| 5 |
+
|
| 6 |
+
x_results(:,1) = state0;
|
| 7 |
+
|
| 8 |
+
for t = 1:T
|
| 9 |
+
t
|
| 10 |
+
xt = x_results(:,t);
|
| 11 |
+
|
| 12 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 13 |
+
|
| 14 |
+
% store results
|
| 15 |
+
R_results(:,t) = R;
|
| 16 |
+
y_results(:,t) = g;
|
| 17 |
+
|
| 18 |
+
x_results(:,t+1) = nPhi(:,disaster(t+1));
|
| 19 |
+
end
|
105/replication_package/Variable_Disaster_Size/solve_and_simulate.m
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
% This file performs the following:
|
| 2 |
+
% 1. Solve the model by Taylor projection at the initial state.
|
| 3 |
+
% 2. Simulate the model without realized disasters.
|
| 4 |
+
|
| 5 |
+
%% make initial guess for a deterministic version of the model
|
| 6 |
+
|
| 7 |
+
% in a deterministic economy, the following variables are constant:
|
| 8 |
+
|
| 9 |
+
x1 = 1; % agents invests only in equity
|
| 10 |
+
x2 = 1;
|
| 11 |
+
tilp = 1/RHO; % price/earning ratio
|
| 12 |
+
hatyp = exp(G-meanB*P); % average growth
|
| 13 |
+
haty = hatyp;
|
| 14 |
+
rep = (1+tilp)/tilp*hatyp; % asset return
|
| 15 |
+
logq = log(1/rep); % price of bond
|
| 16 |
+
c1 = RHO/(1+RHO); % consumption/wealth ratio
|
| 17 |
+
c2 = c1;
|
| 18 |
+
logu1 = (RHO*log(c1)+log(1-c1)+log(rep))/RHO;
|
| 19 |
+
u1 = exp(logu1);
|
| 20 |
+
logu2 = (RHO*log(c2)+log(1-c2)+log(rep))/RHO;
|
| 21 |
+
u2 = exp(logu2);
|
| 22 |
+
f1 = (rep*u1);
|
| 23 |
+
f2 = (rep*u2);
|
| 24 |
+
|
| 25 |
+
k1 = MU;
|
| 26 |
+
|
| 27 |
+
tila1 = k1*(1+tilp);
|
| 28 |
+
|
| 29 |
+
state0 = [k1;0];
|
| 30 |
+
c0 = state0;
|
| 31 |
+
|
| 32 |
+
derivs0 = [f1;f2;x1;x2;logq];
|
| 33 |
+
|
| 34 |
+
derivs1 = zeros(model.n_f,model.n_x);
|
| 35 |
+
derivs2 = zeros(model.n_f,model.n_x^2);
|
| 36 |
+
derivs3 = zeros(model.n_f,model.n_x^3);
|
| 37 |
+
derivs4 = zeros(model.n_f,model.n_x^4);
|
| 38 |
+
|
| 39 |
+
if order==1
|
| 40 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1 );
|
| 41 |
+
elseif order==2
|
| 42 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2);
|
| 43 |
+
elseif order==3
|
| 44 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3 );
|
| 45 |
+
elseif order==4
|
| 46 |
+
[ initial_guess ] = derivs2coeffs( model,derivs0,derivs1,derivs2,derivs3,derivs4 );
|
| 47 |
+
end
|
| 48 |
+
|
| 49 |
+
%% solve the model
|
| 50 |
+
|
| 51 |
+
[coeffs,model] = tpsolve(initial_guess,state0,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 52 |
+
|
| 53 |
+
%% simulate the model
|
| 54 |
+
|
| 55 |
+
solve = 1;
|
| 56 |
+
stop = 0;
|
| 57 |
+
t = 0;
|
| 58 |
+
xt = state0;
|
| 59 |
+
while stop==0
|
| 60 |
+
t = t+1;
|
| 61 |
+
% evaluate the previous solution at the new point xt
|
| 62 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 63 |
+
|
| 64 |
+
% if residuals are too large solve again
|
| 65 |
+
if norm(R(:))>testF && solve==1
|
| 66 |
+
t
|
| 67 |
+
[coeffs] = tpsolve(coeffs,xt,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS); % solve
|
| 68 |
+
|
| 69 |
+
% evaluate the new solution
|
| 70 |
+
[R,g,nPhi] = residual(coeffs,xt,params,c0,nodes,weights);
|
| 71 |
+
end
|
| 72 |
+
|
| 73 |
+
newxt = nPhi(:,disaster(t+1)); % new state
|
| 74 |
+
|
| 75 |
+
if t>=10 % after 10 periods start checking for convergence
|
| 76 |
+
if max(abs(newxt-xt))<1e-7
|
| 77 |
+
stop = 1;
|
| 78 |
+
state0 = xt;
|
| 79 |
+
coeffs0 = coeffs;
|
| 80 |
+
end
|
| 81 |
+
end
|
| 82 |
+
xt = newxt;
|
| 83 |
+
end
|
| 84 |
+
|
105/replication_package/Variable_Disaster_Size/summarize_results.m
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
normal = logical(disaster==1); % normal periods
|
| 3 |
+
d = logical(disaster>1); % disaster periods
|
| 4 |
+
|
| 5 |
+
state1 = x_results(1,1:T);
|
| 6 |
+
state2 = x_results(2,1:T);
|
| 7 |
+
|
| 8 |
+
x1 = y_results(3,1:T);
|
| 9 |
+
logq = y_results(5,1:T);
|
| 10 |
+
|
| 11 |
+
c1 = RHO/(1+RHO);
|
| 12 |
+
tilp = 1/RHO;
|
| 13 |
+
tilp = repmat(tilp,1,T);
|
| 14 |
+
q = exp(logq);
|
| 15 |
+
|
| 16 |
+
tila1 = (1 + tilp).*state1 + state2.*(1 + TAU*q);
|
| 17 |
+
|
| 18 |
+
k1 = x1.*(1 - c1).*tila1./tilp;
|
| 19 |
+
tilb1 = (1 - x1).*(1 - c1).*tila1;
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
W1_share = k1 - NU*(k1 - MU) + (1 - NU)*tilb1./tilp; % wealth share after type changes
|
| 23 |
+
equity = k1 - NU*(k1 - MU);
|
| 24 |
+
|
| 25 |
+
debt_to_assets = -(1 - NU)*tilb1./tilp; % debt ratio (after type changes)
|
| 26 |
+
debt_to_GDP = -(1 - NU)*tilb1*period_length;
|
| 27 |
+
|
| 28 |
+
haty = nodes(1,double(disaster(1:T)));
|
| 29 |
+
delta = nodes(2,double(disaster(1:T)));
|
| 30 |
+
|
| 31 |
+
% compute means by iterated expectations
|
| 32 |
+
|
| 33 |
+
roe = ((1 + tilp(2:T))./tilp(1:T-1).*haty(2:T)); % this is actual return from t to t+1.
|
| 34 |
+
mean_roe = 1/period_length*log((1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)))); % mean return
|
| 35 |
+
|
| 36 |
+
period_mean_roe = (1-P)*mean(roe(normal(2:T)))+P*mean(roe(d(2:T)));
|
| 37 |
+
period_var_roe = (1-P)*mean((roe(normal(2:T)) - period_mean_roe).^2)+P*mean((roe(d(2:T)) - period_mean_roe).^2);
|
| 38 |
+
vol_roe = sqrt(period_var_roe/period_length);
|
| 39 |
+
|
| 40 |
+
rb = log((1 + TAU*q(2:T))./q(1:T-1)).*(1 - delta(2:T))/period_length; % this is log return on bonds
|
| 41 |
+
mean_rb = (1-P)*mean(rb(normal(1:T-1)))+P*mean(rb(d(1:T-1)));
|
| 42 |
+
|
| 43 |
+
Rb = (1 + TAU*q(3:T))./q(2:T-1).*(1 - delta(3:T));
|
| 44 |
+
period_mean_rb = (1-P)*mean(Rb(normal(2:T-1)))+P*mean(Rb(d(2:T-1)));
|
| 45 |
+
period_var_rb = (1-P)*mean((Rb(normal(2:T-1)) - period_mean_rb).^2)+P*mean((Rb(d(2:T-1)) - period_mean_rb).^2);
|
| 46 |
+
vol_rb = sqrt(period_var_rb/period_length);
|
| 47 |
+
|
| 48 |
+
mean_equity = (1-P)*mean(equity(normal(1:T))) + P*mean(equity(d(1:T)));
|
| 49 |
+
mean_debt_to_assets = (1-P)*mean(debt_to_assets(normal(1:T))) + P*mean(debt_to_assets(d(1:T)));
|
| 50 |
+
mean_debt_to_GDP = (1-P)*mean(debt_to_GDP(normal(1:T))) + P*mean(debt_to_GDP(d(1:T)));
|
| 51 |
+
mean_W1_share = (1-P)*mean(W1_share(normal(1:T))) + P*mean(W1_share(d(1:T)));
|
| 52 |
+
|
| 53 |
+
mean_equity_excluding_labor = mean_equity/ALPHA - MU*(1 - ALPHA)/ALPHA;
|
| 54 |
+
mean_debt_to_assets_excluding_labor = mean_debt_to_assets/ALPHA;
|
| 55 |
+
mean_W1_share_excluding_labor = mean_equity_excluding_labor - mean_debt_to_assets_excluding_labor;
|
105/replication_package/examples/rbc/prepare_model.m
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%------------------------------------------------------------------
|
| 2 |
+
% This script shows how to solve the RBC model by Taylor projection
|
| 3 |
+
%------------------------------------------------------------------
|
| 4 |
+
|
| 5 |
+
clear,clc
|
| 6 |
+
|
| 7 |
+
%-----------------------------------------
|
| 8 |
+
% Define symbolic variables and parameters
|
| 9 |
+
%-----------------------------------------
|
| 10 |
+
|
| 11 |
+
syms k kp c cp z zp epsp real
|
| 12 |
+
syms BETA GAMMA ALPHA RHO DELTA SIGMA real
|
| 13 |
+
|
| 14 |
+
%-------------------------------------------------
|
| 15 |
+
% Function f (Euler condition) in a unit-free form
|
| 16 |
+
%-------------------------------------------------
|
| 17 |
+
|
| 18 |
+
f_fun=BETA*(c/cp)^GAMMA*(ALPHA*exp(zp)*kp^(ALPHA-1)+1-DELTA)-1;
|
| 19 |
+
|
| 20 |
+
%-------------------------------------------------------
|
| 21 |
+
% Function Phi (law of motion of capital and technology)
|
| 22 |
+
%-------------------------------------------------------
|
| 23 |
+
|
| 24 |
+
Phi_fun=[exp(z)*k^ALPHA+(1-DELTA)*k-c;
|
| 25 |
+
RHO*z+SIGMA*epsp];
|
| 26 |
+
|
| 27 |
+
%--------------------------
|
| 28 |
+
% Vector of state variables
|
| 29 |
+
%--------------------------
|
| 30 |
+
|
| 31 |
+
x=[k,z]; % current period
|
| 32 |
+
xp=[kp,zp]; % future period
|
| 33 |
+
|
| 34 |
+
%----------------------------
|
| 35 |
+
% Vector of control variables
|
| 36 |
+
%----------------------------
|
| 37 |
+
|
| 38 |
+
y=[c]; % current period
|
| 39 |
+
yp=[cp]; % future period
|
| 40 |
+
|
| 41 |
+
%-----------------
|
| 42 |
+
% Vector of shocks
|
| 43 |
+
%-----------------
|
| 44 |
+
|
| 45 |
+
shocks=[epsp];
|
| 46 |
+
|
| 47 |
+
%---------------------
|
| 48 |
+
% Vector of parameters
|
| 49 |
+
%---------------------
|
| 50 |
+
|
| 51 |
+
symparams=[BETA,GAMMA,ALPHA,RHO,DELTA,SIGMA];
|
| 52 |
+
|
| 53 |
+
%--------------------
|
| 54 |
+
% Approximation order
|
| 55 |
+
%--------------------
|
| 56 |
+
|
| 57 |
+
order=4; % fourth order is the maximum possible
|
| 58 |
+
|
| 59 |
+
%----------------
|
| 60 |
+
% Call prepare_tp
|
| 61 |
+
%----------------
|
| 62 |
+
|
| 63 |
+
model=prepare_tp(f_fun,Phi_fun,yp,y,xp,x,shocks,symparams,order);
|
| 64 |
+
|
| 65 |
+
%-----------
|
| 66 |
+
% Save model
|
| 67 |
+
%-----------
|
| 68 |
+
|
| 69 |
+
save('model') % you will need this later
|
105/replication_package/examples/rbc/prepare_model_auxiliary_functions.m
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%----------------------------------------------
|
| 2 |
+
% RBC model with auxiliary functions
|
| 3 |
+
%----------------------------------------------
|
| 4 |
+
|
| 5 |
+
clear,clc
|
| 6 |
+
|
| 7 |
+
%-----------------------------------------
|
| 8 |
+
% Define symbolic variables and parameters
|
| 9 |
+
%-----------------------------------------
|
| 10 |
+
|
| 11 |
+
syms k kp c cp z zp epsp real
|
| 12 |
+
syms BETA GAMMA ALPHA RHO DELTA SIGMA real
|
| 13 |
+
|
| 14 |
+
%-------------------------------
|
| 15 |
+
% Define the auxiliary functions
|
| 16 |
+
%-------------------------------
|
| 17 |
+
|
| 18 |
+
% Logs of consumption and capital.
|
| 19 |
+
syms logc logcp logk logkp real
|
| 20 |
+
logc_=log(c);
|
| 21 |
+
logcp_=log(cp);
|
| 22 |
+
logk_=log(k);
|
| 23 |
+
logkp_=log(kp);
|
| 24 |
+
|
| 25 |
+
% Log and level of future mpk.
|
| 26 |
+
syms mpkp logmpkp real
|
| 27 |
+
logmpkp_=log(ALPHA)+zp+(ALPHA-1)*logkp;
|
| 28 |
+
mpkp_=exp(logmpkp);
|
| 29 |
+
|
| 30 |
+
% Log and level of stochastic discount factor.
|
| 31 |
+
syms mp logmp real
|
| 32 |
+
logmp_=log(BETA)+GAMMA*(logc-logcp);
|
| 33 |
+
mp_=exp(logmp);
|
| 34 |
+
|
| 35 |
+
% Log and level of output.
|
| 36 |
+
syms logoutput output real
|
| 37 |
+
logoutput_=z+ALPHA*logk;
|
| 38 |
+
output_=exp(logoutput);
|
| 39 |
+
|
| 40 |
+
%-----------------------------
|
| 41 |
+
% Function f (Euler condition)
|
| 42 |
+
%-----------------------------
|
| 43 |
+
f_fun=mp*(mpkp+1-DELTA)-1;
|
| 44 |
+
|
| 45 |
+
%-------------------------------------------------------
|
| 46 |
+
% Function Phi (law of motion of capital and technology)
|
| 47 |
+
%-------------------------------------------------------
|
| 48 |
+
|
| 49 |
+
Phi_fun=[output+(1-DELTA)*k-c;
|
| 50 |
+
RHO*z+SIGMA*epsp];
|
| 51 |
+
|
| 52 |
+
%--------------------------
|
| 53 |
+
% Vector of state variables
|
| 54 |
+
%--------------------------
|
| 55 |
+
x=[k,z]; % current period
|
| 56 |
+
xp=[kp,zp]; % future period
|
| 57 |
+
|
| 58 |
+
%----------------------------
|
| 59 |
+
% Vector of control variables
|
| 60 |
+
%----------------------------
|
| 61 |
+
y=[c]; % current period
|
| 62 |
+
yp=[cp]; % future period
|
| 63 |
+
|
| 64 |
+
%-----------------
|
| 65 |
+
% Vector of shocks
|
| 66 |
+
%-----------------
|
| 67 |
+
shocks=[epsp];
|
| 68 |
+
|
| 69 |
+
%---------------------
|
| 70 |
+
% Vector of parameters
|
| 71 |
+
%---------------------
|
| 72 |
+
symparams=[BETA,GAMMA,ALPHA,RHO,DELTA,SIGMA];
|
| 73 |
+
|
| 74 |
+
%-----------------------------------------------------------
|
| 75 |
+
% Vectors of auxiliary functions and corresponding variables
|
| 76 |
+
%-----------------------------------------------------------
|
| 77 |
+
|
| 78 |
+
% you can do it manually:
|
| 79 |
+
|
| 80 |
+
% auxfuns=[logc_;logcp_;logk_;logkp_;logmp_;logmpkp_;logoutput_;mp_;mpkp_;output_];
|
| 81 |
+
% auxvars=[logc;logcp;logk;logkp;logmp;logmpkp;logoutput;mp;mpkp;output];
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
% or automatically by the following code (the names of the
|
| 85 |
+
% auxiliary functions must be the same as the auxiliary variables with an
|
| 86 |
+
% underscore suffix):
|
| 87 |
+
|
| 88 |
+
allvars=who;
|
| 89 |
+
auxfuns=[];
|
| 90 |
+
auxvars=[];
|
| 91 |
+
for i=1:length(allvars)
|
| 92 |
+
if strcmp(allvars{i}(end),'_')
|
| 93 |
+
eval(['tempfun=' allvars{i} ';'])
|
| 94 |
+
eval(['tempvar=' allvars{i}(1:end-1) ';'])
|
| 95 |
+
auxfuns=[auxfuns(:);tempfun(:)];
|
| 96 |
+
auxvars=[auxvars(:);tempvar(:)];
|
| 97 |
+
end
|
| 98 |
+
end
|
| 99 |
+
|
| 100 |
+
% Note that f is a function of the model variables and the auxiliary
|
| 101 |
+
% variables. To get f as a function of the model variables only, use the
|
| 102 |
+
% function subsf:
|
| 103 |
+
|
| 104 |
+
f_noaux = subsf( f_fun,auxvars,auxfuns );
|
| 105 |
+
|
| 106 |
+
% Compare f with f_noaux
|
| 107 |
+
|
| 108 |
+
f_fun,f_noaux
|
| 109 |
+
|
| 110 |
+
% Display the auxiliary equations:
|
| 111 |
+
|
| 112 |
+
[auxvars,auxfuns]
|
| 113 |
+
|
| 114 |
+
%--------------------
|
| 115 |
+
% Approximation order
|
| 116 |
+
%--------------------
|
| 117 |
+
order=4; % fourth order is the maximum possible
|
| 118 |
+
|
| 119 |
+
%----------------
|
| 120 |
+
% Call prepare_tp
|
| 121 |
+
%----------------
|
| 122 |
+
model=prepare_tp(f_fun,Phi_fun,yp,y,xp,x,shocks,symparams,order,auxfuns,auxvars);
|
| 123 |
+
|
| 124 |
+
%-----------
|
| 125 |
+
% Save model
|
| 126 |
+
%-----------
|
| 127 |
+
save('model') % you will need this later
|
105/replication_package/examples/rbc/solve_continuation.m
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%--------------------------------------------
|
| 2 |
+
% Solve the RBC model by continuation method
|
| 3 |
+
%--------------------------------------------
|
| 4 |
+
|
| 5 |
+
clear,clc
|
| 6 |
+
|
| 7 |
+
%---------------------------------------------------------
|
| 8 |
+
% Add folder 'files' to the search path and load the model
|
| 9 |
+
%---------------------------------------------------------
|
| 10 |
+
addpath('files');
|
| 11 |
+
load('model')
|
| 12 |
+
|
| 13 |
+
%----------------------------------------------------------------------------
|
| 14 |
+
% Provide nodes and weights for the quadrature that approximates expectations
|
| 15 |
+
%----------------------------------------------------------------------------
|
| 16 |
+
n_e=1; % number of shocks.
|
| 17 |
+
[n_nodes,nodes,weights] = Monomials_2(n_e,eye(n_e)); % this quadrature function was written by Judd, Maliar, Maliar and Valero (2014).
|
| 18 |
+
nodes=nodes'; % transpose to n_e-by-n_nodes
|
| 19 |
+
|
| 20 |
+
%----------------------------------------------------
|
| 21 |
+
% Choose parameter values with a closed-form solution
|
| 22 |
+
%----------------------------------------------------
|
| 23 |
+
BETA=.96; GAMMA=1; ALPHA=.3; RHO=.8; DELTA=1; SIGMA=.02;
|
| 24 |
+
params=eval(symparams);
|
| 25 |
+
|
| 26 |
+
%-----------------------------------------------------------------------
|
| 27 |
+
% The closed-form solution for the case GAMMA=1, DELTA=1 for consumption
|
| 28 |
+
%-----------------------------------------------------------------------
|
| 29 |
+
|
| 30 |
+
g=(1-ALPHA*BETA)*exp(z)*k^ALPHA;
|
| 31 |
+
|
| 32 |
+
%---------------------------------------------------------
|
| 33 |
+
% Use the closed-form solution to produce an initial guess
|
| 34 |
+
%---------------------------------------------------------
|
| 35 |
+
|
| 36 |
+
% differentiate the closed-form solution up to fourth order
|
| 37 |
+
gx=jacobian(g,x);
|
| 38 |
+
gxx=jacobian(gx(:),x);
|
| 39 |
+
gxxx=jacobian(gxx(:),x);
|
| 40 |
+
gxxxx=jacobian(gxxx(:),x);
|
| 41 |
+
|
| 42 |
+
% choose some arbitrary state - I use the steady state of the model of
|
| 43 |
+
% interest (with DELTA=.1)
|
| 44 |
+
|
| 45 |
+
k0=((1/BETA-1+.1)/ALPHA)^(1/(ALPHA-1));
|
| 46 |
+
z0=0;
|
| 47 |
+
|
| 48 |
+
x0=[k0;z0];
|
| 49 |
+
|
| 50 |
+
% compute g(x) and its derivatives at x0
|
| 51 |
+
|
| 52 |
+
g0=double(subs(g,x(:),x0));
|
| 53 |
+
gx0=double(subs(gx,x(:),x0));
|
| 54 |
+
gxx0=double(subs(gxx,x(:),x0));
|
| 55 |
+
gxxx0=double(subs(gxxx,x(:),x0));
|
| 56 |
+
gxxxx0=double(subs(gxxxx,x(:),x0));
|
| 57 |
+
|
| 58 |
+
% transform the derivatives into a vector of coefficients
|
| 59 |
+
|
| 60 |
+
[ initial_guess ] = derivs2coeffs(model,g0,gx0,gxx0,gxxx0,gxxxx0);
|
| 61 |
+
|
| 62 |
+
% this is for order=4. for lower orders include only the relevant
|
| 63 |
+
% derivatives, e.g. derivs2coeffs(model,g0,gx0,gxx0) is for second order.
|
| 64 |
+
|
| 65 |
+
% define the center of the initial guess (this is the point at which we computed
|
| 66 |
+
% the derivatives)
|
| 67 |
+
|
| 68 |
+
c0=x0;
|
| 69 |
+
|
| 70 |
+
% now we have the initial guess, and we can proceed to solve the model by
|
| 71 |
+
% continuation
|
| 72 |
+
|
| 73 |
+
%-------------------------------------------------------------------------------
|
| 74 |
+
% solve by Taylor projection and change the parameters gradually to the
|
| 75 |
+
% required level
|
| 76 |
+
%-------------------------------------------------------------------------------
|
| 77 |
+
tolX=1e-6;
|
| 78 |
+
tolF=1e-6;
|
| 79 |
+
maxiter=10;
|
| 80 |
+
|
| 81 |
+
[coeffs,model]=tpsolve(initial_guess,x0,model,params,c0,nodes,weights,tolX,tolF,maxiter);
|
| 82 |
+
|
| 83 |
+
% Now change the parameters GAMMA and DELTA gradually to their required levels:
|
| 84 |
+
|
| 85 |
+
GAMMA_original=GAMMA;
|
| 86 |
+
GAMMA_target=2;
|
| 87 |
+
|
| 88 |
+
DELTA_original=DELTA;
|
| 89 |
+
DELTA_target=.1;
|
| 90 |
+
|
| 91 |
+
for h=0:.1:1 % this is the homotopy parameter
|
| 92 |
+
GAMMA=(1-h)*GAMMA_original+h*GAMMA_target;
|
| 93 |
+
DELTA=(1-h)*DELTA_original+h*DELTA_target;
|
| 94 |
+
|
| 95 |
+
disp(['GAMMA=' num2str(GAMMA) ' DELTA=' num2str(DELTA)])
|
| 96 |
+
|
| 97 |
+
params(2)=GAMMA;
|
| 98 |
+
params(5)=DELTA;
|
| 99 |
+
[coeffs,model]=tpsolve(coeffs,x0,model,params,c0,nodes,weights,tolX,tolF,maxiter);
|
| 100 |
+
|
| 101 |
+
end
|
| 102 |
+
|
105/replication_package/examples/rbc/solve_model.m
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
clear,clc
|
| 2 |
+
|
| 3 |
+
%---------------------------------------------------------
|
| 4 |
+
% Add folder 'files' to the search path and load the model
|
| 5 |
+
%---------------------------------------------------------
|
| 6 |
+
addpath('files');
|
| 7 |
+
load('model')
|
| 8 |
+
|
| 9 |
+
%----------------------------------------------------------------------------
|
| 10 |
+
% Provide nodes and weights for the quadrature that approximates expectations
|
| 11 |
+
%----------------------------------------------------------------------------
|
| 12 |
+
n_e=1; % number of shocks.
|
| 13 |
+
[n_nodes,nodes,weights] = Monomials_2(n_e,eye(n_e)); % this quadrature function was written by Judd, Maliar, Maliar and Valero (2014).
|
| 14 |
+
nodes=nodes'; % transpose to n_e-by-n_nodes
|
| 15 |
+
|
| 16 |
+
%----------------------------------
|
| 17 |
+
% Make a vector of parameter values
|
| 18 |
+
%----------------------------------
|
| 19 |
+
BETA=.96; GAMMA=2; ALPHA=.3; RHO=.8; DELTA=.1; SIGMA=.02;
|
| 20 |
+
params=eval(symparams);
|
| 21 |
+
|
| 22 |
+
%----------------------------------------------------------------------
|
| 23 |
+
% Prepare an initial guess - in this case I use a perturbation solution
|
| 24 |
+
%----------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
% Steady state values
|
| 27 |
+
|
| 28 |
+
kss=((1/BETA-1+DELTA)/ALPHA)^(1/(ALPHA-1));
|
| 29 |
+
zss=0;
|
| 30 |
+
css=kss^ALPHA-DELTA*kss;
|
| 31 |
+
|
| 32 |
+
nxss=[kss;zss];
|
| 33 |
+
nyss=css;
|
| 34 |
+
|
| 35 |
+
% Cross moments of the shocks
|
| 36 |
+
|
| 37 |
+
M=get_moments(nodes,weights,model.order(2));
|
| 38 |
+
|
| 39 |
+
% Compute the perturbation solution (keep the 4 outputs):
|
| 40 |
+
|
| 41 |
+
[derivs,stoch_pert,nonstoch_pert,model]=get_pert(model,params,M,nxss,nyss);
|
| 42 |
+
|
| 43 |
+
% Explanation of outputs:
|
| 44 |
+
% derivs=structure with the perturbation solution as explained in Levintal
|
| 45 |
+
% (2017): "Fifth-Order Perturbation Solution to DSGE Models".
|
| 46 |
+
% stoch_pert=the perturbation solution in the form of unique polynomial coefficients.
|
| 47 |
+
% nonstoch_pert=same as stoch_pert but without correction for the model volatility (i.e. this is a perturbation solution of a deterministic version of the model)
|
| 48 |
+
|
| 49 |
+
%-------------------------------------
|
| 50 |
+
% Solve the model by Taylor projection
|
| 51 |
+
%-------------------------------------
|
| 52 |
+
|
| 53 |
+
x0=nxss; % the approximation point (here we use the steady state, but it could be any arbitrary state)
|
| 54 |
+
c0=nxss; % the center of the initial guess
|
| 55 |
+
|
| 56 |
+
% tolerance parameters for the Newton solver
|
| 57 |
+
tolX=1e-6;
|
| 58 |
+
tolF=1e-6;
|
| 59 |
+
maxiter=10;
|
| 60 |
+
|
| 61 |
+
% model.jacobian='exact'; % this is the default
|
| 62 |
+
% model.jacobian='approximate'; % for large models try the approximate jacobian.
|
| 63 |
+
|
| 64 |
+
initial_guess=stoch_pert;
|
| 65 |
+
[coeffs,model]=tpsolve(initial_guess,x0,model,params,c0,nodes,weights,tolX,tolF,maxiter);
|
| 66 |
+
|
| 67 |
+
%------------------------------------------------------------------
|
| 68 |
+
% Compute the residual function and the model variables at point x0
|
| 69 |
+
%------------------------------------------------------------------
|
| 70 |
+
|
| 71 |
+
[R_fun0,g_fun0,Phi_fun0,auxvars0]=residual(coeffs,x0,params,c0,nodes,weights);
|
| 72 |
+
|
| 73 |
+
% R_fun0 is the residual function at x0.
|
| 74 |
+
% g_fun0 is the control variables at x0, namely, g(x0).
|
| 75 |
+
% Phi_fun0 is the function Phi at x0 and each future node, namely, Phi(x0,g(x0),epsp), for each node of the quadrature.
|
| 76 |
+
% auxvars0 is the auxiliary functions at x0 and each future node.
|
| 77 |
+
|
| 78 |
+
% compute the function g(x) at x0
|
| 79 |
+
y0=evalg(x0,coeffs,c0);
|
| 80 |
+
|
| 81 |
+
% compute the function Phi(x,y,epsp) at x0, y0 and epsp0
|
| 82 |
+
epsp0=.02;
|
| 83 |
+
xp0=evalPhi(x0,y0,epsp0,params);
|
| 84 |
+
|
| 85 |
+
%---------------------------------
|
| 86 |
+
% simulate the model for T periods
|
| 87 |
+
%---------------------------------
|
| 88 |
+
T=100;
|
| 89 |
+
shocks=randn(1,T+1); % draw shocks
|
| 90 |
+
|
| 91 |
+
% preallocate
|
| 92 |
+
x_simul=zeros(model.n_x,T+1);
|
| 93 |
+
y_simul=zeros(model.n_y,T);
|
| 94 |
+
R_simul=zeros(model.n_y,T);
|
| 95 |
+
|
| 96 |
+
x_simul(:,1)=x0;
|
| 97 |
+
|
| 98 |
+
% option=1; % compute only simulated variables
|
| 99 |
+
option=2; % compute model residuals
|
| 100 |
+
|
| 101 |
+
for t=1:T
|
| 102 |
+
xt=x_simul(:,t);
|
| 103 |
+
epsp=shocks(t+1);
|
| 104 |
+
|
| 105 |
+
% Option 1 - compute only the simulated variables
|
| 106 |
+
if option==1
|
| 107 |
+
yt=evalg(xt,coeffs,c0);
|
| 108 |
+
|
| 109 |
+
y_simul(:,t)=yt;
|
| 110 |
+
x_simul(:,t+1)=evalPhi(xt,yt,epsp,params);
|
| 111 |
+
else
|
| 112 |
+
% Option 2 - compute also model residuals
|
| 113 |
+
[Rt,yt]=residual(coeffs,xt,params,c0,nodes,weights);
|
| 114 |
+
|
| 115 |
+
y_simul(:,t)=yt;
|
| 116 |
+
x_simul(:,t+1)=evalPhi(xt,yt,epsp,params);
|
| 117 |
+
R_simul(:,t)=Rt;
|
| 118 |
+
end
|
| 119 |
+
end
|
| 120 |
+
|
| 121 |
+
%-------------------------------------------
|
| 122 |
+
% Solve the model again at a different state
|
| 123 |
+
%-------------------------------------------
|
| 124 |
+
% This is useful when the long run domain of the model is far from the
|
| 125 |
+
% initial state, so we need to approximate the solution at the long run state
|
| 126 |
+
% (e.g. the risky steady state or the mean of the ergodic distribution)
|
| 127 |
+
% rather than the steady state.
|
| 128 |
+
|
| 129 |
+
x1=x0*1.1; % take some arbitrary state
|
| 130 |
+
[coeffs1,model]=tpsolve(coeffs,x1,model,params,c0,nodes,weights,tolX,tolF,maxiter); % solve at x1
|
| 131 |
+
|
| 132 |
+
%-----------------------
|
| 133 |
+
% Use a different solver
|
| 134 |
+
%-----------------------
|
| 135 |
+
|
| 136 |
+
% The function tpsolve uses the Newton method for up to maxiter iterations. If it fails, it
|
| 137 |
+
% switches automatically to fsolve for another maxiter iterations. You can
|
| 138 |
+
% control the parameters of the second solver by optimoptions. The
|
| 139 |
+
% supported solvers are fsolve and lsqnonlin.
|
| 140 |
+
|
| 141 |
+
% For example, do one Newton iteration and switch to lsqnonlin:
|
| 142 |
+
|
| 143 |
+
x2=x1*1.1;
|
| 144 |
+
maxiter=1; % one Newton iteration
|
| 145 |
+
OPTIONS = optimoptions('lsqnonlin','TolX',tolX,'TolF',tolF,'MaxIter',10,'Display','iter-detailed'); % 10 more iterations by lsqnonlin
|
| 146 |
+
|
| 147 |
+
[coeffs2,model]=tpsolve(coeffs,x2,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
% or switch to fsolve:
|
| 151 |
+
|
| 152 |
+
maxiter=1; % one Newton iteration
|
| 153 |
+
OPTIONS = optimoptions('fsolve','TolX',tolX,'TolF',tolF,'MaxIter',10,'Display','iter-detailed'); % 10 more iterations by fsolve
|
| 154 |
+
|
| 155 |
+
[coeffs3,model]=tpsolve(coeffs,x2,model,params,c0,nodes,weights,tolX,tolF,maxiter,OPTIONS);
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
|
105/replication_package/examples/rbc_EZ/prepare_model.m
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%------------------------------------------------------------------
|
| 2 |
+
% RBC model with Epstein-Zin preferences
|
| 3 |
+
%------------------------------------------------------------------
|
| 4 |
+
|
| 5 |
+
clear,clc
|
| 6 |
+
|
| 7 |
+
%-----------------------------------------
|
| 8 |
+
% Define symbolic variables and parameters
|
| 9 |
+
%-----------------------------------------
|
| 10 |
+
|
| 11 |
+
syms logk logkp logc logcp z zp logxi logxip logq logqp epsp real
|
| 12 |
+
syms BETA GAMMA PSI ALPHA RHO DELTA SIGMA real
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
%----------------------
|
| 16 |
+
% Substituted variables
|
| 17 |
+
%----------------------
|
| 18 |
+
|
| 19 |
+
c=exp(logc); cp=exp(logcp);
|
| 20 |
+
|
| 21 |
+
k=exp(logk); kp=exp(logkp);
|
| 22 |
+
|
| 23 |
+
xi=exp(logxi); xip=exp(logxip);
|
| 24 |
+
|
| 25 |
+
q=exp(logq);
|
| 26 |
+
|
| 27 |
+
Vpowerp=(1-BETA)*cp^(1-PSI)+BETA*xip^(1-PSI); % this is Vp^(1-PSI)
|
| 28 |
+
|
| 29 |
+
logVp=1/(1-PSI)*log( Vpowerp );
|
| 30 |
+
|
| 31 |
+
Vp=exp(logVp);
|
| 32 |
+
|
| 33 |
+
logmp=log(BETA)+PSI*(logc-logcp)+(PSI-GAMMA)*(logVp-logxi);
|
| 34 |
+
|
| 35 |
+
mp=exp(logmp);
|
| 36 |
+
|
| 37 |
+
%-----------------------
|
| 38 |
+
% Equilibrium conditions
|
| 39 |
+
%-----------------------
|
| 40 |
+
f1=mp*(ALPHA*exp(zp)*kp^(ALPHA-1)+1-DELTA)-1;
|
| 41 |
+
f2=xi^(GAMMA-1)*Vp^(1-GAMMA)-1;
|
| 42 |
+
f3=mp/q-1;
|
| 43 |
+
|
| 44 |
+
f_fun=[f1;f2;f3];
|
| 45 |
+
|
| 46 |
+
%-------------------------------------------------------
|
| 47 |
+
% Function Phi (law of motion of log capital and technology)
|
| 48 |
+
%-------------------------------------------------------
|
| 49 |
+
|
| 50 |
+
Phi_fun=[log(exp(z)*k^ALPHA+(1-DELTA)*k-c);
|
| 51 |
+
RHO*z+SIGMA*epsp];
|
| 52 |
+
|
| 53 |
+
%--------------------------
|
| 54 |
+
% Vector of state variables
|
| 55 |
+
%--------------------------
|
| 56 |
+
x=[logk,z]; % current period
|
| 57 |
+
xp=[logkp,zp]; % future period
|
| 58 |
+
|
| 59 |
+
%----------------------------
|
| 60 |
+
% Vector of control variables
|
| 61 |
+
%----------------------------
|
| 62 |
+
y=[logc,logxi,logq]; % current period
|
| 63 |
+
yp=[logcp,logxip,logqp]; % future period
|
| 64 |
+
|
| 65 |
+
%-----------------
|
| 66 |
+
% Vector of shocks
|
| 67 |
+
%-----------------
|
| 68 |
+
shocks=[epsp];
|
| 69 |
+
|
| 70 |
+
%---------------------
|
| 71 |
+
% Vector of parameters
|
| 72 |
+
%---------------------
|
| 73 |
+
symparams=[BETA,GAMMA,PSI,ALPHA,RHO,DELTA,SIGMA];
|
| 74 |
+
|
| 75 |
+
%--------------------
|
| 76 |
+
% Approximation order
|
| 77 |
+
%--------------------
|
| 78 |
+
order=3; % fourth order is the maximum possible
|
| 79 |
+
|
| 80 |
+
%----------------
|
| 81 |
+
% Call prepare_tp
|
| 82 |
+
%----------------
|
| 83 |
+
model=prepare_tp(f_fun,Phi_fun,yp,y,xp,x,shocks,symparams,order);
|
| 84 |
+
|
| 85 |
+
%-----------
|
| 86 |
+
% Save model
|
| 87 |
+
%-----------
|
| 88 |
+
save('model') % you will need this later
|
105/replication_package/examples/rbc_EZ/prepare_model_auxiliary_functions.m
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%------------------------------------------------------------------
|
| 2 |
+
% RBC model with Epstein-Zin preferences
|
| 3 |
+
%------------------------------------------------------------------
|
| 4 |
+
|
| 5 |
+
clear,clc
|
| 6 |
+
|
| 7 |
+
%-----------------------------------------
|
| 8 |
+
% Define symbolic variables and parameters
|
| 9 |
+
%-----------------------------------------
|
| 10 |
+
|
| 11 |
+
syms logk logkp logc logcp z zp logxi logxip logq logqp epsp real
|
| 12 |
+
syms BETA GAMMA PSI ALPHA RHO DELTA SIGMA real
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
%-----------------------------------------------------
|
| 16 |
+
% Substituted variables defined by auxiliary functions
|
| 17 |
+
%-----------------------------------------------------
|
| 18 |
+
|
| 19 |
+
syms c cp k kp xi xip q Vpowerp logVp Vp logmp mp real
|
| 20 |
+
|
| 21 |
+
c_=exp(logc); cp_=exp(logcp);
|
| 22 |
+
|
| 23 |
+
k_=exp(logk); kp_=exp(logkp);
|
| 24 |
+
|
| 25 |
+
xi_=exp(logxi); xip_=exp(logxip);
|
| 26 |
+
|
| 27 |
+
q_=exp(logq);
|
| 28 |
+
|
| 29 |
+
Vpowerp_=(1-BETA)*cp^(1-PSI)+BETA*xip^(1-PSI); % this is Vp^(1-PSI)
|
| 30 |
+
|
| 31 |
+
logVp_=1/(1-PSI)*log( Vpowerp );
|
| 32 |
+
|
| 33 |
+
Vp_=exp(logVp);
|
| 34 |
+
|
| 35 |
+
logmp_=log(BETA)+PSI*(logc-logcp)+(PSI-GAMMA)*(logVp-logxi);
|
| 36 |
+
|
| 37 |
+
mp_=exp(logmp);
|
| 38 |
+
|
| 39 |
+
%-----------------------
|
| 40 |
+
% Equilibrium conditions
|
| 41 |
+
%-----------------------
|
| 42 |
+
f1=mp*(ALPHA*exp(zp)*kp^(ALPHA-1)+1-DELTA)-1;
|
| 43 |
+
f2=xi^(GAMMA-1)*Vp^(1-GAMMA)-1;
|
| 44 |
+
f3=mp/q-1;
|
| 45 |
+
|
| 46 |
+
f_fun=[f1;f2;f3];
|
| 47 |
+
|
| 48 |
+
%-------------------------------------------------------
|
| 49 |
+
% Function Phi (law of motion of log capital and technology)
|
| 50 |
+
%-------------------------------------------------------
|
| 51 |
+
|
| 52 |
+
Phi_fun=[log(exp(z)*k^ALPHA+(1-DELTA)*k-c);
|
| 53 |
+
RHO*z+SIGMA*epsp];
|
| 54 |
+
|
| 55 |
+
%--------------------------
|
| 56 |
+
% Vector of state variables
|
| 57 |
+
%--------------------------
|
| 58 |
+
x=[logk,z]; % current period
|
| 59 |
+
xp=[logkp,zp]; % future period
|
| 60 |
+
|
| 61 |
+
%----------------------------
|
| 62 |
+
% Vector of control variables
|
| 63 |
+
%----------------------------
|
| 64 |
+
y=[logc,logxi,logq]; % current period
|
| 65 |
+
yp=[logcp,logxip,logqp]; % future period
|
| 66 |
+
|
| 67 |
+
%-----------------
|
| 68 |
+
% Vector of shocks
|
| 69 |
+
%-----------------
|
| 70 |
+
shocks=[epsp];
|
| 71 |
+
|
| 72 |
+
%---------------------
|
| 73 |
+
% Vector of parameters
|
| 74 |
+
%---------------------
|
| 75 |
+
symparams=[BETA,GAMMA,PSI,ALPHA,RHO,DELTA,SIGMA];
|
| 76 |
+
|
| 77 |
+
%------------------------------------------
|
| 78 |
+
% Collect auxiliary functions and variables
|
| 79 |
+
%------------------------------------------
|
| 80 |
+
|
| 81 |
+
allvars=who;
|
| 82 |
+
auxfuns=[];
|
| 83 |
+
auxvars=[];
|
| 84 |
+
for i=1:length(allvars)
|
| 85 |
+
if strcmp(allvars{i}(end),'_')
|
| 86 |
+
eval(['tempfun=' allvars{i} ';'])
|
| 87 |
+
eval(['tempvar=' allvars{i}(1:end-1) ';'])
|
| 88 |
+
auxfuns=[auxfuns(:);tempfun(:)];
|
| 89 |
+
auxvars=[auxvars(:);tempvar(:)];
|
| 90 |
+
end
|
| 91 |
+
end
|
| 92 |
+
|
| 93 |
+
%--------------------
|
| 94 |
+
% Approximation order
|
| 95 |
+
%--------------------
|
| 96 |
+
order=4; % fourth order is the maximum possible
|
| 97 |
+
|
| 98 |
+
%----------------
|
| 99 |
+
% Call prepare_tp
|
| 100 |
+
%----------------
|
| 101 |
+
model=prepare_tp(f_fun,Phi_fun,yp,y,xp,x,shocks,symparams,order,auxfuns,auxvars);
|
| 102 |
+
|
| 103 |
+
%-----------
|
| 104 |
+
% Save model
|
| 105 |
+
%-----------
|
| 106 |
+
save('model') % you will need this later
|
105/replication_package/examples/rbc_EZ/solve_model.m
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
clear,clc
|
| 2 |
+
|
| 3 |
+
%---------------------------------------------------------
|
| 4 |
+
% Add folder 'files' to the search path and load the model
|
| 5 |
+
%---------------------------------------------------------
|
| 6 |
+
addpath('files');
|
| 7 |
+
load('model')
|
| 8 |
+
|
| 9 |
+
%----------------------------------------------------------------------------
|
| 10 |
+
% Provide nodes and weights for the quadrature that approximates expectations
|
| 11 |
+
%----------------------------------------------------------------------------
|
| 12 |
+
n_e=length(shocks); % number of shocks.
|
| 13 |
+
[n_nodes,nodes,weights] = Monomials_2(n_e,eye(n_e)); % this quadrature function was written by Judd, Maliar, Maliar and Valero (2014).
|
| 14 |
+
nodes=nodes'; % transpose to n_e-by-n_nodes
|
| 15 |
+
|
| 16 |
+
%----------------------------------
|
| 17 |
+
% Make a vector of parameter values
|
| 18 |
+
%----------------------------------
|
| 19 |
+
BETA=.96; GAMMA=2; PSI=1.5; ALPHA=.3; RHO=.8; DELTA=.1; SIGMA=.08;
|
| 20 |
+
params=eval(symparams);
|
| 21 |
+
|
| 22 |
+
%----------------------------------------------------------------------
|
| 23 |
+
% Prepare an initial guess - in this case I use a perturbation solution
|
| 24 |
+
%----------------------------------------------------------------------
|
| 25 |
+
|
| 26 |
+
% Steady state values
|
| 27 |
+
|
| 28 |
+
kss=((1/BETA-1+DELTA)/ALPHA)^(1/(ALPHA-1));
|
| 29 |
+
zss=0;
|
| 30 |
+
css=kss^ALPHA-DELTA*kss;
|
| 31 |
+
vss=css;
|
| 32 |
+
xiss=vss;
|
| 33 |
+
qss=BETA;
|
| 34 |
+
|
| 35 |
+
nxss=[log(kss);zss];
|
| 36 |
+
nyss=[log(css);log(xiss);log(qss)];
|
| 37 |
+
|
| 38 |
+
% Cross moments of the shocks
|
| 39 |
+
|
| 40 |
+
M=get_moments(nodes,weights,model.order(2));
|
| 41 |
+
|
| 42 |
+
% Compute the perturbation solution (keep the 4 outputs):
|
| 43 |
+
|
| 44 |
+
[derivs,stoch_pert,nonstoch_pert,model]=get_pert(model,params,M,nxss,nyss);
|
| 45 |
+
|
| 46 |
+
% Explanation of outputs:
|
| 47 |
+
% derivs=structure with the perturbation solution as explained in Levintal
|
| 48 |
+
% (2017): "Fifth-Order Perturbation Solution to DSGE Models".
|
| 49 |
+
% stoch_pert=the perturbation solution in the form of unique polynomial coefficients.
|
| 50 |
+
% nonstoch_pert=same as stoch_pert but without correction for the model volatility (i.e. this is a perturbation solution of a deterministic version of the model)
|
| 51 |
+
|
| 52 |
+
%-------------------------------------
|
| 53 |
+
% Solve the model by Taylor projection
|
| 54 |
+
%-------------------------------------
|
| 55 |
+
|
| 56 |
+
x0=nxss; % the approximation point (here we use the steady state, but it could be any arbitrary state)
|
| 57 |
+
c0=nxss; % the center of the initial guess
|
| 58 |
+
|
| 59 |
+
% tolerance parameters for the Newton solver
|
| 60 |
+
tolX=1e-6;
|
| 61 |
+
tolF=1e-6;
|
| 62 |
+
maxiter=10;
|
| 63 |
+
|
| 64 |
+
% model.jacobian='exact'; % this is the default
|
| 65 |
+
% model.jacobian='approximate'; % for large models try the approximate jacobian.
|
| 66 |
+
|
| 67 |
+
initial_guess=stoch_pert;
|
| 68 |
+
[coeffs,model]=tpsolve(initial_guess,x0,model,params,c0,nodes,weights,tolX,tolF,maxiter);
|
| 69 |
+
|
| 70 |
+
%------------------------------------------------------------------
|
| 71 |
+
% Compute the residual function and the model variables at point x0
|
| 72 |
+
%------------------------------------------------------------------
|
| 73 |
+
|
| 74 |
+
[R_fun0,g_fun0,Phi_fun0,auxvars0]=residual(coeffs,x0,params,c0,nodes,weights);
|
| 75 |
+
|
| 76 |
+
%------------------------
|
| 77 |
+
% Check the interest rate
|
| 78 |
+
%------------------------
|
| 79 |
+
|
| 80 |
+
logq=g_fun0(3);
|
| 81 |
+
Rf=exp(-logq)-1
|
| 82 |
+
|
| 83 |
+
%----------------------------------------------------------------------------
|
| 84 |
+
% Increase risk aversion (gradually) and see how the interest rate falls
|
| 85 |
+
%----------------------------------------------------------------------------
|
| 86 |
+
|
| 87 |
+
GAMMAvec=2:4:82;
|
| 88 |
+
|
| 89 |
+
Rfvec=zeros(size(GAMMAvec));
|
| 90 |
+
|
| 91 |
+
i=0;
|
| 92 |
+
for GAMMA=GAMMAvec
|
| 93 |
+
i=i+1;
|
| 94 |
+
params(2)=GAMMA;
|
| 95 |
+
[coeffs,model]=tpsolve(coeffs,x0,model,params,c0,nodes,weights,tolX,tolF,maxiter);
|
| 96 |
+
[R_fun0,g_fun0,Phi_fun0,auxvars0]=residual(coeffs,x0,params,c0,nodes,weights);
|
| 97 |
+
logq=g_fun0(3);
|
| 98 |
+
Rfvec(i)=exp(-logq)-1;
|
| 99 |
+
end
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
plot(GAMMAvec,Rfvec)
|
| 103 |
+
xlabel('Risk aversion (GAMMA)')
|
| 104 |
+
ylabel('Risk-free interest rate (Rf)')
|