.- help for ^swor^ (STB-59: dm86) .- Draw random sample (alternative to ^sample^) ------------------------------------------ ^swor^ # [^if^ exp] [^in^ range] [^,^ ^by(^groupvars^)^ ^g^enerate^(^newvar^)^ ^k^eep ] Description ----------- ^swor^ draws a pseudo-random sample of size # from the data in memory, by default discarding (optionally keeping) the remaining observations. Observations not meeting the optional ^if^ and ^in^ criteria are kept (sampled at 100%). # must be positive and no greater than the number of observations in each group to be sampled. Sampling here is defined as drawing observations without replacement. See help on @sample@ for sampling without replacement specified in percent to be sampled, rather than absolute number. See help on @bstrap@ for sampling with replacement. If you are serious about drawing random samples, you must first set the random number seed; see help @generate@. Options ------- ^by(^groupvars^)^ specifies that a sample of size # is to be drawn within each set of values of groupvars. ^generate(^newvar^)^ generates newvar containing 1 for those observations included in the sample and 0 for those not included. ^keep^ overrides the default dropping of nonsampled observations. ^keep^ must be combined with ^generate( )^. Examples -------- draw sample of 100: . ^swor 100^ keep all ^sex^ != 0, but sample 100 from ^sex^ == 0: . ^swor 100 if sex == 0^ sample 100 from each group of ^sex^: . ^swor 100, by(sex)^ sample 100 from each group of ^sex^, but keep all observations: . ^swor 100, by(sex) gen(sample) keep^ sample 100 if ^sex^ == 0 and keep only those observations: . ^swor 100 if sex == 0, gen(sample)^ . ^keep if sample^ Author ------ Nicholas J. Cox, University of Durham, U.K. n.j.cox@@durham.ac.uk Also see -------- Manual: ^[R] sample^ On-line: help for @sample@, @bstrap@