BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Costasg
Calcite | Level 5

Hello everyone,

I have 50 time-series, for which I need to run a GARCH model for volatility forecasting. What I want to do is to avoid running each model seperately (red highlighted). Any ideas on how I could do that?

Many thanks in advance.

data data;

infile "C:\Users\kg25\Desktop\Test Data.txt" dsd dlm='09'x firstobs=2 lrecl=32767 stopover;
input date:ddmmyy. (a1-a50)(:numx.??);

format date ddmmyy10.;

run;


*Create Returns and Squared Returns;

data data2;set data;

vars(*) a1--a50;

array r(50);

do i=1 to dim(vars);

end; drop i;

var(*) r1--r50;

array rsq(50);

do i=1 to dim(var);

end; drop i;

run;

*create time variable;

data data2;set data2(firstobs=2);time + 1;

by date;

run;

*Choose in-sample;

data data3;set data2(obs=1303);

run;

*Create observations for 1 year;

data data4;
do time = 1304 to 1564;output;end;
run;

*merge data;
data data5;
merge data3 data4;by time;
run;


*Estimate AR(1)-Garch (1,1) model;

proc autoreg data=data5;
model r1= / nlag=1 garch=(q=1, p=1) maxit=50 noprint;
output out=data6 cev=vhat1;
run;

*merge data;

data data7;
merge data6 data2;by time;
run;


*Compute Mean Absolute Error and Root Mean Square Error;

data data8;set data7(firstobs=1304);
MAE=abs(rsq1-vhat1);
RMSE=sqrt(rsq1-vhat1);
run;

proc means data=data8 mean stderr prt;
var mae rmse;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Transpose your data.

 

If you have for example r1-r50

 

data transpose_reg;
set data5;
array r(50) r1-r50;
do i=1 to 50;
reg_var=r(i);
output;
end;
 
drop r1-r50;
run;
 
Proc sort data=transpose_reg;
by i;
run;
 
proc autoreg data=transpose_reg;
BY i;
model reg_var= / nlag=1 garch=(q=1, p=1) maxit=50 noprint;
output out=data6 cev=vhat;
run;

 

View solution in original post

2 REPLIES 2
Reeza
Super User

Transpose your data.

 

If you have for example r1-r50

 

data transpose_reg;
set data5;
array r(50) r1-r50;
do i=1 to 50;
reg_var=r(i);
output;
end;
 
drop r1-r50;
run;
 
Proc sort data=transpose_reg;
by i;
run;
 
proc autoreg data=transpose_reg;
BY i;
model reg_var= / nlag=1 garch=(q=1, p=1) maxit=50 noprint;
output out=data6 cev=vhat;
run;

 

Costasg
Calcite | Level 5

Many thanks Reeza! It worked in this way as well!

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1875 views
  • 0 likes
  • 2 in conversation