SAS : Repeated Estimation of Regressions by Group

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, sashelp.baseball 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 : Repeated Estimation of Regression by Group

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 forms.

SAS : Repeated Estimation of Regression by Group


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 : Repeated Estimation of Regression by Group

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 : Repeated Estimation of Regression by Group


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 : Repeated Estimation of Regression by Group

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 : Repeated Estimation of Regression by Group

Period.

No comments:

Post a Comment

Tentative Topics (Keeping Track to Avoid Forgetting)

Segmented Nelson-Siegel model
Shifting Endpoints Nelson-Siegel model
Nadaraya-Watson estimator
Locally weighted scatterplot smoothing (LOWESS)
Time-Varying Parameter Vector Autoregressions (TVP-VAR)
Time-varying or Dynamic Copula
Bayesian VAR
Adrian-Crump-Moench (ACM) term premium model
GARCH-EVT-Copula approach