Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: selection by group characteristics

From   baum <>
Subject   st: Re: selection by group characteristics
Date   Sat, 15 Jun 2002 09:31:10 -0400

--On Saturday, June 15, 2002 2:33 -0400 Nisha wrote:

Hope someone can help me with this.
I have a dataset of households in various zip codes.  I want to keep only
those hholds that are in 700 particular zip codes that I've identified.
The logical way to do this in stata is to write a command that looks like

keep if zip=="12345" | zip=="12456" | zip=="00234" | zip==..............

There would be about 700 "or" conditions.

The problem is, Stata doesn't allow this many "OR" conditions in that
statement.  This command works fine if I only put in 10 or 20 zips.  It
gives me an error saying "too many literals" if I put in all 700 zips in
my list.

Is there any other way for me to perform this operation?
Yes. Hardcoding the desired zip codes in a program is a Very Bad Idwa. The Stataish way to do this is by placing the desired codes in a dataset, and then using merge. That way it is very easy to alter the list of desired groups (in your case zip code areas). There is a FAQ on just this subject at


* For searches and help try:

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