\documentclass[11pt,reqno]{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
%\usepackage{epstopdf}
\usepackage{hyperref}
\usepackage[left=1in,right=1in,top=0.9in,bottom=0.9in]{geometry}
\usepackage{multirow}
\usepackage{verbatim}
\usepackage{fancyhdr}
\usepackage{harvard}
\usepackage{listings}
%\usepackage[small,compact]{titlesec} 

%\usepackage{pxfonts}
%\usepackage{isomath}
\usepackage{mathpazo}
%\usepackage{arev} %     (Arev/Vera Sans)
%\usepackage{eulervm} %_   (Euler Math)
%\usepackage{fixmath} %  (Computer Modern)
%\usepackage{hvmath} %_   (HV-Math/Helvetica)
%\usepackage{tmmath} %_   (TM-Math/Times)
%\usepackage{cmbright}
%\usepackage{ccfonts} \usepackage[T1]{fontenc}
%\usepackage[garamond]{mathdesign}
\usepackage{color}
\usepackage[normalem]{ulem}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{conjecture}{Conjecture}[section]
\newtheorem{corollary}{Corollary}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{proposition}{Proposition}[section]
\theoremstyle{definition}
\newtheorem{assumption}{}[section]
\renewcommand{\theassumption}{A\arabic{assumption}}
\newtheorem{definition}{Definition}[section]
\newtheorem{step}{Step}[section]
\newtheorem{remark}{Comment}[section]
\newtheorem{example}{Example}[section]
\newtheorem*{example*}{Example}
\newtheorem{mpart}{Part}

\linespread{1.1}

\pagestyle{fancy}
%\renewcommand{\sectionmark}[1]{\markright{#1}{}}
\fancyhead{}
\fancyfoot{} 
%\fancyhead[LE,LO]{\tiny{\thepage}}
\fancyhead[CE,CO]{\tiny{\rightmark}}
\fancyfoot[C]{\small{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\small{\thepage}} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}

\makeatletter
\renewcommand{\@maketitle}{
  \null 
  \begin{center}%
    \rule{\linewidth}{1pt} 
    {\Large \textbf{\textsc{\@title}}} \par
    {\small \textsc{Hiro Kasahara, slightly modified by Paul
        Schrimpf}} \par
    {\small \textsc{\@date}} \par
    {\small \textsc{University of British Columbia}} \par
    {\small \textsc{Economics 628: Topics in econometrics}} \par
    \rule{\linewidth}{1pt} 
  \end{center}%
  \par \vskip 0.9em
}
\makeatother

\newcommand{\argmax}{\operatornamewithlimits{arg\,max}}
\newcommand{\argmin}{\operatornamewithlimits{arg\,min}}
\def\inprobLOW{\rightarrow_p}
\def\inprobHIGH{\,{\buildrel p \over \rightarrow}\,} 
\def\inprob{\,{\inprobHIGH}\,} 
\def\indist{\,{\buildrel d \over \rightarrow}\,} 
\def\F{\mathbb{F}}
\def\R{\mathbb{R}}
\newcommand{\gmatrix}[1]{\begin{pmatrix} {#1}_{11} & \cdots &
    {#1}_{1n} \\ \vdots & \ddots & \vdots \\ {#1}_{m1} & \cdots &
    {#1}_{mn} \end{pmatrix}}
\newcommand{\iprod}[2]{\left\langle {#1} , {#2} \right\rangle}
\newcommand{\norm}[1]{\left\Vert {#1} \right\Vert}
\newcommand{\abs}[1]{\left\vert {#1} \right\vert}
\renewcommand{\det}{\mathrm{det}}
\newcommand{\rank}{\mathrm{rank}}
\newcommand{\spn}{\mathrm{span}}
\newcommand{\row}{\mathrm{Row}}
\newcommand{\col}{\mathrm{Col}}
\renewcommand{\dim}{\mathrm{dim}}
\newcommand{\prefeq}{\succeq}
\newcommand{\pref}{\succ}
\newcommand{\seq}[1]{\{{#1}_n \}_{n=1}^\infty }
\renewcommand{\to}{{\rightarrow}}

\providecommand{\En}{\mathbb{E}_n}
\providecommand{\Er}{{\mathrm{E}}}
\renewcommand{\Pr}{{\mathrm{P}}}
\providecommand{\set}[1]{\left\{#1\right\}}
\providecommand{\plim}{\operatornamewithlimits{plim}}
\newcommand\indep{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\setbox0\hbox{$#1#2$}%
    \copy0\kern-\wd0\mkern4mu\box0}} 

\renewcommand{\cite}{\citeasnoun}

\lstset{language=Matlab,                % the language of the code
  basicstyle=\ttfamily,
  keywordstyle=\textcolor{blue},
  commentstyle=\textcolor{red}
}
\title{Homework 6: Structural dynamic discrete choice}
\date{Due: Wednesday, November 30th}

\begin{document}

\maketitle


Consider a dynamic model of import decision:
\begin{align}
  V (\omega_{t-1} , d_{t-1} ) = &
  \max_{d_t \in \{0,1\}} W (\omega_{t-1} , d_{t-1} , d_t ) + \xi_t
  (d_t ) \label{e1} \\
  W (\omega_{t-1} , d_{t-1} , d_t ) = & \Er\left[\tilde{\pi}_\theta
    (\omega_t , d_t ) - F C_\theta (d_t , d_{t-1} ) + \beta V
    (\omega_t , d_t )|\omega_{t-1} , d_{t-1} \right]. \label{e2}
\end{align}
where $\omega_t$ is productivity, $(\xi_t (0), \xi_t (1))$ are import
cost shocks, $d_t$ is a binary import decision, $\pi_t (\cdot)$ is
the profit after maximizing out the variable inputs,
\[ 
F C_\theta (d_t , d_{t-1} ) = (\delta_1 + \delta_2 (1 - d_{t-1} ))d_t 
\]
is the fixed cost of importing materials where $\delta_1$ is per-period
fixed cost while $\delta_2$ is one-time sunk 
cost of importing.
The stochastic process of $\omega_t$ and $(\xi_t (0), \xi_t (1))$ are given by
\begin{align*}
  \omega_t = & \rho \omega_{t-1} + \epsilon_t \\
  \epsilon_t \sim_{iid} & N (0,\sigma^2 ), \\
  (\xi(0), \xi(1)) \sim_{iid} & \text{Type 1 Extreme value
    distribution.}
\end{align*}
We specify 
\[ \tilde{\pi}_\theta (\omega_t , d_t ) = \exp(\tilde{\alpha}_0 + \tilde{\alpha}_1 \omega_t +
\alpha_2 d_t ) \] 
and
\begin{align*}
  \Er\left[\tilde{\pi}_\theta (\omega_t , d_t )|\omega_{t-1} , d_{t-1}
  \right] =  & \Er\left[\exp(\tilde{\alpha}_0 +\tilde{\alpha}_1 \omega_t +\alpha_2 d_t
    )|\omega_{t-1} , d_{t-1} \right] \\
  = & \exp(\alpha_0 +\alpha_1 \omega_{t-1} +\alpha_2 d_t ) \equiv
  \pi_\theta (\omega_{t-1} , d_t )
\end{align*}
with $\alpha_0 = \tilde{\alpha}_0 + 0.5\sigma^2$ and $\alpha_1 =
\tilde{\alpha}_1 \rho$, where the last equality follows from $\omega_t
= \rho\omega_{t-1} + \epsilon_t$ 
and
$
\Er[\exp(\epsilon_t )] = \exp(0.5\sigma^2)$.


Using the property of extreme value distributed variable, (\ref{e1})
and (\ref{e2}) can be written as
\begin{align}
  V (\omega_{t-1} , d_{t-1} ) = & \text{Euler's constant} + \ln\left(
    \sum_{d_t \in \{0,1\}} \exp\left( W (\omega_{t-1} , d_{t-1} , d_t
      ) \right)
  \right) \label{e3} \\
  W (\omega_{t-1} , d_{t-1} , d_t ) = & \pi_\theta (\omega_{t-1} , d_t ) - F C_\theta (d_t , d_{t-1} ) + \beta
  \int V (\rho\omega_{t-1} + \epsilon', d_t )(1/\sigma
  )\phi(\epsilon'/\sigma )d\epsilon'. \label{e4}
\end{align}
Once the fixed point of (\ref{e3}) and (\ref{e4}) is solved, then we
can compute the conditional choice probabilities by 
the logit formula as:
\begin{align}
  \Pr_\theta (d_t = 1|\omega_{t-1} , d_{t-1} ) = &
\frac{\exp\left(\pi_\theta (\omega_{t-1} , 1) - F C_\theta (1, d_{t-1} ) +
  \beta \Er_{\epsilon'} \left[ V (\rho\omega_{t-1} + \epsilon', 1)
  \right] \right)} 
{\sum_{d' \in\{0,1\}} \exp\left(\pi_\theta (\omega_{t-1} , d' ) - F
    C_\theta (d' , d_{t-1} ) + \beta \Er \left[V (\rho\omega_{t-1} + \epsilon',
      d' )\right] \right)} \label{e5}
\end{align}

Read ``HW6\_data'' into Matlab, which contains $N \times (T + 1)$ panel data for firm's discrete
import decisions (``d\_m'') and productivity shock (``omega''), where there are $N = 1976$ firms
across $T + 1 = 7$ years. Estimating the AR(1) process for
$\omega_{it}$ , we have $\hat{\rho} = 0.5955$ and $\hat{\sigma}^2 =
0.0657$. In this exercise, you are asked to estimate the parameters 
\[\theta = (\alpha_0 , \alpha_1 , \alpha_2 , \delta_1 , \delta_2 )\]
while fixing $\rho = 0.5955$ and $\sigma^2 = 0.0657$ by maximizing the
log likelihood function:
\begin{align}
  \mathcal{L} (\theta|\{d_{it},\omega_{it}) = & \sum_{i=1}^N
  \sum_{t=1}^{T_i} \ln\left(\Pr_\theta
    (d_{it} |\omega_{i,t-1} , d_{i,t-1} )\right), \label{e6}
\end{align}
where 
\[ \Pr_\theta (d_{it} |\omega_{i,t-1} , d_{i,t-1} ) 
\]
is given by (\ref{e5}).
\begin{mpart}
  Solve the fixed point of (\ref{e4}) by approximating the state space of $\omega$ by a set of $N_\omega = 61$ discrete
  points: $\mathcal{W} = \{-1.5, -1.45, -1.4, ...., -0.05, 0, 0.05, ...., 1.4, 1.45, 1.5\}$. Let $\omega^1 = -1.5, \omega^2 =
-1.45, ..., \omega^{61} = 1.45$, and $\omega^{N_\omega} = 1.5$. Let 
\[ q_j = (\omega_j + \omega_{j+1} )/2 \]
for $j = 1, ..., N_{\omega - 1}$ so that $q_j$ is the middle point
between $\omega_j$ and $\omega_{j+1}$ . 
The AR(1) process of $\omega$ is then approximated on
the grid as:
\begin{align*}
  \Pr(\omega_t = \omega^j |\omega_{t-1} = \omega^i ) = \begin{cases}
    \Phi((q^1 - \rho\omega^i )/\sigma ) & \text{ if } j = 1 \\
    \Phi((q^j - \rho\omega^i )/\sigma ) - \Phi((q^{j-1} - \rho\omega^i
    )/\sigma ) &  \text{ if } 1 < j < N_\omega \\
    1 - \Phi((q^{N_\omega} - \rho\omega^i )/\sigma ) & \text{ if } j =
    N_\omega .
  \end{cases}
\end{align*}
Compute $Pr(\omega_t = \omega^j |\omega_{t-1} = \omega^i )$ for $i, j
= 1, ..., N_\omega$ and construct a $N_\omega \times N_\omega$
transition 
matrix, called $M_\omega$ , of which $(i, j)$-th element is
$\Pr(\omega_t = \omega^j |\omega_{t-1} = \omega^i )$. 
We set $\beta = 0.9$.
\end{mpart}

\begin{mpart}
  Once the state space is discretized, both the value function $V$ and the conditional choice
  probabilities $\Pr_\theta (d_t = 1|\omega_{t-1} , d_{t-1} )$ can be
  expressed by $N_\omega \times 2$ matrices. Write a function m-file
  which takes $\theta$, $M_\omega$ , and 
  $\{\omega^1 , ..., \omega^{N_\omega }\}$ as inputs and then produces the fixed point $V$
  and the conditional choice probability $\Pr_\theta (d_t = 1|\omega^j
  , d_{t-1} )$ for $j = 1, ..., N_\omega$.
\end{mpart}

\begin{mpart}
   ``Discretize'' the data on productivity shock, $\{\omega_{it} \}$, by setting $\omega_{it}$ equal to the closest grid
point among $\{\omega^1 , ..., \omega^{N\omega} \}$, i.e., 
\[ 
\omega_{it}^* = \begin{cases} \omega^1 & \text{ if } \omega_{it} \leq
  q^1 \\
\omega^j & \text{ if } q^j < \omega_{it} \leq q^{j+1} \\
\omega^{N_\omega} & \text{ if } q^{N_{\omega}} < \omega_{it}
\end{cases}
.
\]
\end{mpart}

\begin{mpart}
  Write a function m-file which takes $\theta$, $M_\omega$ , and $\{\omega^1 , ..., \omega^{N_\omega} \}$, $\{\omega_{it}^* \}$, and $\{d_{it }\}$ as inputs
  and produces the negative value of log-likelihood function
  (\ref{e6}) as output. Estimate $\theta$ by 
  maximum likelihood. Report the estimates and their standard errors.
\end{mpart}

\begin{mpart}
  The conditional choice probabilities $\Pr_\theta (d_t = 1|\omega_t , d_{t-1} )$ and the transition matrix of $\omega^*_t$
  jointly characterize the stochastic process of $(d_t , \omega_t^* )$. Using the estimate $\hat{\theta}$ and the transition
  matrix $M_\omega$ , compute the stationary joint distribution of $(d_t , \omega_t^* )$ as well as the conditional
  distribution of $d_t$ given $\omega^*_t$ in the long-run.
\end{mpart}

\begin{mpart}
  Compute the empirical transition matrix of $d_t$ and report it in the $2 \times 2$ table, where the
  $(1, 1)$-th element is a fraction of firms with $d_t$ = 0 given $d_{t-1} = 0$. Compute the predicted
  transition matrix of $d_t$ under the estimated parameters and compare it with the empirical
  transition probability. Does the estimated model successfully replicate the dynamic patterns
  of import status?
\end{mpart}

\begin{mpart}
  Suppose that a government unexpectedly and permanently introduces import subsidies in the
  form of one-time lump-sum transfer for the ``first-time'' importers at $t = 0 $and, as a result,
  the value of $\delta_2$ decreases by 50\%. Analyze how a fraction of importers change over time after
  the introduction of import subsidies starting from the stationary distribution of $(\omega_t^* , d_t )$ by
  plotting a fraction of importers as y-axis and time as x-axis.
\end{mpart}


\end{document}

