## function to convert rect to vect[vect]

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.

### function to convert rect to vect[vect]

the following function wo't work right: I dont understand why it will dispay different tpvv

declare rect tp(2,2)
compute tp=||0.7,0.2|0.3,0.8||

declare vect[vect] tpvv(2)
compute tpvv = %rectovv(tp)
disp tpvv(1)
disp tpvv(2)

* result ok
* 0.70000 0.30000
* 0.20000 0.80000

do i=1,2
compute tpvv(i) = ||%ran(1),%ran(1)||
disp tpvv(i)
end do i

*result:
*%RECTOVV2, line 2 Using TPVV as VECTOR(VECTOR)
* 0.47879 1.44596
* 0.47630 0.43394
* question: the warning message means I can't use vector(vector) as parameters?

disp 'tpvv'
do i=1,2
disp tpvv(i)
end do i

******** the following output is totally wrong**************
* tpvv
* %RECTOVV2, line 2 Using TPVV as VECTOR(VECTOR)
* 3.23806e+262 0.43394
* 3.23806e+262 0.43394
* question: why ???????

function %Rectovv m
type vect[vect] %Rectovv
type rect m
local integer nc nr i j
compute nc = %cols(m)
compute nr = %rows(m)
dim %Rectovv(nc)
do i=1,nc
dim %Rectovv(i)(nr)
end do i
do i=1,nc
do j=1,nr
compute %rectovv(i)(j) = m(j,i)
end do j
end do i
end
airways1

Posts: 5
Joined: Thu Apr 10, 2008 3:17 pm

### Re: function to convert rect to vect[vect]

The problem is the interpretation of the vect[vect] = vect[vect] when you process the return information from the function. We didn't really set that up to copy all the information through the entire stack of components. We'll put a warning to that effect in future releases.

At any rate, a simple workaround is to pass the target vect[vect] as a parameter. That way, the procedure is working with the actual target array. This will always significantly simplify your code by using the %XCOL function to pull apart the input matrix.

Code: Select all
`procedure %Rectovv r mtype vect[vect] *rtype rect m*local integer idim r(%cols(m))ewise r(i)=%xcol(m,i)enddeclare rect tp(2,2)compute tp=||0.7,0.2|0.3,0.8||declare vect[vect] tpvv(2)@%rectovv tpvv tpdisp tpvv(1)disp tpvv(2)`
TomDoan

Posts: 2727
Joined: Wed Nov 01, 2006 5:36 pm

Return to Help With Programming

### Who is online

Users browsing this forum: No registered users and 1 guest