/* SAS example: Regression with qualitative (categorical) predictors */ /* We use the Insurance innovation data in Table 8.2 of the book */ /* type = 0 indicates a mutual company */ /* type = 1 indicates a stock company */ DATA insurinn; INPUT time size type; cards; 17 151 0 26 92 0 21 175 0 30 31 0 22 104 0 0 277 0 12 210 0 19 120 0 4 290 0 16 238 0 28 164 1 15 272 1 11 295 1 38 68 1 31 85 1 21 224 1 20 166 1 13 305 1 30 124 1 14 246 1 ; run; /* Fitting the regression model through ordinary least squares: */ PROC REG DATA=insurinn; MODEL time = size type / clb; run; /**************************************************************/ /* Example of predictor with 4 categories */ /* shirt size example */ /* We put a dollar sign ($) after size in the INPUT statement */ /* to tell SAS that it is a character (non-numeric) variable. */ DATA shirt; INPUT amount size $; IF size='medium' THEN x1 = 1; ELSE x1 = 0; IF size='large' THEN x2 = 1; ELSE x2 = 0; IF size='xlarge' THEN x3 = 1; ELSE x3 = 0; cards; 24.65 small 16.53 large 27.43 xlarge 31.56 small 16.03 medium 65.23 small 24.96 large 14.78 xlarge 27.34 large 29.54 medium 31.05 medium 29.45 large 41.89 small 16.22 large 21.87 xlarge 43.67 small 34.67 xlarge 33.77 medium ; run; /* Looking at the data set: */ PROC PRINT DATA = shirt; run; /* Fitting the regression model through ordinary least squares: */ PROC REG DATA=shirt; MODEL amount = x1 x2 x3 / clb; run; /* Interpreting estimated regression coefficients: */ /* We estimate that shoppers with "medium" shirt size spend $13.80 LESS */ /* on AVERAGE than shoppers with "small" shirt size. */ /* We estimate that shoppers with "large" shirt size spend $18.50 LESS */ /* on AVERAGE than shoppers with "small" shirt size. */