Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • screen survey responses for state zip code

    Hello,

    I am trying to screen out survey responses that are out-of-state using zip code. My plan was to make an indicator variable:

    gen out_state_zip=1 if !inlist(zipcode, zip1, zip2,....ziplast)

    Since there are so many zip codes (nearly a thousand) I got an error message stating "expression too long." Is there another method I could use to flag out of state zip codes?

    My backup option will be to create a separate data set with Michigan zip codes, then do a many to 1 merge with my survey data set, and exclude surveys that don't have a zip code match.

    Many thanks,
    Alyssa

  • #2
    Merging with a reference dataset is how problems like this are most often approached, and is the path I would take.

    Since inlist() accepts at most 250 arguments, you could break your inlist() into several separate inlist() calls.
    Code:
    gen in_state_zip = inlist(zipcode, zip1, zip2,....zip200) | inlist(zipcode, zip201, zip202,....zip400) | ...
    gen out_state_zip = !in_state_zip
    Another approach is to note that the first two digits of most Michigan zipcodes are 48 or 49, although there are border cases where some Michigan locations may actually have a zipcode that appears to be from an adjoining state, and some zipcodes beginning 48 or 49 may be for an area in an adjoining state.
    Code:
    gen approx_out_state_zip = !inlist(floor(zipcode/1000),48,49)

    Comment

    Working...
    X