Generating Random Samples SAS EXCEL JMP SPSS Population

  • Slides: 10
Download presentation
Generating Random Samples SAS, EXCEL, JMP, SPSS

Generating Random Samples SAS, EXCEL, JMP, SPSS

Population of Data Sample • Data should be in a dataset where each row

Population of Data Sample • Data should be in a dataset where each row represents an individual unit, and column fields represent variables measured on the individual • A new column field will be created that contains a pseudo-random number generated by statistal software package (usually Uniform(0, 1) r. v. ) • Data are sorted by the random number, or simply selected for analysis (depending on software)

All ATL/HNL 10/2004 Delta Flights (N=31)

All ATL/HNL 10/2004 Delta Flights (N=31)

SAS Code to Generate Random Sample (n=10) Data Pop; Input Day Flight. Num Tail.

SAS Code to Generate Random Sample (n=10) Data Pop; Input Day Flight. Num Tail. Num $ Dest. City $ Taxi. Time Sched Actual Distance; Ranx=Ranuni(seed); /* Put in a number where “seed” is */ Cards; 1 317 N 834 MH HNL 29 580 567 4496 … 31 317 N 840 MH HNL 16 580 576 4496 ; Proc Sort; By Ranx; Data Sample; Set Pop; If _N_ <= 10; Run; /* You can run any procedures now on the Sample */

Generating Random Samples in EXCEL • In a new column past the data, type

Generating Random Samples in EXCEL • In a new column past the data, type in the first row containing data on a unit: =RAND() • COPY and PASTE that cell until all N units have a random number • While that range of N cells is still highlighted, click on COPY EDIT PASTE SPECIAL Click on VALUES (This changes them from Dynamic to Static) • Place Cursor in Data Field, Click on: DATA SORT Choose Column with Random Values and Choose appropriate Header Row Status • After data are sorted, COPY and PASTE (SPECIAL VALUES) the first n units to a new worksheet

Random Numbers (Not Sorted Yet)

Random Numbers (Not Sorted Yet)

Data Sorted By Random Number

Data Sorted By Random Number

EXCEL Random Sample (n=10)

EXCEL Random Sample (n=10)

Random Samples in JMP • Import Data into JMP • Click on TABLES SUBSET

Random Samples in JMP • Import Data into JMP • Click on TABLES SUBSET RANDOM SAMPLE Enter Your Sample Size (e. g. 10) in Box • Subset Dataset Appears in New Table • Analyze the Data in that Table

Random Samples in SPSS • Import Data into SPSS • Older Versions: Click Transform

Random Samples in SPSS • Import Data into SPSS • Older Versions: Click Transform Random # Seed Enter a numeric seed • Newer Versions: Click Transform Random # Generators Active Generator Initialization Fixed Value Enter a numeric seed – Click Data Select Cases – Under Select, choose Random Sample of Cases. Click on Sample box. – Choose Exactly n (10) of the first N (31), click Continue – Click OK. Slashes will appear in the case numbers of the cases not in the sample, and an indicator variable representing Filter will be attached to end of dataset. – Analyze the Data