Page 1 of 1

Dofor function for Q tests

Posted: Sat Oct 27, 2012 7:23 am
by lsal0106
Hi everyone,

I was wondering if someone could assist me with the code to develop a dofor function in order to find the Q stats on the series in the file attached? I want to find the Q stats on each of the 19 series in the file, but I am lost as to how to do it. Apologies if this question seems ridiculously simple.

Thanks in advance.

Re: Dofor function for Q tests

Posted: Sat Oct 27, 2012 9:32 am
by TomDoan
This would do it:

cal(d) 2007:12:14
data(format=xls,org=columns) 2007:12:14 2012:3:30 c1 c2 ... c17
dofor s = c1 to c17
corr(noprint,qstat,number=numberofcorrelations) s
disp %l(s) %qstat
end dofor s

Re: Dofor function for Q tests

Posted: Sat Oct 27, 2012 7:09 pm
by lsal0106
As we say in Australia, you are a legend mate! Thank You!

Re: Dofor function for Q tests

Posted: Sat Oct 27, 2012 7:44 pm
by lsal0106
Also I was just wondering, is there a way of finding the second moment Q-stat also? Would I have to use two doloop functions in order to find this? I have the following code supplementary to the above at the moment

dofor s = C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19
set s2 = (s**2)
corr(noprint,qstat,number=20) s2
disp 'Second moment Q(20) = ' %l(s2) %qstat 'p-value = ' #.######### %signif
end dofor

But the output prints the following;

The Error Occurred At Location 325, Line 3 of loop/block
## REG7. Variance is Zero
## REG7. Variance is Zero
The Error Occurred At Location 325, Line 3 of loop/block

Re: Dofor function for Q tests

Posted: Sun Oct 28, 2012 9:10 am
by TomDoan
lsal0106 wrote:Also I was just wondering, is there a way of finding the second moment Q-stat also? Would I have to use two doloop functions in order to find this? I have the following code supplementary to the above at the moment

dofor s = C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19
set s2 = (s**2)
corr(noprint,qstat,number=20) s2
disp 'Second moment Q(20) = ' %l(s2) %qstat 'p-value = ' #.######### %signif
end dofor

But the output prints the following;

The Error Occurred At Location 325, Line 3 of loop/block
## REG7. Variance is Zero
## REG7. Variance is Zero
The Error Occurred At Location 325, Line 3 of loop/block
You need to do

set s2 = s{0}**2

to get S treated as a reference to a series in the SET.