Tauchen Method - Discretization of AR(1) process of entrepreneurial productivity z
Original Description
This function discretizes a continuous AR(1) process by using the method proposed by Tauchen (1986). The AR(1) process takes the following form: y(t) = mu + rho*y(t-1) + eps(t), where eps ~ N(0,sig^2) Parts of the code are taken from the function tauchen.m written by Martin Flodén.
INPUTS - fl_mu: scalar, intercept term of the AR(1) process; fl_rho: scalar, AR-coefficient; fl_sig: scalar, standard deviation of innovations; it_zgridno: scalar, number of grid points for the discretized process;
OUTPUTS - ar_z: column vector of size Nx1, contains all possible states in ascending order; mt_Pi: matrix of size NxN, contains the transition proabilities. Rows are current state and columns future state;
Author: Jan Hannes Lang Date: 6.7.2010
Back to full code page https://kritikhanna.github.io/BKS-modified/
Contents
function [ar_z, mt_Pi] = mytauchen(varargin)
Function default parameters setting
close all; profile off; profile on; if ~isempty(varargin) [fl_mu_z, fl_rho_z, fl_sig_z, it_zgridno, fl_lambda_z, bl_display_param] = varargin{:} else fl_mu_z = 0; fl_rho_z = 0.9; fl_sig_z = 0.2; it_zgridno = 10; fl_lambda_z = 3; bl_display_param = true; end ar_z = zeros(it_zgridno,1); mt_Pi = zeros(it_zgridno,it_zgridno); ar_z(1) = fl_mu_z/(1-fl_rho_z) - fl_lambda_z*sqrt(fl_sig_z^2/(1-fl_rho_z^2)); ar_z(it_zgridno) = fl_mu_z/(1-fl_rho_z) + fl_lambda_z*sqrt(fl_sig_z^2/(1-fl_rho_z^2)); step = (ar_z(it_zgridno)-ar_z(1))/(it_zgridno-1);
Constructing entrepreneurial productivity array
for i=2:(it_zgridno-1) ar_z(i) = ar_z(i-1) + step; end
Constructing transition matrix
for j = 1:it_zgridno for k = 1:it_zgridno if k == 1 mt_Pi(j,k) = cdf_normal((ar_z(1) - fl_mu_z - fl_rho_z*ar_z(j) + step/2) / fl_sig_z); elseif k == it_zgridno mt_Pi(j,k) = 1 - cdf_normal((ar_z(it_zgridno) - fl_mu_z - fl_rho_z*ar_z(j) - step/2) / fl_sig_z); else mt_Pi(j,k) = cdf_normal((ar_z(k) - fl_mu_z - fl_rho_z*ar_z(j) + step/2) / fl_sig_z) - ... cdf_normal((ar_z(k) - fl_mu_z - fl_rho_z*ar_z(j) - step/2) / fl_sig_z); end end end
Displaying entreprenurial productivity array and transition matrix
if (bl_display_param == true) fprintf (2, 'log entrepreneurial Productivity array \n'); disp ('----------------------------------'); disp (ar_z'); fprintf (2, 'Transition Matrix \n'); disp ('------------------'); disp (mt_Pi); end profile off; profile viewer; st_file_name = ['/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/mytauchen_z_profile']; profsave(profile('info'), st_file_name);
log entrepreneurial Productivity array ---------------------------------- Columns 1 through 7 -1.3765 -1.0706 -0.7647 -0.4588 -0.1529 0.1529 0.4588 Columns 8 through 10 0.7647 1.0706 1.3765 Transition Matrix ------------------ Columns 1 through 7 0.5305 0.4154 0.0533 0.0009 0.0000 0.0000 0.0000 0.0968 0.4939 0.3700 0.0388 0.0005 0.0000 0.0000 0.0037 0.1220 0.5232 0.3231 0.0277 0.0003 0.0000 0.0000 0.0058 0.1543 0.5437 0.2767 0.0193 0.0002 0.0000 0.0000 0.0088 0.1912 0.5542 0.2324 0.0132 0.0000 0.0000 0.0001 0.0132 0.2324 0.5542 0.1912 0.0000 0.0000 0.0000 0.0002 0.0193 0.2767 0.5437 0.0000 0.0000 0.0000 0.0000 0.0003 0.0277 0.3231 0.0000 0.0000 0.0000 0.0000 0.0000 0.0005 0.0388 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0009 Columns 8 through 10 0 0 0 0.0000 0 0 0.0000 0.0000 0 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0088 0.0000 0.0000 0.1543 0.0058 0.0000 0.5232 0.1220 0.0037 0.3700 0.4939 0.0968 0.0533 0.4154 0.5305 The files //Users/sidhantkhanna/Documents/GitHub/BKS and /Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Firms/modified/code/Profile/mytauchen_z_profile/file0.html do not exist.
function c = cdf_normal(x)
c = 0.5 * erfc(-x/sqrt(2));