I have a dataset representing a large group of people that I'm using to specify a Cox proportional hazards model of a binary outcome on some explanatory variables. My outcome variable is a health condition of interest (coded 1/0), and, my "focal" explanatory variable -- the one I'm most interested in -- is a binary indication of whether a person has been given a certain treatment or not. The other explanatory variables are the usual sociodemographic suspects: age, sex, and a couple others.

In planning my model, I'd like, if possible, so find some way to also control for subjects' geography in the estimation of my exposure variable (I have a reason to think it could matter). At first glance I've got a handy way to do this: a variable 3_digit_zip_code representing -- you guessed it -- the first 3 digits of a subject's US postal code.

Question / problem

The immediate objection to including ZIP in the model, of course, is that a hazard ratio (HR) for ZIP code would be uninterpretable: what could "a one digit increase" in ZIP code mean in practical terms?

But then I think of an objection to the objection: wouldn't there be some utility of including ZIP in the interpretability of the other covariates in the model, above all the main one, treatment? In other words, the HR for treatment would be saying something useful about the hazard of the outcome between the treated and untreated, given the same levels of the other covariates -- right?

I suppose I have two questions, then:

  1. Is it worth it to include ZIP in such a Cox model, even if its HR is uninterpretable, if it adds to "control" in other HRs?

  2. Is there a better way of controlling for geography, e.g. matching of some kind?

  • 3
    $\begingroup$ It's complicated. I think the proposed approach is a bit lazy. The first 3 digits of a zip code doesn't mean anything. You can find all kinds of useful census information to map to zip-codes however, such as geographic region, median household income, various indices of development and crime, etc. If you have the whole subject address, you can geocode and derive useful measures like drive time to hospital, density of greenspace, etc. $\endgroup$
    – AdamO
    Commented Mar 29, 2022 at 20:51
  • 3
    $\begingroup$ That said, zipcode can be thought of as a cluster with cluster effects. You can adjust these as fixed effects with a large enough sample size, or as random effects if the $n$ is too small; a hard assumption to check. As with all categorical variables, the coded contrasts are a mean difference (or HR for Cox model) with respect to a reference level. The "increase/decrease" phenomenon is neither necessary or sufficient to interpret variables in a model. $\endgroup$
    – AdamO
    Commented Mar 29, 2022 at 20:53
  • 5
    $\begingroup$ What's critical is not to treat the ZIP code as a numeric variable. That might be implied by the way the question is worded. A hazard ratio associated with "a one digit increase" in ZIP code is certainly meaningless. If you can't go into the geographic/demographic detail that @AdamO suggests in a comment, code the ZIP codes as a multi-level categorical predictor for use as fixed effects, cluster terms, or perhaps frailty/random effects. $\endgroup$
    – EdM
    Commented Mar 29, 2022 at 22:09
  • $\begingroup$ Thank you @EdM, that's quite helpful. If you want to write that up as an answer, I'm happy to mark it answered. $\endgroup$
    – logjammin
    Commented Mar 29, 2022 at 22:37
  • $\begingroup$ Also see stats.stackexchange.com/questions/146907/… $\endgroup$ Commented Feb 2 at 0:40

2 Answers 2


Modeling outcome-relevant geographic and demographic covariates directly, as @AdamO suggests, is the best way to go. Another answer suggests ways to start getting such information.

The 3-digit ZIP code poses two problems.

First, without care the numbers might be interpreted as a numeric variable and, as you state, "a one digit increase" in ZIP code would be meaningless. If you are to go with ZIP code as a predictor, you must ensure that it is encoded as a multi-level categorical predictor. That could allow you to use ZIP codes as fixed effects, or as cluster() or frailty/random-effect terms to account for correlations within ZIP codes.

Second, as @AdamO notes in a comment, "The first 3 digits of a zip code doesn't mean anything." The first 3 digits of a ZIP code near where I live includes both wide-open suburban and dense urban localities, areas with some of the highest and lowest average wealth in the state, widely different education levels, and differences in access to transportation and to health-care facilities. If you can't get more detailed geographic and demographic data (e.g., from "ZIP +4" values combined with Census data), at least use the full 5-digit ZIP code.


US ZIP codes contain a lot of information. You can map the leading three digits of a (valid) ZIP code to the state where the ZIP is located. Here is official documentation from the IRS (see Publication 5594); it's also easy to find implementations of this mapping online so you don't have to do it yourself.

A "US state" variable is quite interpretable and will reduce the cardinality of "geography" to 50 states + the district of Columbia.

As @AdamO suggests, you can then link the state with a state-level socio-economic variables.

Whether to include this information in your model or not could depend in part on the actual treatment, focal explanatory variable and the outcome. People move and sometimes they move across states. If the variables of interest are "short-term", this may not be a concern. If they are long-term and you include geography-related variables, you'll have to think carefully how to interpret the geography effects (whether they are random or fixed).

I googled a bit for statistics about how often Americans move. The best I came across is this from the US Census Bureau but you can probably find more detailed information.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.