I am using EViews 10 (Univ. ed.) and seek to implement a specific procedure for outlier treatment. In particular, I want to define outliers as observations with deviations from the median exceeding six times the interquartile range (in absolute terms). These outliers should then be replaced by the median value of the five preceding observations.
So far, my code looks like this:
Code: Select all
'Create a blank output table to store median and interquartile range of all series in the group "xt_all"
table (3, xt_all.@count+1) Xt_stat
setcell(Xt_stat, 1, 1, "Statistic / Series", "l")
setcell(Xt_stat, 2, 1, "Median", "l")
setcell(Xt_stat, 3, 1, "Interquartile range", "l")
'Loop through all series in the group "xt_all"
for !i=1 to xt_all.@count
'Enforce the correct series names
%name = xt_all.@seriesname(!i)
'Obtain and store median and interquartile range for each series in "Xt_all"
Xt_stat(1,1+!i)=%name
Xt_stat(2, 1+!i)= @median({%name})
Xt_stat(3, 1+!i)= @quantile({%name}, 0.75) - @quantile({%name}, 0.25)
next
'Loop through the number of observations of the current series
for !i=1 to xt_all.@count and !j=1 to @obssmpl
'Enforce the correct series name
%name = xt_all.@seriesname(!i)
'Consider each observation one by one
!observation = !j
'Create a temporary vector of the five observations preceding the current observation
vector temp = @fill(@elem({%name}, {!observation}-1), @elem({%name}, {!observation}-2), @elem({%name}, {!observation}-3), @elem({%name}, {!observation}-4), @elem({%name}, {!observation}-5))
'Define rule for identifying outliers
if @abs(@elem({%name}, {!observation})) - @abs(Xt_stat(2, 1+!i)) > 6*@abs(Xt_stat(3, 1+!i)) then
'Replace outliers by the median of the previous five observations
@elem({%name}, {!observation}) = @median(temp)
'Delete vector "temp" before starting next iteration
delete temp
next
Do you have any advice on how to proceed? Your help will be much appreciated!
