Help using Base SAS procedures

Macro for multiple GARCH Regressions

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 75
Accepted Solution

Macro for multiple GARCH Regressions

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;

Attachment

Accepted Solutions
Solution
‎02-26-2015 02:39 PM
Super User
Posts: 17,826

Re: Macro for multiple GARCH Regressions

[ Edited ]

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


All Replies
Solution
‎02-26-2015 02:39 PM
Super User
Posts: 17,826

Re: Macro for multiple GARCH Regressions

[ Edited ]

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;

 

Frequent Contributor
Posts: 75

Re: Macro for multiple GARCH Regressions

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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