Simple loop to eliminate outliers
Posted: Wed Jan 02, 2008 11:06 am
I am trying to eliminate outliers in a factor analysis to replicate a procedure used by Stock and Watson.
I get the upper value for all observations--I suspect that it is using the number (rather that the period value) of the series in the logical statement.
faulty code:
cal 1983 1 12
all 0 2007:9
open data gavin-kliesen_data.rat
data(org=col,for=rat) /
close data
smpl 1983:1 1983:12
Print / d1 d2 d3 d4
smpl 1983:1 2007:9
dofor variable = 1 to 4
stat(fractiles,noprint) variable /
compute up_val = %median + 6*(%fract75-%median)
compute low_val = %median - 6*(%median-%fract25)
do i = 1983:1,2007:9,1
smpl i i
if variable > up_val
{
set variable = up_val
}
else if variable < low_val
{
set variable = low_val
}
else
{
set variable = variable
}
end do
smpl 1983:1 2007:9
end dofor x
smpl 1983:1 1983:12
Print / d1 d2 d3 d4
Any suggestions would be appreciated.
Bill
I get the upper value for all observations--I suspect that it is using the number (rather that the period value) of the series in the logical statement.
faulty code:
cal 1983 1 12
all 0 2007:9
open data gavin-kliesen_data.rat
data(org=col,for=rat) /
close data
smpl 1983:1 1983:12
Print / d1 d2 d3 d4
smpl 1983:1 2007:9
dofor variable = 1 to 4
stat(fractiles,noprint) variable /
compute up_val = %median + 6*(%fract75-%median)
compute low_val = %median - 6*(%median-%fract25)
do i = 1983:1,2007:9,1
smpl i i
if variable > up_val
{
set variable = up_val
}
else if variable < low_val
{
set variable = low_val
}
else
{
set variable = variable
}
end do
smpl 1983:1 2007:9
end dofor x
smpl 1983:1 1983:12
Print / d1 d2 d3 d4
Any suggestions would be appreciated.
Bill