warning 'off';

close all; clc; clear; 

delete('*.mat','*.pdf', '*.asv','*.fig','*.eps','cacciaFiori.m','cacciaFioriDeterministic.m','*_dynamic.m','*_static.m','*.txt','*.bin',...
       '*.cod', '*.jnl','*.log','*_set_auxiliary_variables.m','cycle_irf.m','cycle_moments.m','transition.m');

addpath C:\dynare\4.4.3\matlab

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CHOOSE OPTIONS
deterministicI      =      1;                            %% -- set to one if you want transition dynamics following deregulation
                                                                 %  -- otherwise: IRFs/second moments following a productivity shock

reformI             =      1;                            %% -- set to one if you consider a market reform
                                                                 %  -- otherwise: regulation set at euro area level

% momentsI            =      0*(1-deterministicI); %% -- set to one if you want second moments (for given level of regulation);
                                                                 %  -- always zero when considering transition dynamics.
momentsI            =      0;                                                                 
save options deterministicI reformI momentsI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CHOOSE REFORM
pmrI   = 1; fcI    = 0;  ubI   = 0;  
save reforms ubI fcI pmrI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CALIBRATE THE MODEL AND GET INITIAL, RIGID STEADY STATE
calibration; 
clear; load options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if deterministicI==0 && reformI==0 
   %% BUSINES CYCLE DYNAMICS FOR BENCHMARK CALIBRATION WITH HIGH REGULATION (EITHER IRF OR SECOND MOMENTS)
    
   if momentsI==0
      dynare cycle_irf noclearall; load options
   else
      dynare cycle_moments noclearall; load options
      second_moments;
   end    
       clear; load options
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


                          
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if reformI==1 
   %% COMPUTE STEADY STATE AFTER MARKET REFORM   
   newsteady; 
   clear; load options
          
   if deterministicI==0 
      %% BUSINES CYCLE DYNAMICS AFTER DEREGULATION (EITHER IRF OR SECOND MOMENTS)
   
      if momentsI==0
         dynare cycle_irf noclearall; load options
      else
         dynare cycle_moments noclearall; load options
        second_moments;
      end    
             
   else
      %% TRANSITION DYNAMICS AFTER DEREGULATION
       dynare transition
       


   end
   
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
