Hi
I have a time series for which the variable has missing values. I would like to replace the missing values by a linear model derived from the closest available values in time.
What would be the best way?
And if the script could do that to all the columns of my table (except the time), that would be even better
Thanks
Example
What I have
t | Output |
---|---|
0 | 10 |
1 | . |
2 | . |
4 | 30 |
10 | . |
20 | 10 |
What I want:
t | Output |
---|---|
0 | 10 |
1 | 15 |
2 | 20 |
4 | 30 |
10 | 22.5 |
20 | 10 |
If you want to make the value in the Interpreted column to be equal to 0 whenever the :Time value is 0, a change to the code something like below would work
For( i = 1, i <= N Rows( values ), i++,
If( :Time[i] == 0, values[i]=0); // **************
If( Is Missing( values[i] ),
counter++,
If( counter > 0,
For( k = 1, k <= counter, k++,
base = values[i - counter - 1];
incr = Abs( (base - values[i]) / (counter + 1) );
If( base < values[i],
values[(i - counter - 1) + k] = base + k * incr,
values[(i - counter - 1) + k] = base - k * incr
);
);
counter = 0;
)
)
);
Jim,
Thanks so much. this works really well now. can you explain to me what the last "values[Row()];" does