如何在同一 SAS 数据集上按月执行回归? [英] How do I perform regression by month on the same SAS data set?

查看:65
本文介绍了如何在同一 SAS 数据集上按月执行回归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的规格如下:

Proc reg data = liqfworld;
     Model x = y z ;

我需要对我的数据集中的每只股票执行此回归,这些股票具有每日数据和每月数据.它按 SAS 格式的股票 ID 和日期排序.我是否需要一个宏来对同一数据集执行重复回归?我的最终目标是将每个股票和每个月的 y 系数获取到输出数据集中.

I need to perform this regression for every stock in my data set which has daily data and for every month. It is sorted by stock ID and dates in SAS format. Do I need a macro for performing repeated regressions on the same data set? My ultimate aim is to obtain the coefficient for y for each stock and each month into an output data set.

感谢任何指点.谢谢.

为了澄清,我需要进行多次非滚动回归(每个月每只股票),虽然股票 ID 按升序排序,但它们是这样的:83、94、105 等.

To clarify, I need to do multiple not rolling regressions (each stock each month) and while the stock ID's are sorted in ascending order they are like this: 83, 94, 105 etc.

推荐答案

由于您的数据集已按正确顺序排序,您应该能够使用按组处理来完成此操作,而无需使用宏.如果您还没有月份变量,则需要先从现有日期变量中创建一个.我建议使用视图来执行此操作.

As your dataset is already sorted in the right order, you should be able to do this using by-group processing, without using a macro. If you don't already have a month variable, you will need to first create one from your existing date variable. I'd suggest using a view to do this.

那么你应该可以这样做:

Then you should be able to do this like so:

Proc reg data = liqfworld; 
Model x = y z ;
/*More statements within the proc reg as needed*/
by stock month;
run;

这篇关于如何在同一 SAS 数据集上按月执行回归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆