Help in changing my codes from series to matrix
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
Help in changing my codes from series to matrix
Hi,
Can anyone help me out to optimise my code?
I have been using series, but I found out that as the number of elements in the list get higher, it take hours to run this code.
I would like to use matrix. Any help will be greatly appreciated.
My code that I would like to change from using series to using matrix.
string clist = " lists"  up to 40 elements
string curlist = "Currency"  up to 2 elements
string list_eq = "gsd"  up to 21 elements
string certain = "CN"  up to 34 currencies
string scenario = "BB00 CC00 DD00 EE00 FF00 B00 BB25 CC25 DD25 EE25 FF25 B25 BB50 CC50 DD50 EE50 FF50 B50 BB75 CC75 DD75 EE75 FF75 B75 BB_75 CC_75 DD_75 EE_75 FF_75 BB_50 CC_50 DD_50 EE_50 FF_50 BB_25 CC_25 DD_25 EE_25 FF_25 L00 NN00 PP00 QQ00 RR00 SS00 L25 NN25 PP25 QQ25 RR25 SS25 L50 NN50 PP50 QQ50 RR50 SS50 L75 NN75 PP75 QQ75 RR75 SS75 "
for %a {scenario}
for %c {clist}
for %u {curlist}
for %x {list_eq}
for %i {certain}
if @isobject("zsc_"+%c+"_"+%u+"_"+%x+"_"+%i) then
smpl 1970w1 @now
series signal_{%a}_{%c}_{%u}_{%x}_{%i} = 0
scalar obs= @obs(signal_{%a}_{%c}_{%u}_{%x}_{%i})
smpl if zsc_{%c}_{%u}_{%x}_{%i} <> na
for !j=2 to obs
' when z > 2, go 100% short
if zsc_{%c}_{%u}_{%x}_{%i}(!j)>=!a_200 then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_100
'when 1.75>Z<2 , stay in the original position or enter into a new 75% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_200 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_75 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_200 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_75
'when 1.50>Z<1.75 , stay in the original position or enter into a new 50% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_50) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_50) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_50
'when 1.4>Z<1.5 , stay in the original position or enter into a new 40% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_40) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_40) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_40
'when 1.3>Z<1.4 , stay in the original position or enter into a new 30% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_30
'when 1.25>Z<1.3 , stay in the original position or enter into a new 25% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_25) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_25) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_25
'when 1>Z<1.25 stay in the original position or enter into a new 25% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_00
'when 0.5>Z<1 and was in a short position, stay in the position otherwise zero position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= s0 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= s0 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 0.5>Z<0.5 , don't enter into any position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > s0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 1.00 >Z<0.5 and was in a long position, stay in that position, otherwise zero position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <=s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >  !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > 0 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 1.25>Z<1.00, stay in that position or enter a % long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_00
'when 1.30>Z<1.25, stay in that position or enter at 25 % long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_25 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_25 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_25
'when 1.30>Z<1.25, stay in that position or enter at 30% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_30
'when 1.50>Z<1.40, stay in that position or enter at 40% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_40 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_40 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_40
'when 1.75>Z<1.50, stay in that position or enter at 50% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_50 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_50 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_50
'when 2>Z<1.75, stay in that position or enter at 75% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_200 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_200 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_75
'when Z<2 and was not in a long position, enter into a long position
else if zsc_{%c}_{%u}_{%x}_{%i}(!j)<=!a_200 then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_100
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
next
endif
next
next
next
next
next
Can anyone help me out to optimise my code?
I have been using series, but I found out that as the number of elements in the list get higher, it take hours to run this code.
I would like to use matrix. Any help will be greatly appreciated.
My code that I would like to change from using series to using matrix.
string clist = " lists"  up to 40 elements
string curlist = "Currency"  up to 2 elements
string list_eq = "gsd"  up to 21 elements
string certain = "CN"  up to 34 currencies
string scenario = "BB00 CC00 DD00 EE00 FF00 B00 BB25 CC25 DD25 EE25 FF25 B25 BB50 CC50 DD50 EE50 FF50 B50 BB75 CC75 DD75 EE75 FF75 B75 BB_75 CC_75 DD_75 EE_75 FF_75 BB_50 CC_50 DD_50 EE_50 FF_50 BB_25 CC_25 DD_25 EE_25 FF_25 L00 NN00 PP00 QQ00 RR00 SS00 L25 NN25 PP25 QQ25 RR25 SS25 L50 NN50 PP50 QQ50 RR50 SS50 L75 NN75 PP75 QQ75 RR75 SS75 "
for %a {scenario}
for %c {clist}
for %u {curlist}
for %x {list_eq}
for %i {certain}
if @isobject("zsc_"+%c+"_"+%u+"_"+%x+"_"+%i) then
smpl 1970w1 @now
series signal_{%a}_{%c}_{%u}_{%x}_{%i} = 0
scalar obs= @obs(signal_{%a}_{%c}_{%u}_{%x}_{%i})
smpl if zsc_{%c}_{%u}_{%x}_{%i} <> na
for !j=2 to obs
' when z > 2, go 100% short
if zsc_{%c}_{%u}_{%x}_{%i}(!j)>=!a_200 then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_100
'when 1.75>Z<2 , stay in the original position or enter into a new 75% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_200 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_75 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_200 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_75
'when 1.50>Z<1.75 , stay in the original position or enter into a new 50% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_50) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_50) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_50
'when 1.4>Z<1.5 , stay in the original position or enter into a new 40% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_40) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_40) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_40
'when 1.3>Z<1.4 , stay in the original position or enter into a new 30% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_30
'when 1.25>Z<1.3 , stay in the original position or enter into a new 25% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_25) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >=!a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_25) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_25
'when 1>Z<1.25 stay in the original position or enter into a new 25% short position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_00
'when 0.5>Z<1 and was in a short position, stay in the position otherwise zero position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= s0 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) < 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >= s0 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) >= 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 0.5>Z<0.5 , don't enter into any position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) < s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > s0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 1.00 >Z<0.5 and was in a long position, stay in that position, otherwise zero position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <=s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) >  !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > 0 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= s0 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_100 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= 0) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = 0
'when 1.25>Z<1.00, stay in that position or enter a % long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_100 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_125 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_00) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_00
'when 1.30>Z<1.25, stay in that position or enter at 25 % long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_25 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_125 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_130 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_25 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_25
'when 1.30>Z<1.25, stay in that position or enter at 30% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_130 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_140 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_30) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_30
'when 1.50>Z<1.40, stay in that position or enter at 40% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_40 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_140 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_150 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_40 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_40
'when 1.75>Z<1.50, stay in that position or enter at 50% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_50 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_150 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_175 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_50 ) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_50
'when 2>Z<1.75, stay in that position or enter at 75% long position
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_200 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) > !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j1)
else if (zsc_{%c}_{%u}_{%x}_{%i}(!j) <= !a_175 and zsc_{%c}_{%u}_{%x}_{%i}(!j) > !a_200 and signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j  1) <= !e_75) then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_75
'when Z<2 and was not in a long position, enter into a long position
else if zsc_{%c}_{%u}_{%x}_{%i}(!j)<=!a_200 then signal_{%a}_{%c}_{%u}_{%x}_{%i}(!j) = !e_100
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
endif
next
endif
next
next
next
next
next

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
Hello,
I think the major performance hindrance in your code is its use of an explicit loop to go through every observation combined with the large list of conditionals that must be (at least) partially evaluated for each observation. Removing that loop by rewriting your logic using series generation expressions ("genr") may speed up execution a significant amount. This is same performance improving idea behind using vector or matrix operations instead of explicit loops, but we don't have to use vectors or matrices, we can be clever about how the series are generated. Basically, we want to create the bulk of the series in a single line:
The trick is coming up with the righthand side of that assignment statement. Note that the code ideas below will make your program harder to read, which is often the price of improved performance.
Your logic breaks things up into 17 different cases based on the value in zsc_{%c}_{%u}_{%x}_{%i}. In three of those cases you directly assign the signal value, while in the rest you compare the previous value of the signal to a threshold. There is a lot of redundancy there that you can exploit to rewrite your logic. First, suppose we create a helper series that stores which of those cases each observation is in. Here, I'll create a case number series ("casenum") that will store the a number 1 through 17 (1 being the first case, zsc > 2, and 17 being the last case, zsc < 2) using a genr expression rather than if statements.
I've omitted most of the nested @recode statements, but you can see there's a pattern to completing the rest of them. The completed line would be quite long, but it will be calculated much more quickly that using if statements within an observation loop. With just this new helper series we could write part of the signal genr expression:
The rightmost part is incomplete, but the three cases that don't depend on the previous value of signal are done. To finish this off, we need to handle the 14 cases that compare the signal to a threshold value. You've stored those threshold values separate variables, e.g., !e_100, but they'll be much easier to access if we can use an index number, such as the case number, to determine what the appropriate threshold value is. Next, I'll create some temporary auxiliary data ("tmp" and "tmp2") plus another helper series ("threshold") that holds the threshold value for each observation.
Three of the cases don't use a threshold value, so I've used NA as a reminder in those positions. I've also used a vector and converted it to a series only because it's easier to initialize a vector with a list of numbers. The clever bit is tmp2(casenum  @obsid), which uses each observation's case number to look up that observation's threshold value.
Building a expression that compares the signal value to the threshold and assigns a value:
Finally, combining everything we've done so far:
The above code is incomplete and likely needs further debugging, but it does outline how your ~40 lines of logic could be replaced with a few genr expressions.
I think the major performance hindrance in your code is its use of an explicit loop to go through every observation combined with the large list of conditionals that must be (at least) partially evaluated for each observation. Removing that loop by rewriting your logic using series generation expressions ("genr") may speed up execution a significant amount. This is same performance improving idea behind using vector or matrix operations instead of explicit loops, but we don't have to use vectors or matrices, we can be clever about how the series are generated. Basically, we want to create the bulk of the series in a single line:
Code: Select all
signal_{%a}_{%c}_{%u}_{%x}_{%i} = ...
The trick is coming up with the righthand side of that assignment statement. Note that the code ideas below will make your program harder to read, which is often the price of improved performance.
Your logic breaks things up into 17 different cases based on the value in zsc_{%c}_{%u}_{%x}_{%i}. In three of those cases you directly assign the signal value, while in the rest you compare the previous value of the signal to a threshold. There is a lot of redundancy there that you can exploit to rewrite your logic. First, suppose we create a helper series that stores which of those cases each observation is in. Here, I'll create a case number series ("casenum") that will store the a number 1 through 17 (1 being the first case, zsc > 2, and 17 being the last case, zsc < 2) using a genr expression rather than if statements.
Code: Select all
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i 'Create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75, 2, @recode({%zsc} >= 1.5, 3, @recode({%zsc} >= 1.4, 4, ...))))
I've omitted most of the nested @recode statements, but you can see there's a pattern to completing the rest of them. The completed line would be quite long, but it will be calculated much more quickly that using if statements within an observation loop. With just this new helper series we could write part of the signal genr expression:
Code: Select all
signal_{%a}_{%c}_{%u}_{%x}_{%i} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum = 17, !e_100, )))
The rightmost part is incomplete, but the three cases that don't depend on the previous value of signal are done. To finish this off, we need to handle the 14 cases that compare the signal to a threshold value. You've stored those threshold values separate variables, e.g., !e_100, but they'll be much easier to access if we can use an index number, such as the case number, to determine what the appropriate threshold value is. Next, I'll create some temporary auxiliary data ("tmp" and "tmp2") plus another helper series ("threshold") that holds the threshold value for each observation.
Code: Select all
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
mtos(tmp, tmp2)
genr threshold = tmp2(casenum  @obsid)
Three of the cases don't use a threshold value, so I've used NA as a reminder in those positions. I've also used a vector and converted it to a series only because it's easier to initialize a vector with a list of numbers. The clever bit is tmp2(casenum  @obsid), which uses each observation's case number to look up that observation's threshold value.
Building a expression that compares the signal value to the threshold and assigns a value:
Code: Select all
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i 'Shorter name for signal
... = @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold)
Finally, combining everything we've done so far:
Code: Select all
(outside the loops)
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
mtos(tmp, tmp2)
(inside the loops, replacing the innermost loop !j)
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i ' create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75, 2, @recode({%zsc} >= 1.5, 3, @recode({%zsc} >= 1.4, 4, ...))))
genr threshold = tmp2(casenum  @obsid)
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i ' Shorter name for signal
{%sig} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum = 17, !e_100, @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold))))
The above code is incomplete and likely needs further debugging, but it does outline how your ~40 lines of logic could be replaced with a few genr expressions.
Last edited by EViews Matt on Wed Mar 21, 2018 10:53 am, edited 1 time in total.
Re: Help in changing my codes from series to matrix
Hi Matt,
Thanks you for your replied. It will definately reduced the processing time.
I will further need your help.
For example
Case 1 ' when z > 2, go 100% short
Case 2 'when 1.75>Z<2 , stay in the original position or enter into a new 75% short position :
Therefore ,
genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75, 2, 0))
Is it ok, like this or should have put something like genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75 and {%zsc} < 1.75, 2, 0)) ?
Thanks for your help.
Sudesh
Thanks you for your replied. It will definately reduced the processing time.
I will further need your help.
For example
Case 1 ' when z > 2, go 100% short
Case 2 'when 1.75>Z<2 , stay in the original position or enter into a new 75% short position :
Therefore ,
genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75, 2, 0))
Is it ok, like this or should have put something like genr casenum = @recode({%zsc} > 2, 1, @recode({%zsc} >= 1.75 and {%zsc} < 1.75, 2, 0)) ?
Thanks for your help.
Sudesh
Re: Help in changing my codes from series to matrix
First step done:
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 9,@recode({%zsc} <= 1.75, 10,@recode({%zsc} <= 1.50, 11,@recode({%zsc} <= 1.40, 12,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 14,@recode({%zsc} <= 1, 15,@recode({%zsc} <= 0.5, 16,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 17,0)))))))))))))))))
it's working....
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 9,@recode({%zsc} <= 1.75, 10,@recode({%zsc} <= 1.50, 11,@recode({%zsc} <= 1.40, 12,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 14,@recode({%zsc} <= 1, 15,@recode({%zsc} <= 0.5, 16,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 17,0)))))))))))))))))
it's working....

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
Very good. You've numbered your cases slightly differently than I outlined, but as long as you compensate for those differences in the remaining code your program should work correctly.
Re: Help in changing my codes from series to matrix
Hi Matt,
Step 2: I'm unable to create the threshold.
Is there something wrong in what I'm doing?
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
mtos(tmp, tmp2)
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i 'Create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 17,@recode({%zsc} <= 1.75, 16,@recode({%zsc} <= 1.50, 15,@recode({%zsc} <= 1.40, 14,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 12,@recode({%zsc} <= 1, 11,@recode({%zsc} <= 0.5, 10,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 9,0)))))))))))))))))
genr threshold = tmp2(casenum  @obsid)
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i ' Shorter name for signal
{%sig} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum = 17, !e_100, @recode(@recode(casename < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold))))
Thanks
Step 2: I'm unable to create the threshold.
Is there something wrong in what I'm doing?
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
mtos(tmp, tmp2)
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i 'Create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 17,@recode({%zsc} <= 1.75, 16,@recode({%zsc} <= 1.50, 15,@recode({%zsc} <= 1.40, 14,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 12,@recode({%zsc} <= 1, 11,@recode({%zsc} <= 0.5, 10,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 9,0)))))))))))))))))
genr threshold = tmp2(casenum  @obsid)
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i ' Shorter name for signal
{%sig} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum = 17, !e_100, @recode(@recode(casename < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold))))
Thanks

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
I don't see anything obviously wrong, what happens when you execute that code?
Re: Help in changing my codes from series to matrix
Hi Matt,
I have enclosed the result of tmp, tmp2, casenum and threshold.
As you can see there is no data in threshold.
Did I miss a step?
I really appreciate your help as I have to optimise this code for today.
Thanks alots.
I have enclosed the result of tmp, tmp2, casenum and threshold.
As you can see there is no data in threshold.
Did I miss a step?
I really appreciate your help as I have to optimise this code for today.
Thanks alots.
 Attachments

 Optimisation of signal.xlsx
 (94.11 KiB) Downloaded 31 times

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
Ah, the workfile sample is causing the contents of tmp to be copied to the wrong observations of tmp2, which breaks the calculation of threshold. Thankfully, we can have mtos() ingore the current workfile sample. Try replacing the mtos() line with the following:
Code: Select all
sample all @all
mtos(tmp, tmp2, all)
Re: Help in changing my codes from series to matrix
Hi Matt,
In step 3, I have the following erreur message now.
signal_B50_rel_CAD_MOD10_CN is not defined or is an illegal
command in "{%SIG} = @RECODE(CASENUM = 1, 1, 0)".
My code now
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
smpl all @all
mtos(tmp, tmp2,all)
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i 'Create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 17,@recode({%zsc} <= 1.75, 16,@recode({%zsc} <= 1.50, 15,@recode({%zsc} <= 1.40, 14,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 12,@recode({%zsc} <= 1, 11,@recode({%zsc} <= 0.5, 10,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 9,0)))))))))))))))))
genr threshold = tmp2(casenum  @obsid)
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i ' Shorter name for signal
{%sig} = @recode(casenum = 1, !e_100, 0)
I have enclosed the data of tmp, tmp2, casenum, threshold and the zsc.
Thanks.
Sudesh
In step 3, I have the following erreur message now.
signal_B50_rel_CAD_MOD10_CN is not defined or is an illegal
command in "{%SIG} = @RECODE(CASENUM = 1, 1, 0)".
My code now
vector(17) tmp
tmp.fill NA, !e_75, !e_50, !e_40, !e_30, !e_25, !e_00, 0, NA, 0, !e_00, !e_25, !e_30, !e_40, !e_50, !e_75, NA
smpl all @all
mtos(tmp, tmp2,all)
%zsc = "zsc_" + %c + "_" + %u + "_" + %x + "_" + %i 'Create a shorter name for the series
genr casenum = @recode({%zsc} > 2, 1,@recode({%zsc} >= 1.75, 2,@recode({%zsc} >= 1.50, 3,@recode({%zsc} >= 1.4, 4,@recode({%zsc} >= 1.30, 5,@recode({%zsc} >= 1.25, 6,@recode({%zsc} >= 1, 7,@recode({%zsc} >= 0.5, 8,@recode({%zsc} < 2, 17,@recode({%zsc} <= 1.75, 16,@recode({%zsc} <= 1.50, 15,@recode({%zsc} <= 1.40, 14,@recode({%zsc} <= 1.30, 13,@recode({%zsc} <= 1.25, 12,@recode({%zsc} <= 1, 11,@recode({%zsc} <= 0.5, 10,@recode({%zsc} > 0.5 and {%zsc} < 0.5, 9,0)))))))))))))))))
genr threshold = tmp2(casenum  @obsid)
%sig = "signal_" + %a + "_" + %c + "_" + %u + "_" + %x + "_" + %i ' Shorter name for signal
{%sig} = @recode(casenum = 1, !e_100, 0)
I have enclosed the data of tmp, tmp2, casenum, threshold and the zsc.
Thanks.
Sudesh
 Attachments

 Optimisation of signal.xlsx
 (169.78 KiB) Downloaded 31 times
Re: Help in changing my codes from series to matrix
I don't understand why signal_B50_rel_CAD_MOD10_CN is not defined as B50 as be defined as scenario.
signal_B50_rel_CAD_MOD10_CN is not defined or is an illegal
command in "{%SIG} = @RECODE(CASENUM = 1, 1,
@RECODE(CASENUM = 9, 0, @RECODE(CASENUM = 17, 1,
@RECODE(@RECODE(CASENAME < 9, SIGNAL_B50_REL_CAD_
MOD10_CN < THRESHOLD, SIGNAL_B50_REL_CAD_MOD10_CN
> THRESHOLD) , SIGNAL_B50_REL_CAD_MOD10_CN(1),
THRESHOLD))))".
string scenario = "B50"
string clist = "rel"
%curlist = "CAD"
string list_eq = "MOD10"
string certain = "CN"
for %a {scenario}
for %c {clist}
for %u {curlist}
for %x {list_eq}
for %i {certain}
signal_B50_rel_CAD_MOD10_CN is not defined or is an illegal
command in "{%SIG} = @RECODE(CASENUM = 1, 1,
@RECODE(CASENUM = 9, 0, @RECODE(CASENUM = 17, 1,
@RECODE(@RECODE(CASENAME < 9, SIGNAL_B50_REL_CAD_
MOD10_CN < THRESHOLD, SIGNAL_B50_REL_CAD_MOD10_CN
> THRESHOLD) , SIGNAL_B50_REL_CAD_MOD10_CN(1),
THRESHOLD))))".
string scenario = "B50"
string clist = "rel"
%curlist = "CAD"
string list_eq = "MOD10"
string certain = "CN"
for %a {scenario}
for %c {clist}
for %u {curlist}
for %x {list_eq}
for %i {certain}

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
There is an error where the series name "casename" is used instead of "casenum", I mistyped it my original response to you.

 EViews Developer
 Posts: 328
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Help in changing my codes from series to matrix
Also, did you remove the "series signal_{%a}_{%c}_{%u}_{%x}_{%i} = 0" line from your program? That would account for the error you're experiencing.
Re: Help in changing my codes from series to matrix
Hi Matt,
I'm trying to understand the code:
vector (17) : creating a vector with 17 rows
tmp.fill is filing tmp with the 17 values,
smpl all @all,
mtos(tmp,tmp2, all) is converting the vector into a series and the range have been defined by %zsc
genr casenum is creating a series with the 17 values based on the formula : @recode({%zsc} > 2, 1, etc))))))
genr threshold = tmp2(casenum  @obsid) is subtracting the value of tmp2 from casenum and assigned it back to tmp2
Does I have the right understanding?
Thanks.
Sudesh
I'm trying to understand the code:
vector (17) : creating a vector with 17 rows
tmp.fill is filing tmp with the 17 values,
smpl all @all,
mtos(tmp,tmp2, all) is converting the vector into a series and the range have been defined by %zsc
genr casenum is creating a series with the 17 values based on the formula : @recode({%zsc} > 2, 1, etc))))))
genr threshold = tmp2(casenum  @obsid) is subtracting the value of tmp2 from casenum and assigned it back to tmp2
Does I have the right understanding?
Thanks.
Sudesh
Re: Help in changing my codes from series to matrix
Hi Matt,
I'm really sorry to bother you that much as I don't have any alternative.
{%sig} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum= 17, !e_100, @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold))))
My understanding
casenum = 1, !e_100 is for zsc >= 2
casenum = 9, 0, is for 0.5< zsc < 0.5
casenum = 17, is for zsc <= 2
for casenum < 9, therefore between 1 and 8 , @recode(casenum < 9, {%sig} < threshold, {%sig} > threshold)
Therefore for casenum between 10 and 16, @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold)
Do you I have the right understanding...
Thanks.
I'm really sorry to bother you that much as I don't have any alternative.
{%sig} = @recode(casenum = 1, !e_100, @recode(casenum = 9, 0, @recode(casenum= 17, !e_100, @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold))))
My understanding
casenum = 1, !e_100 is for zsc >= 2
casenum = 9, 0, is for 0.5< zsc < 0.5
casenum = 17, is for zsc <= 2
for casenum < 9, therefore between 1 and 8 , @recode(casenum < 9, {%sig} < threshold, {%sig} > threshold)
Therefore for casenum between 10 and 16, @recode(@recode(casenum < 9, {%sig} < threshold, {%sig} > threshold) , {%sig}(1), threshold)
Do you I have the right understanding...
Thanks.
Who is online
Users browsing this forum: No registered users and 12 guests