by moderator » Tue Jul 10, 2012 10:40 am
smpl 2000:2 2012:3
Dofor i = dlprod dlesi dlnord dlppi dlmetmins
set %s('di'+%l(i)) = %if(i.ge.0,1.0,0.0)
end dofor i
The problem is with this expression:
i.ge.0
As written, RATS is going to interpret "i" as referring to the integer-valued identification number associated with the current series, rather than the values stored in the series itself. Because series numbers are always bigger than 0, the expression is always true.
You need to do something to tell RATS to interpret i as a series, rather than as a series number. One way to do that is by adding lag notation (using lag zero since you want to refer to the current entry). For example:
set %s('di'+%l(i)) = %if(i{0}.ge.0,1.0,0.0)
Another way is to use a "type modifier", like this (note the parens around the "[series]i" expression:
set %s('di'+%l(i)) = %if( ([series]i).ge.0,1.0,0.0)
>Also any suggestions on how to sum (count) the 1's and 0's over each entry would be very helpful.
If you know the series will be defined for all entries, you could just use the %sum() function:
compute sum = %sum(%s('di'+%l(i)))
More generally, you can use SSTATS, which computes sums by default:
sstats / %s('di'+%l(i))>>sum1
For example:
dec vector sums(5)
compute n = 1
Dofor i = dlprod dlesi dlnord dlppi dlmetmins
set %s('di'+%l(i)) = %if(i{0}.ge.0,1.0,0.0)
sstats / %s('di'+%l(i))>>sums(n)
compute n = n+1
end dofor i
Regards,
Tom Maycock