@ ------------------------------- CoRRAM_1.src ---------------------------------

   Alfred Maußner
   23 December 2010

   First piece of code to solve a DSGE model via linear or quadratic
   approximation of the model at the stationary equilibrium of the
   underlying deterministic model.

----------------------------------------------------------------------------- @



/********************************************************************************************************************/
/* The following code definces a Gauss structure 
** to provide variable names and other information required .
** DO NOT edit THIS CODE!
*/

struct Variable 
{string varname;
 string vartype;    @ x=predetermined variable, y=not predetermined variable, z shock variable @
 scalar varpos;     @ the index of the variable in x, y, or z @
 scalar crosscorr;  @ =1 the program compute cross correlations with this variable @
 scalar relsx;      @ =1 the program computes standard deviations relative to the standard deviation of this variable @
 scalar varprint;   @ =1 print second moments for this variable @
 scalar varplot;    @ =1 plott impulse responses of this variable @
 scalar plotno;     @ the number of the graphics panel in which the variable is plotted, up to six different panels are @
                    @ supported                                                                                         @
};
/*********************************************************************************************************************/

/************************************** DO NOT EDIT THE CODE HERE ******************************************/


_nvar=_nx+_ny+_nz;

/* Inititialize the structure that stores information on the model's variables */
struct Variable Var;
Var=reshape(Var, _nvar, 1);

/* Draw and store random numbers if demanded by the user */
if _makeShocks;
    eps_array=arrayinit(nofs|_nz|nobs+1,0);
    for i (1,nofs,1);
        eps=mattoarray(rndn(_nz,nobs+1));
        eps_array[i,.,.]=eps;
    endfor;
    save eps_array;
endif;

/* Inititilize the matrices if the model is log-linearized by the user */
if not _equations;
    _nl=_ny-_ns-_nu;
    Cu=zeros(_nu,_nu);
    Cxl=zeros(_nu,_nx+_nl);
    Cz=zeros(_nu,_nz);
    Dxl=zeros(_nx+_nl,_nx+_nl);
    Fxl=Dxl;
    Du=zeros(_nx+_nl,_nu);
    Fu=Du;
    Dz=zeros(_nx+_nl,_nz);
    Fz=Dz;
    clear Lsx, Lsz;
else;
    clear _xstar, _ystar;
endif;

/* Inititialize the matrices that store information of the shock process */
clear _sigma;
_Rho=zeros(_nz,_nz);
_Omega=eye(_nz);
clear _eqno;

/* Initialize the array that can be used to position the legend individually */
ord=_nz|6|2;
_plegend=arrayinit(ord,0);
for i (1,6,1);
    for j (1,_nz,1);
        _plegend[j,i,1]=miss(1,1);
    endfor;
endfor;

/* GetOmega:
**
** Usage: y=GetOmega(x)
**
** input:   x, a nz by nz symmetric positive definite matrix,
** output:  y, a nz by ny matrix, the matrix square root of x=C*Lambda^(-1/2), where Lambda^(1/2) is a diagonal matrix with
**                                the positive square roots of x on its main diagonal and where C'C=I, the matrix of eigenvectors of x.
*/

proc(1)=GetOmega(x);

    local va, ve, l, i, n;
    
    { va,ve } = eighv(x);
    
    @ normalize the eigenvectors in ve @
    ve=L2Norm(ve);
    @ compute the square roots of va @
    n=rows(x);
    l=zeros(n,n);
    for i (1,n,1);  l[i,i]=sqrt(va[i]); endfor;
    
    retp(ve*l);
    
endp;

/*******************************************************************************/
