Page 1 of 1

Creating new variables using MOVCOR

Posted: Tue Mar 06, 2012 7:08 am
by jlsmith09012
I have 30 new variables that I need to create moving correlations between 1 of the variables and each of the other 29 variables. Is there an easy loop that will do this?

Re: Creating new variables using MOVCOR

Posted: Tue Mar 06, 2012 7:44 am
by trubador

Re: Creating new variables using MOVCOR

Posted: Tue Mar 06, 2012 8:27 am
by jlsmith09012
Thank you. I considered this solution, but my problem is that my variables have different names, such as A_ret, B_ret, C_ret, etc. I contemplated renaming the variables to X1 through X29, but I don't want to lose the descriptive data in the variable name. Is this possible?

Re: Creating new variables using MOVCOR

Posted: Tue Mar 06, 2012 10:25 am
by EViews Glenn
You can also loop over a list of names.

Re: Creating new variables using MOVCOR

Posted: Tue Mar 06, 2012 11:53 am
by jlsmith09012
I'm not sure if this is the most elegant solution, but here's what I have (and it works):

for !i=1 to portfolio1.@count
%constant = "A_ret"
%name = portfolio1.@seriesname(!i)
%newname = %name +"A"+ "_mc"
series {%newname} =@Movcor({%constant},{%name},10)
next

This allows me to loop through the variables, add the name of the variable and the designator MC, and generate the new series. It does provide me a moving correlation with variable A and A, but that's a small price to pay. I'm sure there is a way to delete variable A from portfolio1.@seriesname(!i), but I'm okay with my 98% solution. thanks to Trubador and Eviews Glenn (as well as an unnamed co-author) for the help.

Re: Creating new variables using MOVCOR

Posted: Thu Apr 03, 2014 6:32 am
by jsaldain
Could you explain what each command, from the loop, does?

Thanks!!