Page 1 of 1

Store correlation matrix output

Posted: Tue May 31, 2016 1:40 pm
by cyang40
Dear Tom,

I would like to store the correlation between two variables, but my following command does not do the job. Could you please direct me as to what is missing in my code? Thank you.
cmom(corr,print)
# gdp_detrend govt_detrend
compute mycorrs = %cmom(gdp_detrend,govt_detrend)

Re: Store correlation matrix output

Posted: Tue May 31, 2016 1:50 pm
by TomDoan
You want %cmom(1,2)---the elements of the array are accessed by position, not by the variable.

Re: Store correlation matrix output

Posted: Tue May 31, 2016 2:15 pm
by cyang40
Hi Tom,

I fixed the code but the output doesn't seem to exist.
cmom(corr,print)
# gdp_detrend govt_detrend
compute mycorrs = %cmom(1,2)

print / mycorrs
## SX22. Expected Type SERIES[REAL], Got REAL Instead
>>>>print / mycorrs<<<<

Re: Store correlation matrix output

Posted: Tue May 31, 2016 2:17 pm
by TomDoan
MYCORRS is a number, not a series. Use DISPLAY, not PRINT.

Re: Store correlation matrix output

Posted: Tue May 31, 2016 2:40 pm
by cyang40
Hi Tom,

Thank you for the advise. Since I have a panel data, is there a way to store the output by country? I have attempted the following procedure, and I received an error message from the system. Perhaps, I am doing this incorrectly.
do i=1,61
cmom(corr,print) i//1970:1 i//2013:1
# gdp_detrend govt_detrend
compute mycorrs(i) = %cmom(1,2)
display mycorrs(i)
end do i
## SX11. Identifier MYCORRS is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>> compute mycorrs(<<<<

Re: Store correlation matrix output

Posted: Tue May 31, 2016 3:19 pm
by TomDoan
add

clear mycorrs

before the loop so mycorrs is recognized as a series.

Re: Store correlation matrix output

Posted: Tue May 31, 2016 3:51 pm
by cyang40
This will create a vector with 1//1970:1 2//1986:1 instead of a matrix with 1//1970:1 61//2013:1. Ideally, I would like to have the value of correlation assigned to each country over time. Is there a way to modify this setting? Thank you.

Re: Store correlation matrix output

Posted: Tue May 31, 2016 4:03 pm
by TomDoan
Instead of compute do

set mycorrs i//1970:1 i//2013:1 = %cmom(1,2)

Re: Store correlation matrix output

Posted: Tue May 31, 2016 4:13 pm
by cyang40
Great. Thank you very much, Tom.