choosing k from real values

This is the development of a 2nd Edition of Enders' RATS Programming Manual.

Moderator: TomDoan

choosing k from real values

Postby vtsa » Mon May 09, 2016 3:25 pm

Dear Tom Doan,
I have a question about how to choose k from the real values. I have a rpf in which the code is written as follows:

dec vector[series] mean(26)
com lmax = 36
set trend = t
dec vector[integer] reglist
compute reglist = || constant| trend ||
dec vector[series] sine(10) dsine(10)
dec vector[series] cosine(10) dcosine(10)
com header$ = || 'Series' | 'k' | 'Tau' | 'F-value' | 'DF' | 'Lags'| 'T'||
report(action=define,hlab=header$)
com i = 23
sta(noprint) [series]i ; com cap_T = %nobs , start = 1961:2+612-%nobs
do k = 1,3
set sine(k) = sin(2.*%pi*k*t/%nobs) ; dif sine(k) / dsine(k)
set cosine(k) = cos(2.*%pi*k*t/%nobs) ; dif cosine(k) / dcosine(k)
end do k
...
I want to choose k from the range [0.1,0.2,0.3,...,2.8,2.9,3.0]. But do loop selects k from integer values. How can I change the code in order to select k from the real values such as [0.1,0.2,0.3,...,2.8,2.9,3.0].
I willl appreciate your response,
Kind Regards,
vtsa
 
Posts: 14
Joined: Thu Oct 10, 2013 7:25 am

Re: choosing k from real values

Postby TomDoan » Mon May 09, 2016 3:44 pm

DOFOR with %SEQA looks like it is what you need. For instance, one of the examples on that page uses a doubly nested grid using this:

Code: Select all
dec real lower upper
dofor lower = %seqa(-.2,.1,5)
  dofor upper = %seqa(1.6,.1,5)
     sweep(group=(thresh>=lower)+(thresh>upper))
     # spread
     # constant spread{1 2}
     compute rss=%scalar(%sigma)
     if rss<rssbest
        compute lowerbest=lower,upperbest=upper,rssbest=rss
  end dofor upper
end dofor lower
TomDoan
 
Posts: 6492
Joined: Wed Nov 01, 2006 5:36 pm

Re: choosing k from real values

Postby vtsa » Fri May 13, 2016 6:43 am

Dear Tom Doan,
When I changed the code and run the program, I got the following message:
*
Code: Select all
calendar(q) 1987:01
allocate 2015:04
open data cad.rat
data(format=rat,org=columns) / cad
*
set y = cad
*
graph
# y
*
table
Series             Obs       Mean        Std Error      Minimum       Maximum
CAD                  116 -2.5887029528  3.2252496038 -9.8292520000  4.8927893830
Y                    116 -2.5887029528  3.2252496038 -9.8292520000  4.8927893830

*dec vector[series] mean(26)
*com lmax = 36
set trend = t
dec vector[integer] reglist
compute reglist = || constant| trend ||
dec vector[series] sine(10) dsine(10)
dec vector[series] cosine(10) dcosine(10)
com header$ = || 'Series' | 'k' | 'Tau' | 'F-value' | 'DF'  | 'Lags'| 'T'||

report(action=define,hlab=header$)
dec real k
com i = 2
   sta(noprint) [series]i   ; com cap_T = %nobs  , start = 1987:2+116-%nobs
   dofor k = %seqa(0.1,.1,50)
      set sine(k)   = sin(2.*%pi*k*t/%nobs)  ; dif sine(k) / dsine(k)
      set cosine(k) = cos(2.*%pi*k*t/%nobs)  ; dif cosine(k) / dcosine(k)
   end dofor k

Subscripting Error. Had Array Reference with (). Needed (INTEGER)
## SX27. Illegal Combination of Data Types for Operation
>>>> set sine(k) <<<<

I couldn’t solve this problem. Could You advise me how to change the code to run the program.
I will appreciate your response,
Thank You in advance.
vtsa
 
Posts: 14
Joined: Thu Oct 10, 2013 7:25 am

Re: choosing k from real values

Postby TomDoan » Fri May 13, 2016 7:04 am

This will adapt the number of elements of the VECT[SERIES] to the number of elements in the sequence.

Code: Select all
compute kf=%seqa(0.1,.1,50)
dec vect[series] sine(%sizef(kf)) dsine(%size(kf)) cosine(%size(kf)) dcosine(%size(kf))
do k = 1,%size(kf)
   set sine(k) = sin(2.*%pi*kf(k)*t/%nobs) ; dif sine(k) / dsine(k)
   set cosine(k) = cos(2.*%pi*kf(k)*t/%nobs) ; dif cosine(k) / dcosine(k)
end do k
TomDoan
 
Posts: 6492
Joined: Wed Nov 01, 2006 5:36 pm


Return to RATS Programming Manual

Who is online

Users browsing this forum: No registered users and 1 guest