Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten buis <maartenbuis@yahoo.co.uk> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: looking for more efficient programming for randomly shuffling list of numbers |
Date | Thu, 26 Aug 2010 16:12:30 +0000 (GMT) |
--- On Thu, 26/8/10, Evelyn Ersanilli wrote: > For a survey I need to make stickers that can be used to > randomly select respondents within a household. > These stickers should contain the numbers 1-20 in a random > order (most households will have less than 20 members). Each > sticker should have its own random order, though it is not a > problem if by chance some stickers are the same. The > stickers should be generated in such a way that each order > of numbers 1-20 should be possible and equally likely. What about this: *----------------- begin example ---------------- // create some data // I would start with a single dataset containing // only the household id drop _all set obs 9600 gen hhid = _n // make twenty copies of each houshold and assigning // them numbers 1 till 20 expand 20 bys hhid : gen number = _n // sort on the random variable u within each household gen u = runiform() bys hhid (u) : gen random_order = _n // u no longer needed drop u // turn into a dataset with one observation per household // with 20 numbers in random order reshape wide number , i(hhid) j(random_order) *------------------- end example ------------------------ Hope this helps, Maarten -------------------------- Maarten L. Buis Institut fuer Soziologie Universitaet Tuebingen Wilhelmstrasse 36 72074 Tuebingen Germany http://www.maartenbuis.nl -------------------------- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/