Skip to contents

Builds a set of `FGAgent`s by sampling rows from a haven-coded survey file and turning labeled variables into demographics/survey-responses driven personas. Works with any Stata (.dta), SPSS (.sav), or SAS files that have variable labels.

Usage

create_agents_from_survey(
  n_participants,
  survey_path,
  demographic_vars = NULL,
  survey_vars = NULL,
  llm_config = NULL
)

Arguments

n_participants

Integer number of participants (excludes the moderator).

survey_path

Character path to survey file (e.g., .dta, .sav files)

demographic_vars

Character vector of variable names to use as demographics. If NULL, attempts to auto-detect common demographic variables.

survey_vars

Character vector of variable names to use as survey responses. If NULL, auto-detects by variable labels or names. No dataset is hardcoded.

llm_config

Optional `LLMR::llm_config` for all agents. If `NULL`, a small OpenAI config is created.

Value

A list of `FGAgent` objects (participants + moderator).

Examples

if (FALSE) { # \dontrun{
# Use ANES data
anes_path <- "path/to/anes_timeseries_2024_stata.dta"
agents <- create_agents_from_survey(6, anes_path)

# Specify particular variables
agents <- create_agents_from_survey(
  n_participants = 4,
  survey_path = anes_path,
  demographic_vars = c("age", "gender", "education", "race"),
  survey_vars = c("party_id", "ideology", "vote_intent")
)
} # }