Stata FAQ How can I draw a random sample of my data?
There are many instances when you may want to take a random sample of your dataset. For example, you may have a very large data set, and you are trying to work out the code to clean your data or to analyze it. Running the code on many observations can take a while, so testing the code on a subset of the data is a good way to save some time. However, you may not want to take just the first 100 or so cases, as they may be different in some important way than cases that occur later in the data set. Hence, taking a random sample of the data would be desirable. There are two commands in Stata that can be used to take a random sample of your data set. Use the sample command to draw a sample without replacement, meaning that once an observation (i.e., case, element) has been selected into the sample, it is not available to be selected into the sample again. Use the bsample command if you want to draw a sample with replacement, meaning that once the observation has been selected into the sampl