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:
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.
Last modified on May 04, 2011.







