Page 1 of 1

Vector assigned to scalar

Posted: Wed Sep 28, 2011 5:44 am
by Zappa_F
Hi Everybody,

I do have a problem with the following code:

Code: Select all

for %criterion aic bic hqc ' Specification of page pageselect {%daily} %spec = "spline_" + %criterion ' vector with Information criterion from different knot specifications vector(!Kmax - 1) {%criterion}_knots for !k=2 to !Kmax {%criterion}_knots(!k - 1) = {%criterion}_!k delete {%criterion}_!k next ' minimum information criterion scalar min_knots_{%criterion} = @cimin({%criterion}_knots) +1 scalar min_{%criterion}= @cmin({%criterion}_knots) scalar obs_per_knots_{%criterion} = (!end - !start)/min_knots_{%criterion} !minknot = min_knots_{%criterion} next
If i comment the scalar part and !minknot eveything just works perfectly fine.

The error message I get is "vector assigned to scalar" I even understand the error message because the right hand side of the first scalar equation is a 1 by 1 vector. Now, a 1 by one vector is the same as a scalar to me. But unfortunately I do not know how to "explain" this fact to the compiler which is reading through the code...

Has anybody a suggestion for solving this problem?

Thanks in advance

Vector assigned to scalar

Posted: Wed Sep 28, 2011 6:26 am
by EViews Gareth
Create a temporary scalar that is equal to the (1,1) element of your vector, and use that scalar instead.

Re: Vector assigned to scalar

Posted: Thu Sep 29, 2011 7:34 am
by Amber
Dear Gareth, I also have a similar problem. Could you please tell me how to extract the 1st element out of one vector in command? Thanks!
I have tried scalar element1=@rows(vector,1). But it doesn't work.

Re: Vector assigned to scalar

Posted: Thu Sep 29, 2011 7:49 am
by EViews Gareth

Code: Select all

scalar element1 = myvector(1,1)

Re: Vector assigned to scalar

Posted: Fri Sep 30, 2011 6:46 am
by Zappa_F
Dear Gareth and Amber!

First of all thank you, for helping me out.

As I saw Amber's thread I got the idea to write the code as follows:

Code: Select all

vector interimvec_{%criterion} = @cimin({%criterion}_knots) +1 scalar min_nod_{%criterion} = interimvec_{%criterion}(1,1) vector interimvec_{%criterion} = @cmin({%criterion}_knots) scalar min_{%criterion}= interimvec_{%criterion}(1,1) scalar obs_per_knots_{%criterion} = (!end - !start)/min_nod_{%criterion}
I'm not quite sure whether this is exactly the way Gareth you meant me to do it, but I think it works :wink: