Often the data you need for analysis lives outside the survey — a panel source, a plan type, a client-assigned segment. If you have a table keyed by respondent ID, you can join it onto each respondent in the recode script using r.respondent_id.
The recipe
from survey import Recoder
r = Recoder(**globals())
CLIENT_APPEND = {
"respondent_00000": {
"respondent_source": "Client Panel",
"plan_type": "Commercial",
"client_segment": "Priority",
},
"respondent_00001": {
"respondent_source": "External Panel",
"plan_type": "Medicare",
"client_segment": "Standard",
},
"respondent_00002": {
"respondent_source": "Client Panel",
"plan_type": "Medicaid",
"client_segment": "Priority",
},
}
append_row = CLIENT_APPEND.get(r.respondent_id)
r.store_value("Respondent source", append_row["respondent_source"] if append_row else "Unknown")
r.store_value("Plan type", append_row["plan_type"] if append_row else "Unknown")
r.store_value("Client segment", append_row["client_segment"] if append_row else "Unknown")
How it works
CLIENT_APPEND is a lookup table: each key is a respondent ID and each value is the row of metadata to attach to that respondent. The script runs once per respondent, and r.respondent_id gives the ID of the one currently being processed.
CLIENT_APPEND.get(r.respondent_id) looks up that respondent's row. Using .get() rather than square brackets is deliberate — it returns None when there is no matching row instead of raising an error, so respondents missing from the append table do not crash the script.
Each store_value then writes one field, falling back to "Unknown" when no row matched. That keeps every respondent populated and makes the unmatched cases easy to spot and filter in reporting.
You can find respondent IDs in the raw data downloads, which is where you would build the lookup table from your external file.
Variations
The table is inlined here for clarity, but for a real study you would generate it from your client file rather than typing it by hand. A small script can read a CSV keyed by respondent ID and emit the CLIENT_APPEND dictionary, which you paste into the recode editor.
If you would rather quantify the match rate than hide misses behind "Unknown", store a flag as well:
r.store_value("Append matched", 1 if append_row else 0)
This lets you report how many respondents were successfully joined, which is a useful quality check on the append itself.