I need to produce the out-of-sample forecast using AUTOREG by hand (meaning that I don't need to update the coefficients every time I change my data).
Assume I have this data:
DATA test;
FORMAT Date MMDDYY10.;
INFORMAT Date MMDDYY10.;
INPUT Date x z;
DATALINES;
1/31/2019 1 0
2/28/2019 2 1
3/31/2019 3 2
4/30/2019 4 3
5/31/2019 5 .
6/30/2019 6 .
7/31/2019 7 .
RUN;
Also, suppose the estimated coefficients are: beta = 0.9996 and alpha = -1 .
I need to create (by hand) a new variable, named predicted (which should be the same as yhat), that is calculated as follows:
data p_test;
set test;
beta = 0.9996;
alpha = -1;
predicted = beta*x - alpha*(lag(z) - beta*lag(x));
run;
But I cannot do it for the last two dates. The thing is that if lag(z) is missing, I should tell SAS to use lag(predicted). How to do it?
The predicted values should be equal to yhat as shown below:
yhat Date x z beta alpha predicted
0.9995547997 01/31/2019 1 0 0.9996 -1 .
0.9995547998 02/28/2019 2 1 0.9996 -1 0.9996
1.9995547998 03/31/2019 3 2 0.9996 -1 1.9996
2.9995547998 04/30/2019 4 3 0.9996 -1 2.9996
3.9995547998 05/31/2019 5 . 0.9996 -1 3.9996
4.9991095996 06/30/2019 6 . 0.9996 -1 .
5.9986643994 07/31/2019 7 . 0.9996 -1 .
Hello,
Something like this ?
data test;
format Date MMDDYY10.;
informat Date MMDDYY10.;
input Date x z;
datalines;
1/31/2019 1 0
2/28/2019 2 1
3/31/2019 3 2
4/30/2019 4 3
5/31/2019 5 .
6/30/2019 6 .
7/31/2019 7 .
;
run;
data p_test;
set test;
retain error 0;
beta = 0.9996;
alpha = -1;
predicted = beta*x;
if _N_>1 then predicted=predicted - alpha*error;
error=coalesce(Z, predicted) - beta*X;
run;
Hello,
Something like this ?
data test;
format Date MMDDYY10.;
informat Date MMDDYY10.;
input Date x z;
datalines;
1/31/2019 1 0
2/28/2019 2 1
3/31/2019 3 2
4/30/2019 4 3
5/31/2019 5 .
6/30/2019 6 .
7/31/2019 7 .
;
run;
data p_test;
set test;
retain error 0;
beta = 0.9996;
alpha = -1;
predicted = beta*x;
if _N_>1 then predicted=predicted - alpha*error;
error=coalesce(Z, predicted) - beta*X;
run;
Hello gamotte, thank you for the valuable input. You helped me very much! I appreciate it! Yelena
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.