## 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

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

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 upperdofor 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 upperend dofor lower`
TomDoan

Posts: 6629
Joined: Wed Nov 01, 2006 5:36 pm

### Re: choosing k from real values

Dear Tom Doan,
When I changed the code and run the program, I got the following message:
*
Code: Select all
`calendar(q) 1987:01allocate 2015:04open data cad.ratdata(format=rat,org=columns) / cad*set y = cad*graph# y*tableSeries             Obs       Mean        Std Error      Minimum       MaximumCAD                  116 -2.5887029528  3.2252496038 -9.8292520000  4.8927893830Y                    116 -2.5887029528  3.2252496038 -9.8292520000  4.8927893830*dec vector[series] mean(26)*com lmax = 36set trend = tdec vector[integer] reglistcompute 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 kcom 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

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: 6629
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