Tauchen Method - Discretization of AR(1) process of labor productivity - l

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_l(varargin)

Function default parameters setting

close all;
profile off;
profile on;

if ~isempty(varargin)

        [fl_mu_l, fl_rho_l, fl_sig_l, it_zgridno, fl_lambda_z]      = varargin{:}
        bl_display_param = true;

    else
         fl_mu_l            = 0;
         fl_rho_l           = 0.9;
         fl_sig_l           = 0.2;
         it_zgridno         = 2;
         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_l/(1-fl_rho_l) - fl_lambda_z*sqrt(fl_sig_l^2/(1-fl_rho_l^2));
ar_z(it_zgridno)    = fl_mu_l/(1-fl_rho_l) + fl_lambda_z*sqrt(fl_sig_l^2/(1-fl_rho_l^2));
step    = (ar_z(it_zgridno)-ar_z(1))/(it_zgridno-1);

Constructing Labor productivity array

for i=2:(it_zgridno-1)
   ar_z(i) = ar_z(i-1) + step;
end

Constructing Labor productivity 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_l - fl_rho_l*ar_z(j) + step/2) / fl_sig_l);
        elseif k == it_zgridno
            mt_Pi(j,k) = 1 - cdf_normal((ar_z(it_zgridno) - fl_mu_l - fl_rho_l*ar_z(j) - step/2) / fl_sig_l);
        else
            mt_Pi(j,k) = cdf_normal((ar_z(k) - fl_mu_l - fl_rho_l*ar_z(j) + step/2) / fl_sig_l) - ...
                      cdf_normal((ar_z(k) - fl_mu_l - fl_rho_l*ar_z(j) - step/2) / fl_sig_l);
        end
    end
end

Displaying labor productivity array and transition matrix

if (bl_display_param == true)
        fprintf (2, 'Labor 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_l_profile'];
profsave(profile('info'), st_file_name);
Labor Productivity array  
--------------------------
   -1.3765    1.3765

Transition Matrix 
------------------
    1.0000    0.0000
    0.0000    1.0000

The files //Users/sidhantkhanna/Documents/GitHub/BKS and /Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Firms/modified/code/Profile/mytauchen_l_profile/file0.html do not exist.
    function c = cdf_normal(x)
c = 0.5 * erfc(-x/sqrt(2));