100 likes | 186 Views
Generating Random Samples. SAS, EXCEL, JMP, SPSS. 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
E N D
Generating Random Samples SAS, EXCEL, JMP, SPSS
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)
SAS Code to Generate Random Sample (n=10) Data Pop; Input Day FlightNum TailNum $ DestCity $ TaxiTime Sched Actual Distance; Ranx=Ranuni(seed); /* Put in a number where “seed” is */ Cards; 1 317 N834MH HNL 29 580 567 4496 … 31 317 N840MH 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 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 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 # 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