

    \filetitle{sort}{Sort SVAR parameterisations by squared distance of shock reponses to median}{SVAR/sort}

	\paragraph{Syntax}
 
 \begin{verbatim}
 [B,DATA,INDEX,CRIT] = sort(A,DATA,SORTBY,...)
 \end{verbatim}
 \paragraph{Input arguments}
 
 \begin{itemize}
 \item
   \texttt{A} {[} SVAR {]} - SVAR object with multiple parameterisations
   that will be sorted.
 \item
   \texttt{DATA} {[} tseries \textbar{} struct \textbar{} empty {]} -
   SVAR data (endogenous variables and structural shocks); the structural
   shocks will be re-ordered according to the SVAR parameterisations. You
   can leave the input argument \texttt{DATA} empty.
 \item
   \texttt{SORTBY} {[} char {]} - Text string that will be evaluated to
   compute the criterion by which the parameterisations will be sorted;
   see Description for how to write \texttt{SORTBY}.
 \end{itemize}
 \paragraph{Output arguments}
 
 \begin{itemize}
 \item
   \texttt{B} {[} SVAR {]} - SVAR object with parameterisations sorted by
   the specified criterion.
 \item
   \texttt{DATA} {[} tseries \textbar{} struct \textbar{} empty {]} -
   SVAR data with the structural shocks re-ordered to correspond to the
   order of parameterisations.
 \item
   \texttt{INDEX} {[} numeric {]} - Vector of indices so that
   \texttt{B = A(INDEX)}.
 \item
   \texttt{CRIT} {[} numeric {]} - The value of the criterion based on
   the string \texttt{SORTBY} for each parameterisation.
 \end{itemize}
 \paragraph{Options}
 
 \begin{itemize}
 \item
   \texttt{'progress='} {[} \texttt{true} \textbar{}
   \emph{\texttt{false}} {]} - Display progress bar in the command
   window.
 \end{itemize}
 \paragraph{Description}
 
 The individual parameterisations within the SVAR object \texttt{A} are
 sorted by the sum squared distances of selected shock responses to the
 respective median reponses. Formally, the following criterion is
 evaluated for each parameterisation
 
 \[ \sum_{i\in I,j\in J,k\in K} \left[ S_{i,j}(k) - M_{i,j}(k) \right]^2 \]
 
 where $S_{i,j}(k)$ denotes the response of the i-th variable to the j-th
 shock in period k, and $M_{i,j}(k)$ is the median responses. The sets of
 variables, shocks and periods, i.e. \texttt{I}, \texttt{J}, \texttt{K},
 respectively, over which the summation runs are determined by the user
 in the \texttt{SORTBY} string.
 
 How do you select the shock responses that enter the criterion in
 \texttt{SORTBY}? The input argument \texttt{SORTBY} is a text string
 that refers to array \texttt{S}, whose element \texttt{S(i,j,k)} is the
 response of the i-th variable to the j-th shock in period k.
 
 \paragraph{Example}
 
 Sort the parameterisations by squared distance to median of shock
 responses of all variables to the first shock in the first four periods.
 The parameterisation that is closest to the median responses
 
 \begin{verbatim}
 S2 = sort(S1,[],'S(:,1,1:4)')
 \end{verbatim}


