Eliminating Duplicate Cases Stat A
Eliminating Duplicate Cases Stat A
Eliminating Duplicate Cases Stat A
* "h:\000\STATA_doc\DelDupCases.do"
* This is a sample program that eliminates duplicate cases from a datset.
* The sample data mimics data from CPS.
* People can be interviewed for up to three years.
* This researcher wants to save all of the cases that were interviewed
* in 2008, and any cases that were interviewed in 2007 and 2009
* who were not interviewed in 2008, and she wants only one case per person
* even if they were interviewed in multiple years.
** I have color coded this for you.
** My comments are in green, my commands to Stata are in blue, and the things
** stata has to tell me are in black.
1
Prepared by Patty Glynn, University of Washington, November 1, 2010. Thanks to Sara Vera for testing this.
** The following command creates a variable named ppdup that has the
** value of id for the case behind it.
** [_n-1] asks stata to look at the previous case .
** (similar to “lag” in SAS and SPSS) .
** select cases where the id is not the same as the id in the previous case .
drop if ppdup == id
(4 observations deleted)
** All of the key commands not annotated and without “list” commands .