\section{Example of sorting bias: omitted variables} \label{Section:Example} 

This section clearly motivates the importance of the bias that arises from sorting into groups and thereby complicates the analysis of group-level data. The focus in the following example is on the bias that results when variables influencing peer selection are not observed in the data. %Appendix \ref{Appendix:Example} continues this example by illustrating the bias arising when variables influencing peer selection are measured with error. Appendix \ref{Appendix:MeasurementError} shows that sorting bias persists -- even in the absence of omitted variables and measurement error -- when the analysis is based on market-level, rather than group-level variables.



\subsection{Matching}

To begin with, consider a credit market with four entrepreneurs $A$, $B$, $C$ and $D$, who have no pledgeable collateral, and one lender, who offers a group-lending contract. In this contract, loans are given to groups of two and borrowers repay an interest rate $r$ if their project succeeds plus a joint-liability payment $q\leq r$ when they succeed and their partner defaults. Assume that the entrepreneurs prefer to take loans in groups over the outside option of remaining unmatched.
There are three feasible group constellations or matchings. One possibility is that borrower $A$ forms a match with borrower $B$ and borrower $C$ matches with borrower $D$. Denote this matching $\mu_1=\{ AB, CD \}$. The other two possible matchings are $\mu_2=\{ AC, BD \}$ and $\mu_3=\{ AD, BC \}$. I will refer to $M=\{ \mu_1, \mu_2, \mu_3\}$ as the set of feasible matchings. 


Which of these matchings is observed depends on all four borrowers' preferences over feasible matches. Each of the six potential matches between any two borrowers $i$ and $j$ has an associated match valuation, $V_{ij}$. %Assume, for illustrative convenience, preferences to be aligned. Then, 
Using the equilibrium characterisation under non-transferable utility in \citet{Klein2015a}, the equilibrium condition for $\mu_1$ can be written in the form of the inequality
\begin{eqnarray} \label{Eqn:IntroExampleEquilibriumCondition}
\max\{ V_{AB}, V_{CD} \} &>& \max\{ V_{AC}, V_{BD}, V_{AD}, V_{BC} \}.
\end{eqnarray} 
The inequality states that the equilibrium matching contains the match with the largest of the six match valuations. The intuition is that those two borrowers who form the match with the highest valuation have no incentive to deviate. In this simple example, the second equilibrium group is formed by the two residual borrowers. Put differently, the valuation of every non-equilibrium group must be smaller than the opportunity costs of its members to leave their equilibrium groups $AB$ and $CD$ and form a new group.



\subsection{Match valuation}

The equilibrium condition is based on the six match valuation equations. These equations are taken from the model in \citet{Ghatak1999} with %but only include the interaction terms $u_{i,j}=-q[p_i(1-p_j)-\epsilon_{ij}]$ that are relevant for the borrowers' group formation decision. 
two modifications. First, I denote the borrowers' inherent probability of default as $d_i:=1-p_i$ and assume -- for clearer exposition -- that $d_id_j$ is close to zero and therefore negligible. Second, I assume that all borrowers are exposed to the same external shocks but differ in the intensity $\gamma$ with which external shocks affect their probability of default. 
This results in linear match valuations as follows:
\begin{eqnarray}
V_{ij} = u_{i,j} + u_{j,i} &=& -q(p_i+p_j) + 2qp_ip_j + 2q\gamma_i\gamma_j \\
       &\stackrel{d_id_j=0}{=}& -q(d_i+d_j) + 2q\epsilon_{ij} \label{Eqn:ExampleSelectionEqn2}\\ 
       &=& \alpha_1 \epsilon_{ij} + \eta_{ij}. \label{Eqn:ExampleSelectionEqn}
\end{eqnarray}
Here, $d_i$ and $d_j$ give the risk type (probability of default) of borrower $i$ and $j$. 
%The parameter $\alpha_1$ in Eqn \ref{Eqn:ExampleSelectionEqn} equals $2q$. 
When risk type is unobserved, the term $-q(d_i+d_j)$ is captured in the match-specific error term $\eta_{ij}$. 

For this example, let the characteristics of the four borrowers be as given in Table \ref{Tab:BiasExampleSimple1}. Furthermore, let the interest payment be $r=2$ and set the joint liability payment to $q=1$. The six valuations, $V_{ij}$, are then given in Table \ref{Tab:BiasExampleSimple2}.

\begin{table}[htbp!]
  \begin{center}
    \begin{minipage}[c]{0.3\linewidth}
\centering %\hfill
      \caption{Borrower-level characteristics. \\ - $d_i$: failure prob. \\ - $\gamma_i$: risk exposure} \label{Tab:BiasExampleSimple1}
    \end{minipage}
    \begin{minipage}[c]{0.6\linewidth}
\centering
\small
\begin{tabular}{c||cc}
& $d_i$ & $\gamma_i$ \\
\hline\hline
\multicolumn{1}{|c||}{$A$} & 0.2 & \multicolumn{1}{c|}{0.3}\\
\multicolumn{1}{|c||}{$B$} & 0.3 & \multicolumn{1}{c|}{0.4} \\
\hline\hline
\multicolumn{1}{|c||}{$C$} & 0.3 & \multicolumn{1}{c|}{0.2} \\
\multicolumn{1}{|c||}{$D$} & 0.4 & \multicolumn{1}{c|}{0.3} \\
\hline\hline
\end{tabular}
    \end{minipage}
  \end{center}
\end{table}

\noindent Which groups are observed in equilibrium is determined by the condition in Eqn \ref{Eqn:IntroExampleEquilibriumCondition}. In this example, the values in Table \ref{Tab:BiasExampleSimple1} were chosen such that the observed component $\gamma_i$ and the unobserved component $d_i$ are uncorrelated, i.e.\ $cor(\gamma_i,d_i)=0$. Table \ref{Tab:BiasExampleSimple2} illustrates how, for observed equilibrium groups, the independent variable $\epsilon_{ij}$ will be correlated with the error term $\eta_{ij}$ when matching is on both these variables, i.e.\ when $\alpha_1\neq 0$. Simple algebra confirms that for the set of feasible groups in Table \ref{Tab:BiasExampleSimple2}, the correlation between $\epsilon_{ij}$ and $\eta_{ij}$ is zero. For the equilibrium groups in $\mu=\{ AB,CD \}$, however, we find $cov(\epsilon_{ij}, \eta_{ij})=+0.06$.

\begin{table}[htbp!]
  \begin{center}
    \begin{minipage}[c]{0.3\linewidth}
\centering %\hfill
      \caption{Group-level variable values of\\ - $(d_i+d_j)$: failure prob. \\ - $\epsilon_{ij}$: risk exposure \\ - $V_{ij}$: group valuation \\ - $Y^{\beta_1=0}_{ij}$: group outcome} \label{Tab:BiasExampleSimple2}
    \end{minipage}
    \begin{minipage}[c]{0.6\linewidth}
\centering
\small
\begin{tabular}{c||cccc}
& $(d_{i}+d_j)$ & $\epsilon_{ij}=\gamma_i\gamma_j$ & $V_{ij}$ & $Y^{\beta_1=0}_{ij}$ \\
\hline\hline
\multicolumn{1}{|c||}{$AB$}& 0.5 & 0.12 & $-$0.26 & \multicolumn{1}{c|}{3.5} \\
\hline
\multicolumn{1}{c||}{$AC$} & 0.5 & 0.06 & $-$0.38 & 3.5 \\
\multicolumn{1}{c||}{$AD$} & 0.6 & 0.09 & $-$0.42 & 3.4 \\
\multicolumn{1}{c||}{$BC$} & 0.6 & 0.08 & $-$0.44 & 3.4 \\
\multicolumn{1}{c||}{$BD$} & 0.7 & 0.12 & $-$0.46 & 3.3 \\
\hline
\multicolumn{1}{|c||}{$CD$}& 0.7 & 0.06 & $-$0.58 & \multicolumn{1}{c|}{3.3} \\
\hline\hline
%\multicolumn{5}{l}{Note that here: $q=1$, $r=2$ and}\\
%\multicolumn{5}{l}{$max\{ \epsilon_{ij}\} \leq min\{ p_i(1-p_j), p_j(1-p_i) \}$}
\end{tabular}
    \end{minipage}
  \end{center}
\end{table}



\subsection{Match outcome}

\noindent Let us now turn to the group outcome, $Y^*_{ij}$, which is given by the expected repayment: %from the two-borrower equivalent of Eqn \ref{Eqn:GrpOutcome} as below:
\begin{eqnarray}
Y^*_{ij} &=& (r+q)(p_i+p_j) - 2qp_ip_j - 2q\epsilon_{ij} \\
         &\stackrel{d_id_j=0}{=}& 2r - (r-q)(d_i+d_j) - 2q\epsilon_{ij}\\
         &=& \beta_0 + \beta_1\epsilon_{ij} + \varepsilon_{ij}.
\end{eqnarray}
\noindent Note that $\frac{\partial V_{ij}}{\partial p_i}=-q+2qp_j>0$ for $p_j>0.5$ and $\frac{\partial Y^*_{ij}}{\partial p_i}=r+q-2qp_j>0$ for $r>q$. That is, both match valuation and match outcome are increasing in risk type. In fact, the unobservable component in the outcome equation is $\varepsilon_{ij}=\delta\eta_{ij}$ with $\delta=(r-q)/q=+1$ and the outcome equation can be rewritten as %$cov(\varepsilon_{ij},\eta_{ij})/var(\eta_{ij})=+1$.
\begin{eqnarray}
Y^*_{ij} &=& \beta_0 + \beta_1\epsilon_{ij} + \delta\eta_{ij}. \label{Eqn:ExampleOutcomeEqn}
\end{eqnarray}
Now consider estimating the parameter $\beta_1$. Assume, for simplicity, that the true coefficient is $\beta_1=0$. That is, the group outcome $Y^*_{ij}$ only depends on the unobservable risk type. A simple OLS based on the observed data points yields an upwards-biased coefficient of $\hat \beta_1=+10/3$ (see Figure \ref{Fig:Bias pi}). It is clear that the source of the bias is the correlation between the independent variables and the error term. For the expected value of $\hat{\beta_1}$, we have $\mathbb E[\hat{\beta_1}] = \beta_1 + \frac{cov(\epsilon_{ij}, \varepsilon_{ij})}{var(\epsilon_{ij})} = 0 + \frac{0.06}{0.018} = 10/3$.


Figure \ref{Fig:Bias pi} also illustrates how the bias resolves when groups are assigned randomly. %\footnote{It also follows trivially that there is no selection problem when borrowers match either on unobservables \textit{or} observables only} 
Then, the expected marginal effect $\hat \beta_1$ can be seen as the equally weighted average of the OLS estimates for the three equiprobable, feasible group constellations, i.e.\ $\frac{1}{3}(+\frac{10}{3}-\frac{10}{3}+0)=0$. 
%This is essentially the outcome of the ideal experiment outlined in the introductory section. 
A comparison of the coefficient estimate for the endogenously formed groups ($\hat \beta_1$=$10/3$) and the random assignment ($\hat \beta_1^*$=$0$) separates the bias from sorting.

%http://www.texample.net/tikz/examples/line-plot-example/
%http://www.faqoverflow.com/tex/1175.html
\begin{figure}[htbp!]
  \begin{center}
    \begin{minipage}[c]{0.3\linewidth}
\centering %\hfill
      \caption{Bias on coefficient pertaining to risk exposure term $\epsilon_{ij}$ from endogenous sorting when risk type is unobserved. Bias resolves (i) under random assignment, or (ii) when matching is independent of risk exposure, i.e.\ $\alpha_1=0$.} 
      \label{Fig:Bias pi}
    \end{minipage}
    \begin{minipage}[c]{0.6\linewidth}
\centering
\begin{tikzpicture}[domain=0:4, scale=1.2]
%axis
	\draw[->] (-0.2,0) -- (4.5,0) node[below right] {$\epsilon_{ij}$};
	\draw[->] (0,-.2) -- (0,4.2) node[above left] {$Y^*_{ij}$};
%lines
\draw[dashed,color=black] plot (\x, 2); 
\draw[dashed,color=black] plot (0.5,3.5) -- (4,0);
\draw[color=black] plot (0,0) -- (3.5,3.5); 
%ticks (y-axis)
\draw (1pt, 1) -- (-3pt,1) node[anchor=east] {3.3}; 
\draw (1pt, 2) -- (-3pt,2) node[anchor=east] {3.4}; 
\draw (1pt, 3) -- (-3pt,3) node[anchor=east] {3.5}; 
%ticks (x-axis)
\draw (1, 1pt) -- (1,-3pt) node[anchor=north] {.06}; 
\draw (5/3, 1pt) -- (5/3,-3pt) node[anchor=north] {}; 
\draw (2, 1pt) -- (2,-3pt) node[anchor=north] {.09}; 
\draw (3, 1pt) -- (3,-3pt) node[anchor=north] {.12}; 
%arrows
	\draw [dotted] (3.25,2) arc (0:360:1.25cm);
	\draw [->, color=black] (0.75, 2) arc (180:220:1.25cm);
	\draw [->, color=black] (3.25, 2) arc (0:40:1.25cm);
%points
	\draw plot[mark=square*, mark options={fill=white}] (3,3) node[right]{$AB$};
	\draw plot[mark=square*, mark options={fill=white}] (1,1) node[left]{$CD$};
	\draw plot[mark=square*, mark options={fill=white}] (1,3) node[left]{$AC$};
	\draw plot[mark=square*, mark options={fill=white}] (3,1) node[right]{$BD$};
	\draw plot[mark=square*, mark options={fill=white}] (2,2) node[below right]{$BC$};
	\draw plot[mark=square*, mark options={fill=white}] (5/3,2) node[above left]{$AD$};

	\draw plot[mark=x] (1,1);
	\draw plot[mark=x] (3,3);
%text along path
        \draw[decorate, decoration={text along path, text={${ \ \beta_1}$=0}}] (0,2.05) -- (1,2.05);
        \draw[decorate, decoration={text along path, text={${ \ \ \hat \beta_1}$=${\frac{10}{3} \ \ }$}}] (2,2.15) -- (3,3.15);
%legend
	\begin{scope}[shift={(0.85,3.55)}] 
	\draw[yshift=0.6\baselineskip] (0,0) -- 
		plot[mark=x] (0.15,0) -- (0.3,0)
		node[right]{systematic matching};
	\draw[yshift=1.2\baselineskip] (0,0) -- 
		plot[mark=square*, mark options={fill=white}] (0.15,0) -- (0.3,0)
		node[right]{random assignment};
	\end{scope}
%braces
%	\draw plot (4.12,2) node[right]{ \shortstack{ expected outcome under\\[-0.25ex] a) random assignment\\[-0.25ex] \ \ b) matching on $\eta_{ij}$ only} };
\end{tikzpicture}
    \end{minipage}
  \end{center}
\end{figure}

\noindent The matching model in the econometric analysis below controls for this bias by estimating both the matching and outcome equations simultaneously. The variation in borrower types across markets serves the role of an instrumental variable and helps to identify the coefficients in the outcome equation.



