Create duplicate observations in Stata

For certain cleaning jobs, it can be useful to duplicate an observation (often only temporarily). To create a identical copy of an observation, just type

expand 2 if testvar==1, gen(dupindicator)

The 2 tells Stata that there should be two copies of the same observation (i.e. the original and the copy), which can be identified by the new variable dupindicator that is defined as 1 for the duplicate, and 0 for the original variables. With his new variable, the duplicates can later easily be identified and dropped if necessary.

Leave a Reply