Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In SPSS, how can I randomly assign half the cases to one group and the remaining half to another group?

SPSS can randomly select a specified number of cases from your data set. Following is an example:

Suppose you have 50 observations for the variables Y, X1, and X2. You wish to randomly select 25 cases and run a regression of Y on X1 and X2, and then use the other 25 cases to run the same regression so you can compare the results from the two analyses.

To select 25 cases and run the regression, use the following SPSS syntax:

USE ALL. do if $casenum = 1. compute #s_$_1=25. compute #s_$_2=50. end if. do if #s_$_2 > 0. compute filter_$ = uniform(1)* #s_$_2 < #s_$_1. compute #s_$_1 = #s_$_1 - filter_$. compute #s_$_2 = #s_$_2 - 1. else. compute filter_$ = 0. end if. VARIABLE LABEL filter_$ '25 from the first 50 cases (SAMPLE)'. FILTER BY filter_$. REGRESSION /DEPENDENT y /METHOD=ENTER x1 x2.

When SPSS selects the sample, it also generates a new variable, FILTER_$, which is coded as 1 if the case is selected, and 0 otherwise. For the second analysis, you can use this variable to include those cases that were not selected in the first sample. To do so, use the following SPSS syntax:

USE ALL. COMPUTE filter_$=(filter_$=0). VARIABLE LABEL filter_$ 'filter_$=0 (FILTER)'. VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'. FILTER BY filter_$. REGRESSION /DEPENDENT y /METHOD=ENTER x1 x2.

Finally, if you want to reset the data set to its original form (including all 50 cases), use the SPSS command FILTER OFF .

For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.

This is document acwb in domain all.
Last modified on May 04, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.