Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re: changing numbers of observations

From   Kit Baum <>
Subject   st: re: changing numbers of observations
Date   Mon, 28 May 2007 10:40:42 -0400

Jesse said

I have a large do file that I've created to clean a dataset. It
includes some merging as well as forvalues commands. The first line of
code is use "filepath", clear

I've run it five times now and each time there has been a different
number of observations at the end (n=7639, 7637, 7645, 7629, and 7641)

It seems that if the do file starts with the same file and does the same
thing every time it should be returning the same observations every
time. Any ideas on what is happening here?

This is a FAQ. Merging without one or the other datasets having a unique merge key causes this problem. Section 3.7.2 of my book (URL below), "The dangers of many-to-many merges", discusses this issue.

Make sure you have unique keys on one side or the other, and use the uniqusing or uniqmaster options on merge to ensure that uniqueness is present.

Kit Baum, Boston College Economics and DIW Berlin
An Introduction to Modern Econometrics Using Stata:

* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index