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.
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.
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.
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.
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)
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).
Period.
No comments:
Post a Comment