f



Error in Creating bootstrapped samples

Hi,

I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 


I get this error when i try to run it. 

>Error # 5130 
>File out of order.  All the files in MATCH FILES must be in non-descending 
>order on the BY variables.  Use SORT CASES to sort the file. 
>Execution of this command stops. 

Here is my syntax.

COMPUTE ID=GPA.
SAVE OUTFILE 'BOOTDATA.SAV'.
INPUT PROGRAM .
*Replace "nsamples" in the next line with the desired number of samples.
LOOP SAMP=1 to 100.
*Replace "ncases" in the next two lines with the number of cases.
LOOP V = 1 to 1269.
COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
END CASE.
LEAVE SAMP.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM .
SORT CASES BY ID .
MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
SORT CASES BY SAMP.
SPLIT FILE BY SAMP. 


0
bryan
8/18/2016 10:20:17 PM
comp.soft-sys.stat.spss 5679 articles. 0 followers. Post Follow

5 Replies
323 Views

Similar Articles

[PageSpeed] 35

On Thu, 18 Aug 2016 15:20:17 -0700 (PDT), bryan.mac24@gmail.com wrote:

>Hi,
>
>I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
>I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 
>
>
>I get this error when i try to run it. 
>
>>Error # 5130 
>>File out of order.  All the files in MATCH FILES must be in non-descending 
>>order on the BY variables.  Use SORT CASES to sort the file. 
>>Execution of this command stops. 


The error message tells you that a file is not sorted. 

Since you sort  *  just before the MATCH, it would seem
that the other file is not sorted in order by GPA ( = ID). 

On the other hand, it seems possible that your error is
that you should have set ID equal to the Case Number, 
not to "GPA"; and that would already be in order. 

-- 
Rich Ulrich 


>
>Here is my syntax.
>
>COMPUTE ID=GPA.
>SAVE OUTFILE 'BOOTDATA.SAV'.
>INPUT PROGRAM .
>*Replace "nsamples" in the next line with the desired number of samples.
>LOOP SAMP=1 to 100.
>*Replace "ncases" in the next two lines with the number of cases.
>LOOP V = 1 to 1269.
>COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
>END CASE.
>LEAVE SAMP.
>END LOOP.
>END LOOP.
>END FILE.
>END INPUT PROGRAM .
>SORT CASES BY ID .
>MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
>SORT CASES BY SAMP.
>SPLIT FILE BY SAMP. 
>
0
Rich
8/18/2016 10:54:50 PM
On Thursday, August 18, 2016 at 3:54:57 PM UTC-7, Rich Ulrich wrote:
> On Thu, 18 Aug 2016 15:20:17 -0700 (PDT), bryan.mac24@gmail.com wrote:
> 
> >Hi,
> >
> >I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
> >I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 
> >
> >
> >I get this error when i try to run it. 
> >
> >>Error # 5130 
> >>File out of order.  All the files in MATCH FILES must be in non-descending 
> >>order on the BY variables.  Use SORT CASES to sort the file. 
> >>Execution of this command stops. 
> 
> 
> The error message tells you that a file is not sorted. 
> 
> Since you sort  *  just before the MATCH, it would seem
> that the other file is not sorted in order by GPA ( = ID). 
> 
> On the other hand, it seems possible that your error is
> that you should have set ID equal to the Case Number, 
> not to "GPA"; and that would already be in order. 
> 
> -- 
> Rich Ulrich 
> 
> 
> >
> >Here is my syntax.
> >
> >COMPUTE ID=$CASENUM.
> >SAVE OUTFILE 'BOOTDATA.SAV'.
> >INPUT PROGRAM .
> >*Replace "nsamples" in the next line with the desired number of samples.
> >LOOP SAMP=1 to 100.
> >*Replace "ncases" in the next two lines with the number of cases.
> >LOOP V = 1 to 1269.
> >COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
> >END CASE.
> >LEAVE SAMP.
> >END LOOP.
> >END LOOP.
> >END FILE.
> >END INPUT PROGRAM .
> >SORT CASES BY ID .
> >MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
> >SORT CASES BY SAMP.
> >SPLIT FILE BY SAMP. 
> >

Thanks. That makes sense. I had it set to a variable. The issue was be $CASENUM.  
Also is there an easier way to get the total descriptives of the bootstrapped. (Instead of adding the average of each sample).  I don't have the Bootstrapping module in my SPSS.


0
bryan
8/19/2016 12:15:52 AM
On Thursday, August 18, 2016 at 5:15:55 PM UTC-7, bryan...@gmail.com wrote:
> On Thursday, August 18, 2016 at 3:54:57 PM UTC-7, Rich Ulrich wrote:
> > On Thu, 18 Aug 2016 15:20:17 -0700 (PDT), bryan.mac24@gmail.com wrote:
> > 
> > >Hi,
> > >
> > >I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
> > >I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 
> > >
> > >
> > >I get this error when i try to run it. 
> > >
> > >>Error # 5130 
> > >>File out of order.  All the files in MATCH FILES must be in non-descending 
> > >>order on the BY variables.  Use SORT CASES to sort the file. 
> > >>Execution of this command stops. 
> > 
> > 
> > The error message tells you that a file is not sorted. 
> > 
> > Since you sort  *  just before the MATCH, it would seem
> > that the other file is not sorted in order by GPA ( = ID). 
> > 
> > On the other hand, it seems possible that your error is
> > that you should have set ID equal to the Case Number, 
> > not to "GPA"; and that would already be in order. 
> > 
> > -- 
> > Rich Ulrich 
> > 
> > 
> > >
> > >Here is my syntax.
> > >
> > >COMPUTE ID=$CASENUM.
> > >SAVE OUTFILE 'BOOTDATA.SAV'.
> > >INPUT PROGRAM .
> > >*Replace "nsamples" in the next line with the desired number of samples.
> > >LOOP SAMP=1 to 100.
> > >*Replace "ncases" in the next two lines with the number of cases.
> > >LOOP V = 1 to 1269.
> > >COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
> > >END CASE.
> > >LEAVE SAMP.
> > >END LOOP.
> > >END LOOP.
> > >END FILE.
> > >END INPUT PROGRAM .
> > >SORT CASES BY ID .
> > >MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
> > >SORT CASES BY SAMP.
> > >SPLIT FILE BY SAMP. 
> > >
> 
> Thanks. That makes sense. I had it set to a variable. The issue was be $CASENUM.  
> Also is there an easier way to get the total descriptives of the bootstrapped. (Instead of adding the average of each sample).  I don't have the Bootstrapping module in my SPSS.

Just an update: For some reason when I run this syntax in SPSS with the bootstrap module installed and one without, I get errors about how the: 

"specified file or directory cannot be read into. The file will not be saved. Save the file with another name or different location or change permissions first.
0
bryan
8/19/2016 5:26:09 PM
This appears to be something I wrote (likely 20 yrs ago).
Go to the SPSS-X http://spssx-discussion.1045642.n5.nabble.com/ (Nabble group)  and search "Bootstrap Marso" for much more reasonable code.
Sometimes I wish I had a time machine so I could go back and delete 
some of the crap I wrote before I knew what the fuck I was doing ;-)

On Thursday, August 18, 2016 at 6:20:20 PM UTC-4, bryan...@gmail.com wrote:
> Hi,
> 
> I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
> I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 
> 
> 
> I get this error when i try to run it. 
> 
> >Error # 5130 
> >File out of order.  All the files in MATCH FILES must be in non-descending 
> >order on the BY variables.  Use SORT CASES to sort the file. 
> >Execution of this command stops. 
> 
> Here is my syntax.
> 
> COMPUTE ID=GPA.
> SAVE OUTFILE 'BOOTDATA.SAV'.
> INPUT PROGRAM .
> *Replace "nsamples" in the next line with the desired number of samples.
> LOOP SAMP=1 to 100.
> *Replace "ncases" in the next two lines with the number of cases.
> LOOP V = 1 to 1269.
> COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
> END CASE.
> LEAVE SAMP.
> END LOOP.
> END LOOP.
> END FILE.
> END INPUT PROGRAM .
> SORT CASES BY ID .
> MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
> SORT CASES BY SAMP.
> SPLIT FILE BY SAMP.

0
David
8/19/2016 7:45:41 PM
On Friday, August 19, 2016 at 12:45:44 PM UTC-7, David Marso wrote:
> This appears to be something I wrote (likely 20 yrs ago).
> Go to the SPSS-X http://spssx-discussion.1045642.n5.nabble.com/ (Nabble group)  and search "Bootstrap Marso" for much more reasonable code.
> Sometimes I wish I had a time machine so I could go back and delete 
> some of the crap I wrote before I knew what the fuck I was doing ;-)
> 
> On Thursday, August 18, 2016 at 6:20:20 PM UTC-4, bryan...@gmail.com wrote:
> > Hi,
> > 
> > I was wondering on how to fix the syntax for obtaining bootstrapped samples in SPSS?
> > I saw this online but I kept getting errors, especially the MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID . 
> > 
> > 
> > I get this error when i try to run it. 
> > 
> > >Error # 5130 
> > >File out of order.  All the files in MATCH FILES must be in non-descending 
> > >order on the BY variables.  Use SORT CASES to sort the file. 
> > >Execution of this command stops. 
> > 
> > Here is my syntax.
> > 
> > COMPUTE ID=GPA.
> > SAVE OUTFILE 'BOOTDATA.SAV'.
> > INPUT PROGRAM .
> > *Replace "nsamples" in the next line with the desired number of samples.
> > LOOP SAMP=1 to 100.
> > *Replace "ncases" in the next two lines with the number of cases.
> > LOOP V = 1 to 1269.
> > COMPUTE ID=TRUNC(UNIFORM(1269)) + 1.
> > END CASE.
> > LEAVE SAMP.
> > END LOOP.
> > END LOOP.
> > END FILE.
> > END INPUT PROGRAM .
> > SORT CASES BY ID .
> > MATCH FILES / FILE * / TABLE 'BOOTDATA.SAV' / BY ID .
> > SORT CASES BY SAMP.
> > SPLIT FILE BY SAMP.

I hope I found the more reasonable code and hope my syntax looks good.  :)
Does it look right? I need 100 bootstrapped samples.

I was wondering if this is how you calculate the 95% confidence interval? I tried running it but nothing showed up sadly. I would like to find the bootstrapped distribution of the mean.



*Calculate Confidence Interval.
COMPUTE Stats(:,3)= (0.975)*Stats(:,2)/SQRT(N).



Descriptives GPA.

DEFINE BOOT (VAR !TOKENS(1) / NSAMP !TOKENS(1)/SPRINT !TOKENS(1) !DEFAULT(F) ). 
PRESERVE. 
SET MXLOOPS=200000. 
FREQ GPA /STAT ALL/FORMAT NOT. 
MATRIX. 
GET DATA / VARIABLES !VAR / FILE *. 
COMPUTE N=NROW(DATA). 
*Determine ranks of Median case(s)*. 
COMPUTE CRIT={(N/2)+.5, (N/2)+.5 }. 
DO IF N/2=TRUNC(N/2). 
+  COMPUTE CRIT=CRIT + {-1.5,0.5}. 
END IF. 

COMPUTE Stats=MAKE(100,3,0). 
COMPUTE SAMPLES=MAKE(N,1,0). 
LOOP SAMPLE=1 TO 100. 
* Construct array of random Indexes (Data pointers). 
+  COMPUTE RArray=TRUNC(UNIFORM(N,1)*N +1). 
+  LOOP CASEID=1 TO N. 
+    COMPUTE SAMPLES(CASEID)=DATA(RARRAY(CASEID)). 
+  END LOOP. 
** Calculate Median **. 
+  COMPUTE MEDSTAT=GRADE(SAMPLES). 
+  COMPUTE Stats(SAMPLE,3) =0. 
+  LOOP I=1 TO N. 
+    LOOP J=1 TO 2. 
+      DO IF MEDSTAT(I)=CRIT(J). 
+        COMPUTE Stats(SAMPLE,3) =Stats(SAMPLE,3)+SAMPLES(I). 
+      END IF. 
+    END LOOP. 
+  END LOOP. 
+  COMPUTE Stats(SAMPLE,3)=Stats(SAMPLE,3)/2. 
*  Generate Sum(GPA) and SUM(GPA**2). 
+  COMPUTE Stats(SAMPLE,1)=CSUM(Samples)/N. 
+  COMPUTE Stats(SAMPLE,2)=T(Samples)*Samples). 
END LOOP. 
* Calculate StdDev *. 
COMPUTE Stats(:,2)=SQRT((Stats(:,2)-N*Stats(:,1))/(N-1)). 
!IF (!SPRINT !EQ T) !THEN 
PRINT Stats 
     /TITLE "Individual Bootstrapped Sample Statistics" 
     /CLABELS "Mean","SD","Median". 
!IFEND 
* Calculate Averages of Bootstrapped statistics *. 
PRINT (CSUM(Stats)/!NSAMP) 
     /TITLE="Averaged Bootstrapped Statistics" 
     /CLABELS "Mean","StdDev","Median". 
END MATRIX. 
!ENDDEFINE. 
BOOT Var=GPA NSAMP=100 SPRINT=T. 
BOOT Var=GPA NSAMP=100. 
0
bryan
8/20/2016 8:47:31 AM
Reply: