looping overlaying graph

For questions and discussion related to graphs, reports, and other output, including issues related to presenting or publishing results.
Anders
Posts: 2
Joined: Mon Apr 16, 2018 3:58 pm

looping overlaying graph

Unread post by Anders »

Hi
I'm new to RATS so my question is probably pretty basic. Nonetheless I would be really grateful of any help.

I want to do 4 graphs of overlapping stock index and return.
In the following code I get 16 graphs. I know I can pick out the right ones, but learning how to do the right coding would be really great.

dofor i = USA China Denmark Romania
dofor y = RETURNUSA RETURNchi RETURNden RETURNrom
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# y
# i
end dofor i
end dofor y

Hope you can help
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: looping overlaying graph

Unread post by TomDoan »

If it's just 4, you might want to just to 4 graph instructions:

GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# usa
# returnusa
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# china
# returnchi
etc.

Because the return series don't quite match the root names for the index (it would be a bit simpler if you did "returnchina" to match with "china" for instance), you would have to do an extra step to match the two up in order to use a loop. For instance,

Code: Select all

dec hash[string] rname
compute rname("usa")="returnusa"
compute rname("china")="returnchi"
compute rname("denmark")="returnden"
compute rname("romania")="returnrom"
*
dofor i = USA China Denmark Romania
   GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
   # i
   # %s(rname(%l(i))
end dofor
Anders
Posts: 2
Joined: Mon Apr 16, 2018 3:58 pm

Re: looping overlaying graph

Unread post by Anders »

Thank you very much! Worked perfectly
Post Reply