string loop to generate an 'ad hoc' autoregressive equation

For questions regarding programming in the EViews programming language.

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

Novi
Posts: 44
Joined: Sun May 16, 2010 11:48 am

string loop to generate an 'ad hoc' autoregressive equation

Postby Novi » Fri Sep 28, 2012 8:03 am

Hi All,
I am facing problems to write a formula for an autorgeressive equation where the coefficients are not the default ones, but they are defined by me in a specific coef object named phi1. (I cannot use the standard syntax "equation standard.ls x x(-1 to -!pmax)" because then the coefficients will be the default ones)

Basically what I would like to get is to generate an equation of the type x=phi1(1)+phi1(2)*x(-1)+phi1(3)*x(-2)+....+phi1(p)*x(-p)

I wrote the following code:

Code: Select all

%auto= "(" for !j=1 to !pmax %auto= %auto +phi1(!j)+"phi1(!j)*x(-"@str(-!j)")" next '%auto = %auto ")" equation try.ls x {%auto}
But I always get the error that auto is not defined or an illegal command...do you know what I am doing wrong?

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

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby EViews Gareth » Fri Sep 28, 2012 8:20 am

The quotes in your %alpha = line seem off. It looks like you inserted them at random.

Novi
Posts: 44
Joined: Sun May 16, 2010 11:48 am

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby Novi » Mon Oct 01, 2012 7:44 am

Sorry I don't think I understand what you mean...how would you write it then??

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

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby EViews Gareth » Mon Oct 01, 2012 8:53 am

I don't understand that line at all, so can't see how to fix it.

Novi
Posts: 44
Joined: Sun May 16, 2010 11:48 am

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby Novi » Mon Oct 01, 2012 9:06 am

Dear Gareth,
I am sorry If my code is so unclear :( I will try 2 elaborate a bit on it...
So, I am trying 2 figure out a way 2 save time and witing complicated autoregressive expressions through loops.
For example the following code
coef(2) teta

%nom = "("

for !j=1 to !kmax
%nom = %nom + "+exp(teta(1)*" +@str(!J) + "+teta(2)*" + @str(!J^2) + ") "
next
%nom = %nom + ")"
will actually write an expression like "(+exp(teta(1)*1+teta(2)*1)+exp(teta(1)*2+teta(2)*4)...)" for as long as !kmax is, and then I can use this in an equation by simply writing "equation eq1.LS y={%nom}+ c(1)*x " , clearly all of this runs in a program and it saves me a lot of time in writing long polynomials.

Now, I need to write a similar code but for a more simple autoregressive polynomial, one like Phi1(1)+phi1(2)*x(-2)+phi1(3)*x(-3)+.....+phi1(p+1)*x(-p).... I need a string expression which then I can use multiple times within my program. Is there a way in which I can modify the above code to obtain what I need? Hope this is clearer....many many thanks!

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

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby EViews Gareth » Mon Oct 01, 2012 9:13 am

Code: Select all

%auto= %auto +phi1(!j)+"phi1(!j)*x(-"@str(-!j)")"
Again, it looks like you inserted quotation marks at random into this.

At a guess:

Code: Select all

%auto= %auto + " + phi1(!j)*x(-" + @str(-!j) + ")"

Novi
Posts: 44
Joined: Sun May 16, 2010 11:48 am

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby Novi » Mon Oct 01, 2012 9:18 am

I am not really familiar with this string variables thing that's why I make mistakes.... sorry!
anyway I still get the the illegal command error with your corrections :(

Novi
Posts: 44
Joined: Sun May 16, 2010 11:48 am

Re: string loop to generate an 'ad hoc' autoregressive equat

Postby Novi » Mon Oct 01, 2012 9:56 am

Found the problem!!!!! auto is actually an eviews command which gets the program confused, I cannot name my string variable auto!

For everybody who needs it here it is the right code:

Code: Select all

%pol= "(" for !j=1 to !pmax %pol= %pol + " + phi1("+@str(!j)+")*x(-" + @str(!j) + ")" next %pol = %pol+")"
Thank u so much again!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests