Vector assigned to scalar

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

Zappa_F
Posts: 14
Joined: Wed Sep 28, 2011 5:27 am

Vector assigned to scalar

Postby Zappa_F » Wed Sep 28, 2011 5:44 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

Vector assigned to scalar

Postby EViews Gareth » Wed Sep 28, 2011 6:26 am

Create a temporary scalar that is equal to the (1,1) element of your vector, and use that scalar instead.

Amber
Posts: 31
Joined: Wed Aug 03, 2011 4:35 am

Re: Vector assigned to scalar

Postby Amber » Thu Sep 29, 2011 7:34 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13585
Joined: Tue Sep 16, 2008 5:38 pm

Re: Vector assigned to scalar

Postby EViews Gareth » Thu Sep 29, 2011 7:49 am

Code: Select all

scalar element1 = myvector(1,1)

Zappa_F
Posts: 14
Joined: Wed Sep 28, 2011 5:27 am

Re: Vector assigned to scalar

Postby Zappa_F » Fri Sep 30, 2011 6:46 am

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:


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests