On Sat, 29 Mar 2014, Artur T. wrote:

> Hello,
>
> I was thinking how to implement the following code snippet into a
> vectorized form, but I couldn't figure out how to do this effectively. The
> issue I face is the lagged value of y which changes over the loop. Does
> anybody have an alternative way to run this thing?
>
> <hansl>
> scalar T = 100
> scalar b1 = -0.2
> scalar b2 = 0.5
> matrix u = mnormal(T,1)
> matrix dx = mnormal(T,1)
> matrix dy = zeros(T,1)
> matrix y = zeros(T,1)
>
> loop i=2..T -q
>    dy[i] = b1*y[(i-1)] + b2*dx[i] + u[i]
>
>    y[i] = y[i-1] + dy[i]
> endloop
> <\hansl>

This ought to work:

<hansl>
scalar T = 100
scalar b1 = -0.2
scalar b2 = 0.5
matrix u = mnormal(T,1)
matrix dx = mnormal(T,1)
matrix z = u + b2*dx
matrix y = varsimul({1+b1}, z[2:], {0})
</hansl>


-------------------------------------------------------
   Riccardo (Jack) Lucchetti
   Dipartimento di Scienze Economiche e Sociali (DiSES)

   Università Politecnica delle Marche
   (formerly known as Università di Ancona)

   r.lucchetti(a)univpm.it
   http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------

Reply via email to