Module 2: Using Chatbots for Statistical Work

AI-Powered Coding and Data Analysis

Demo project: Download ZIP

GitHub repository

An instructor demonstration. You don’t need to follow along; the project is here if you want to try it afterward.

Chat interfaces

Pasting into a chatbot is the most common way to use AI:

  1. Paste context and a question into a chatbot.
  2. Read the answer.
  3. Paste the answer into the editor, adapt it, and test it.
  4. Repeat.

The copy-and-paste workflow

  1. Open notebooks/chat-demo.qmd and run the chunk.
  2. Copy the code into a chatbot and ask:
Can you help me visualize this?
  1. Paste the reply into a new chunk and run it.
  2. Repeat until it works.

Limits of chat

  • You copy and paste code, results, and context back and forth between your project and the chat window.
  • The chatbot never sees the data, the codebook, or the output.
  • It can’t run or test the code it writes.
  • The answer depends entirely on how clearly you ask.

Points to notice

If the chatbot plotted by Subgroup Category, did it notice that one category is spelled three ways (“Adequacy of Prenatal care”, “Adequacy of Prenatal Care”, “Adequacy prenatal care”)? It had no way to know. In Module 4, an agent reads the data file itself.