Store correlation matrix output

For questions and discussion related to reading in and working with data.
cyang40
Posts: 9
Joined: Tue Apr 26, 2016 3:30 pm

Store correlation matrix output

Unread post 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)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Store correlation matrix output

Unread post by TomDoan »

You want %cmom(1,2)---the elements of the array are accessed by position, not by the variable.
cyang40
Posts: 9
Joined: Tue Apr 26, 2016 3:30 pm

Re: Store correlation matrix output

Unread post 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<<<<
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Store correlation matrix output

Unread post by TomDoan »

MYCORRS is a number, not a series. Use DISPLAY, not PRINT.
cyang40
Posts: 9
Joined: Tue Apr 26, 2016 3:30 pm

Re: Store correlation matrix output

Unread post 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(<<<<
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Store correlation matrix output

Unread post by TomDoan »

add

clear mycorrs

before the loop so mycorrs is recognized as a series.
cyang40
Posts: 9
Joined: Tue Apr 26, 2016 3:30 pm

Re: Store correlation matrix output

Unread post 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.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Store correlation matrix output

Unread post by TomDoan »

Instead of compute do

set mycorrs i//1970:1 i//2013:1 = %cmom(1,2)
cyang40
Posts: 9
Joined: Tue Apr 26, 2016 3:30 pm

Re: Store correlation matrix output

Unread post by cyang40 »

Great. Thank you very much, Tom.
Post Reply