Asset Classes

Free investment financial education


Multilingual content from IBKR

Close Navigation
Learn more about IBKR accounts
SAS: Repeated Estimation of Regressions by Group

SAS: Repeated Estimation of Regressions by Group

Posted June 12, 2024 at 1:59 pm
Sang-Heon Lee
SHLee AI Financial Model

This post presents a SAS code for estimating regression models by group. The number of group is not small that multiple estimation using a do-loop is convenient. In this process, each regression model name is set to each group name.

SAS Repeated Estimation of Regression by Group

For an example of repeated regressions, dataset is used and is copied to work.base1. work.base2 is created by adding the number and name of groups based on Team column. This preliminary work is done by the following SAS code.

SAS Data

In the above SAS code, the baseball dataset is grouped by Team and the number and name of group are created. The group name is used for the model name but the regression model name does not permit spaces so that we substitute underbars for spaces. Of course the number or name of group can have another available form.

SAS Sample Data

Regression with a group name as the model name

Given work.base2 dataset, the following SAS code performs an estimation of linear regression model. To use a group name as a regression model name, the group name is retrieved with the input group number before estimation of regression model is done. The regression output is saved to work.regout dataset with additional statistics such as R-squared.

SAS Data Sample 2

We can find that the estimation result of Atlanta Team group has the model name as “Atlanta”. All estimation results with varying the group number from ’01’ manually are as follows.

SAS Output 2

Repeated regressions

It is tedious and time-consuming to run every regressions manually. For an easy estimation, repeated estimation of regressions are preferred. For this purpose, the following SAS macro code is implemented for retrieving array of group names and multiple estimations are carried out using a do-loop.

Finally, some modifications of results are made and all estimation results are summarized into one dataset (work.regout_all)

SAS Data 3

The final output is of parameter estimates and relevant statistics such as the standard error, t-statistics, and p-values with R-squared and adjusted R-squared by each group (Team).

SAS Data Set Sample 3

Originally posted on SH Fintech Modeling blog.

Join The Conversation

If you have a general question, it may already be covered in our FAQs. If you have an account-specific question or concern, please reach out to Client Services.

Leave a Reply

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from SHLee AI Financial Model and is being posted with its permission. The views expressed in this material are solely those of the author and/or SHLee AI Financial Model and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.