one single program that works for differently named objects

For questions regarding programming in the EViews programming language.

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

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

one single program that works for differently named objects

Postby neptunhiker » Sat Oct 20, 2012 7:47 am

Hi everyone,

I am absolutely new to eViews and I am very grateful for your patience with me and your advice.

I have written a program which I want to run on different pages in my workfile, which contains times series that have similar names. Just to clarify what I mean, here is a short example.

Page 1: series TTT_8
Page 2: series TTT_4
Page 3: series TTT_12

So, the pages each contain a series with the Name TTT_ followed by an id, which can have one digit, also 2,3 or more. The programs that I have written look like this:

For Page 1:

Code: Select all

series r=TTT_8/TTT_8(-1)
For Page 2:

Code: Select all

series r=TTT_4/TTT_4(-1)
For Page 3:

Code: Select all

series r=TTT_12/TTT_12(-1)
As you can imagine, there will be more than 3 pages and more than 3 programs to write in the future. So, I would like to write a program, that works for objects with different names. Is there a possibiliy to substitute the id in my times series with something like a star or a question mark? I hope I have made myself clear. Not so easy to explain for a beginner. Anyway, what you see below is what I have in mind for a solution:

Code: Select all

series r=TTT_*/TTT_*(-1)
Or with a question mark:

Code: Select all

series r=TTT_?/TTT_?(-1)
Thank you very much for your help. I really appreciate it.

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

Re: one single program that works for differently named obje

Postby EViews Gareth » Sat Oct 20, 2012 9:16 am

Just use a program variable. Reading Chapter 6 of the EViews Command and Programming Reference is probably beneficial.

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: one single program that works for differently named obje

Postby neptunhiker » Mon Oct 22, 2012 1:06 am

Thank you for your advice. I read chapter 6 and here is what I can come up with:

For Page 1:

Code: Select all

' Define program variable %id="8" ' Calculate return series series r=TTT_{%id}/TTT_{%id}(-1)
For Page 2:

Code: Select all

' Define program variable %id="4" ' Calculate return series series r=TTT_{%id}/TTT_{%id}(-1)
For Page 3:

Code: Select all

' Define program variable %id="12" ' Calculate return series series r=TTT_{%id}/TTT_{%id}(-1)
So far so good, I guess, but that is not really what I wanted. I would like to avoid defining any id. The program variable that I am looking for is supposed to be some kind of placeholder. Unfortunately I didn't find anything like that in the users guide. I'd be happy, if someone could guide me in the right direction;)

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

Re: one single program that works for differently named obje

Postby EViews Gareth » Mon Oct 22, 2012 7:44 am

You could use the @wlookup command to obtain the name of the series in a specific page.

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: one single program that works for differently named obje

Postby neptunhiker » Wed Oct 24, 2012 3:21 am

Thank you very much for your advice. It seemed to be the right hint. I have tried using the @wlookup command and here is my solution:

Code: Select all

' Define program variable %id=@wlookup("TTT*","series") ' Calculate return series series r_{%id}={%id}/{%id}(-1)-1
And it does work for the three different pages I have created, nice! BUT, unfortunately I have come up with another problem with the @wlookup command. If I want to estimate an equation using the following program (r_index contains returns that are closely realted to the returns of the TTT series)

Code: Select all

' Define program variable %id=@wlookup("TTT*","series") ' Calculate return series series r_{%id}={%id}/{%id}(-1)-1 ' Estimate equation equation ols_{%id}.ls r_{%id} c r_index
then I will not get any results in the equation output. It states "equation does not have estimates". If I substitute the last line in my code with:

Code: Select all

equation ols_TTT_8.ls r_{%id} c r_index
then everything works out fine and I get results. So, I wonder why does the equation not have any estimates, especially since creating series with for example

Code: Select all

series r_{%id}
works perfectly fine. Why does eViews not create an equation with the name given by the @wlookup command? I am hoping for help, again;) Thanks.

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

Re: one single program that works for differently named obje

Postby EViews Gareth » Wed Oct 24, 2012 6:49 am

We'd need to see the workfile

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: one single program that works for differently named obje

Postby neptunhiker » Wed Oct 24, 2012 7:20 am

This is the workfile, I am working with.
Attachments
ttt.wf1
(23.41 KiB) Downloaded 363 times

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

Re: one single program that works for differently named obje

Postby EViews Gareth » Wed Oct 24, 2012 7:52 am

Code: Select all

' Define program variable %id=@trim(@wlookup("TTT*","series"))

neptunhiker
Posts: 50
Joined: Sat Oct 20, 2012 7:30 am

Re: one single program that works for differently named obje

Postby neptunhiker » Wed Oct 24, 2012 1:43 pm

Hi Gareth,

thank you very much. It works that way. I just don't understand why. Could you tell me the reason? @trim deletes spaces on the left and right, but there are no spaces that need to be deleted, right?

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

Re: one single program that works for differently named obje

Postby EViews Gareth » Wed Oct 24, 2012 1:43 pm

There was a trailing space.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest