Thank you both Jack and Hélio for your suggestions! Both example work well.
Jack's nice version is about 10% less time consuming than my original
example (at least in my procedure here).

Best,
Artur


2014-03-29 16:08 GMT+01:00 Hélio Guilherme <helioxentric(a)gmail.com>:

> This was my attempt (but results are the expect ones):
>
> set seed 732237
>
>
> 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
>
> #Vectorized
> set seed 732237
> matrix uu = mnormal(T,1)
> matrix dxx = mnormal(T,1)
> matrix w = zeros(T,1) # same as initial y
>
> result = ( uu = u ) ? "Equal" : "Different"
> printf "uu and u matrix are %s\n", result
>
> w[2:T,1] = w[1:(T-1),1] +  b1*w[1:(T-1),1] + b2*dxx[2:T,1] + uu[2:T,1]
>
> result = ( w = y ) ? "Equal" : "Different"
>
> print result
>
> matrix z = w ~ y
>
> print z
>
> ---
> I now that Jack already gave a better answer.
>
> Hélio
>
>
> On Sat, Mar 29, 2014 at 12:40 PM, Artur T. 
> <artur.tarassow(a)googlemail.com>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>
>>
>> Thanks in advance.
>> Artur
>>
>> _______________________________________________
>> Gretl-users mailing list
>> Gretl-users(a)lists.wfu.edu
>> http://lists.wfu.edu/mailman/listinfo/gretl-users
>>
>
>
> _______________________________________________
> Gretl-users mailing list
> Gretl-users(a)lists.wfu.edu
> http://lists.wfu.edu/mailman/listinfo/gretl-users
>
Thank you both Jack and Hélio for your suggestions! Both example work well.
Jack's nice version is about 10% less time consuming than my original example (at least in my procedure here).

Best,
Artur


2014-03-29 16:08 GMT+01:00 Hélio Guilherme <helioxent...@gmail.com>:
This was my attempt (but results are the expect ones):

set seed 732237


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

#Vectorized
set seed 732237
matrix uu = mnormal(T,1)
matrix dxx = mnormal(T,1)
matrix w = zeros(T,1) # same as initial y

result = ( uu = u ) ? "Equal" : "Different"
printf "uu and u matrix are %s\n", result

w[2:T,1] = w[1:(T-1),1] +  b1*w[1:(T-1),1] + b2*dxx[2:T,1] + uu[2:T,1]

result = ( w = y ) ? "Equal" : "Different"

print result

matrix z = w ~ y

print z

---
I now that Jack already gave a better answer.

Hélio


On Sat, Mar 29, 2014 at 12:40 PM, Artur T. <artur.taras...@googlemail.com> 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>

Thanks in advance.
Artur

_______________________________________________
Gretl-users mailing list
gretl-us...@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users


_______________________________________________
Gretl-users mailing list
gretl-us...@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users

Reply via email to