%% The Chinese Anomaly
%  Andrea Ferrero
%  September 26, 2012
%  This version: September 26, 2012

%% Simulation of Neoclassical Growth Model
%  with time-varying productivity and population growth
%  and capital tax rates and government spending

close all
clear all

%% Data (1962:2008)

% NIPA data are from CEIC in bn yuan
% GDP deflator is from World Bank WDI (= 100 in 1990)

data = xlsread('china_TFP_calc','data');

year = data(:,1);

T = size(year,1);

gdp  = data(:,2);
cons = data(:,3);
govt = data(:,4);
inv  = data(:,5);
nx   = data(:,6);
empl = data(:,7);

%% Construction of capital stock

% Guess initial capital stock
k_1961 = 3;

% Depreciation rate
depre = 0.1;

% Perpetual inventory method
k = zeros(T+1,1);
k(1) = k_1961;
for i = 1:T
    k(i+1) = inv(i) + (1 - depre) * k(i);
end
k = k(1:T);

%% Construction of TFP factor and TFP growth

% Capital share 
k_share = 0.33;

tfp_lev  = (gdp./((k.^k_share).*(empl.^(1-k_share)))).^(1/(1-k_share));

tfp_grow = zeros(T,1);

for i = 2:T
    tfp_grow(i) = tfp_lev(i) / tfp_lev(i-1);
end

% Average TFP growth (set initial value)
gamma_ss = mean(tfp_grow(2:T));
tfp_grow(1) = gamma_ss;

%% Employment growth

empl_grow = zeros(T,1);

for i = 2:T
    empl_grow(i) = empl(i) / empl(i-1);
end

% Average employment growth (set initial value)
n_ss = mean(empl_grow(2:T));
empl_grow(1) = n_ss;

%% Government spending % of GDP

gy = govt./gdp;

%% Calibration (annual)

% Remaining structural parameters 
disc_fact  = 0.99;      % Discount factor
risk_av    = 1;         % Risk aversion
k_adjust   = 1;         % Capital adjustment cost

% Steady state exogenous variables
tau_ss     = 0;         % Capital tax rate
g_ss       = mean(gy);  % Government spending

%% Save parameters
save china_calib disc_fact risk_av depre k_share k_adjust...
                 tau_ss gamma_ss n_ss g_ss
             
%% Save shocks
shocks_ch = tfp_grow;
save('china_shocks','shocks_ch');

%% Run deterministic simulation 
%  of neoclassical growth model
%  with time-varying productivity
%  population growth and fiscal variables

dynare china_adjc

