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

st: Re: keep based on zip codes


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: keep based on zip codes
Date   Sun, 16 Jun 2002 10:35:29 -0400

On Sunday, June 16, 2002, at 02:33 AM, Ahmed wrote:

I ended up doing it in SAS, but Diana later gave me a stata suggestion which also works. It's the "for" command in Stata that does the same thing Frank suggests below.

I've come to the conclusion that it's worth learning *both* SAS and stata, especially if you work with large datasets.

Mushfiq


[email protected] 06/14/02 10:40PM >>>
You probably can do what you want by using -real- to generate the numeric
variable -newzip- from -zip-, reformat as integer, and then use the -egen-
function,
- -eqany newzip, values(12345, 12456, 234,...), to create a 0-1 variable to be
used with -keep-.
The much better way to do this is to place the (sorted) zip codes (using the same variable type that appears in your existing file) in a separate Stata .dta file, say wantzip.dta; then all you have to do is

sort zip
merge zip using wantzip
keep if _merge==3

which will keep the records in the big file that have the zipcodes in the wantzip file. No need to have a command with 700 values in it!

Kit

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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