Add Casewise Regression Estimatest to the Data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | * QUESTION: How can I add casewise regression parameters to the data file. * ANSWER by rlevesque@videotron.ca posted to SPSSX-L. * Define dummy data file for illustration purposes (here I assume there are 5 cases). INPUT PROGRAM. LOOP id=1 TO 5. VECTOR drink(6F8.0). LOOP #time=1 TO 6. COMPUTE drink(#time)=RND( UNIFORM(9)). END LOOP. END CASE. END LOOP. END FILE. END INPUT PROGRAM. LIST. SAVE OUTFILE='c:\\temp\\mydata.sav'. *Next line prints the macro expansion in the output window. SET MPRINT=yes. * Start the job. STRING newname(A8). * Next line works provided there are less than 10,000,000 cases. COMPUTE newname=CONCAT('v',LTRIM(STRING($CASENUM,F7.0))). FLIP /newnames=newname. * Define the 2 IVs and the selecvar in order to skip the ID line. COMPUTE time1 = $casenum-1. COMPUTE selecvar=time1>0. COMPUTE time2 = time1**2. *//////////////////////////////////////////////. DEFINE !doit(nbvar=!TOKENS(1)) * Save the regression parameters of each case in a separate file. !DO !cnt=1 !TO !nbvar REGRESSION /SELECT= selecvar EQ 1 /MISSING LISTWISE /STATISTICS COEFF OUTS R ANOVA /CRITERIA=PIN(.05) POUT(.10) /NOORIGIN /DEPENDENT !CONCAT('v',!cnt) /METHOD=ENTER time1 time2 /OUTFILE=COVB( !QUOTE(!CONCAT('C:\\temp\\param',!cnt,'.sav'))) . !DOEND * Get all parameters in the same file; keep only the parameters estimates.. GET FILE= 'C:\\temp\\param1.sav'. !DO !cnt=2 !TO !nbvar ADD FILES FILE=* /FILE=!QUOTE(!CONCAT('C:\\temp\\param',!cnt,'.sav')) . !DOEND SELECT IF RTRIM(rowtype_)="EST". * then add them to the original data file. MATCH FILES /FILE=* /RENAME (depvar_ rowtype_ varname_ = d0 d1 d2) /FILE='C:\\Temp\\mydata.sav' /DROP= d0 d1 d2. EXECUTE. !ENDDEFINE. *//////////////////////////////////////////////. **** Call macro (replace the 5 by the number of cases you have in your file). **** (This step could be automated if necessary). !doit nbvar=5. |
Related pages
...