我需要每天滚动回归输出。数据集是股票收益和交易量,模型仅为return = volume。 我需要过去30天的回归系数,每天进一步使得30天的窗口保持不变。
答案 0 :(得分:0)
基于我理解的问题,你想要追溯一个庞大的数据集每月运行模型。这是我最近做过的类似事情。
/*Select the parts of the data from base data based on input.*/
%macro model_by_dates(id, date1, date2);
data to_model;
set begin(where=( &date1. < date_var < &date2.));
run;
/*YOUR model code here*/
data result_file;
set From_model;
id=&id; /*To recognize from which model this is from.*/
run;
/*If you have huge files, do permanent data after every 10 loops or so. Depends.*/
proc append base=all_Results data=result_file force; run;
%mend model_by_dates;
/*here we create the dates list. You can do this in multiple ways. Datdiff maybe?*/
%let maxmonths=3;
data dates;
do i=0 to &maxmonths. by 1;
begin=date()-(i*30);
end = date()-( (i+1)*30);
output;
end;
run;
/*This is the master switch. It executes the macro for each row of the dates.*/
data _NULL_;
set dates;
call execute('%nrstr(%model_by_dates('
||strip(id)||','
||strip(begin)||','
||strip(end)||
'))');
run;
编辑根据进一步澄清,我正在更改日期列表的创建:
data dates;
do i=0 to 30 by 1;
begin=date()-(i+30);
end = date()- i ;
output;
end;
run;