code issue

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
Aaron
Posts: 11
Joined: Thu Nov 07, 2013 2:42 pm

code issue

Unread post by Aaron »

Dear All,

I do not understand why I have an error from the following code:

----------------------------------------------------
all 100
com size = 100

com sigu=1; com k =2
com dxa = sigu*%ranmat(size,k); *dis dxa
com x = %zeros(size,k); *dis x

do aa=1, size
com dxaa = %xsubmat(dxa,1,aa,1,k)
com dxaa1 = %sumc(dxaa); dis dxaa1

do kk = 1, k
com x(aa,kk) = %xcol(dxaa1,kk)
end do kk
end do aa

---------------------------------------------------

What I want to do is making a DGP which includes:
1) a random matrix of dx
2) a matrix of x which is defined as a cumulative sum of dx.

When I print dxaa1, it gives two numbers, like
-0.23
0.11

If it is for aa==1, x needs to show

-0.23 0.11
0.00 0.00
0.00 0.00
. .
. .

Finally, after all the do loop, zero values in x should be changed cumulative column sum of dx.
What could be my mistake in this code?

Thank you.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: code issue

Unread post by TomDoan »

It looks like you're thinking Gauss/Matlab rather than RATS. Wouldn't

set dx 1 100 = %ran(sigu)
acc dx / x

give you what you want?

Regarding your code,

com x(aa,kk) = %xcol(dxaa1,kk)

seems to be trying to push the whole column of values into a single location. What you needed there was

com x(aa,kk) = dxaa1(kk,1)
Aaron
Posts: 11
Joined: Thu Nov 07, 2013 2:42 pm

Re: code issue

Unread post by Aaron »

Yes, it works now. Thank you very much. :D
Post Reply