``` 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86``` ```*QUESTION: I have a dataset in which each case includes six consecutive months of the average number of drinks per drinking day. Cases are persons. What i want to do is compute two regression equations for each case. One equation is the linear equation relating time (i.e., month) to drinks per drinking day (DDD) and the second is a quadratic equation relating time and time squared to DDD. Equation 1: DDD = A0 + A1 * Time Equation 2: DDD = A0 + A1 * Time + A2 * Time**2 Thus I want to add the casewise slope and intercept for equation one and similar for equation two. I can easily do it for Equation 1 using the computations given in Cohen (and any other regression book). But how do i compute the coefficients for equation two? Missing data is not an issue. ***************************************************. *ANSWER: * Add Casewise regression coefficients to data file. * Posted to SPSSX-L on 2001/02/03 by Raynald Levesque. * 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 also be automated if necessary). !doit nbvar=5. ```
Related pages

...