Everyone searches for help
- Professional programmers and applied economists constantly look things up.
- You are not expected to memorize every command and option in Stata.
- You are expected to learn how to:
- Search effectively
- Read help pages and online answers
- Adapt examples safely to your own work
Today we’ll focus on three sources:
- Built-in Stata help and documentation
- Online help (Stata docs, Statalist, Stack Overflow, blogs)
- Large Language Models (LLMs) like ChatGPT
Built-in Stata help
Before you open a browser, try Stata’s own tools.
help for a specific command
* open the help file for summarize
help summarize
- Shows syntax
- Lists options
- Often includes examples at the bottom (pay attention to these)
If you know roughly what you want but not the exact syntax (e.g., xtile, merge, collapse), help is your friend.
search for related commands
* search for commands related to "percentile"
search percentile
This looks through:
- Command names and descriptions
- Installed help files
- Sometimes user-written packages
You can click on entries in the Viewer to open help pages.
Habit to build: when you see a new command in lecture or sample code, run
help commandnameand skim the help file.
Good targets for Stata help
Places where help/search are especially useful:
- Basic data management commands
help generate,help replace,help egenhelp merge,help append,help collapse
- Graphics
help graph,help histogram,help twoway
- Common analysis commands
help regress,help ttest
When debugging, also consider help r(###) for error codes.
Online Stata resources
Some high-value websites:
- Official Stata documentation
- Mirrors the
helpsystem - Searchable on the web
- Very precise, includes lots of examples
- Mirrors the
- Statalist
- Long-running forum where people ask detailed Stata questions
- Often your exact error or task has been discussed
- Stack Overflow / Cross Validated
- More general programming/stats Q&A
- Stata content mixed in with R, Python, etc.
How to search effectively
When you go to Google (or DuckDuckGo, etc.), your goal is to express your problem in search-engine language. One thing I’ve learned in 10 years of teaching is that students often struggle with developing useful prompts or key-words for searches. The returns you get from a search are only as good as what you ask it to search for.
Get the vocabulary right
Include:
stata- The command (if you know it)
- A short phrase about what you want
- Or the error code
Good examples:
stata collapse mean by groupstata merge 1:m not uniquely identifiedstata graph bar mean by groupstata r(111) variable not found
Less good:
collapse not workingmissing unique identifierhow do I write bar graph code?stata help please
Avoid extra words
Start simple:
stata reshape wide long examplestata -999 missing value
You can always add words if results are off.
Reading results: help sites, forums, blogs
When you click a search result:
Help sites / Q&A (Statalist, Stack Overflow)
- Read the question carefully
- Does it sound like your situation?
- Same command? Same type of data?
- Look at the setup
- Are they reshaping wide-to-long or long-to-wide?
- Are their variable names similar?
- Check the age
- Stata syntax is fairly stable, but a 2003 post may reference ancient versions
- Check the top answers
- On Stack Overflow, higher-voted answers are usually better
- On Statalist, look for answers from known experts
- Glance at the comments
- Sometimes corrections or caveats are discussed there
- Test and modify the example
- Never copy-paste blindly
- Adapt variable names and paths to your data
- Confirm that the code does what you think it does
Blog posts and tutorials
- Scan for the section you need
- Use your browser’s
Find(Ctrl+F/Cmd+F) - Search within the page for “merge”, “collapse”, etc.
- Use your browser’s
- Focus on code blocks
- They usually contain the key ideas
- Try to understand them, then rewrite into house style before using
Testing and integrating code you find
When you grab code from online (or from an LLM):
- Try it on a small subset
- Add
in 1/50or a restrictiveifto avoid damaging your whole dataset
- Add
- Watch for paths and filenames
- Change
"C:\Users\someone\Downloads\mydata.dta"to your project paths and globals
- Change
- Check for version issues
- Some commands/options only exist in newer versions of Stata
- If you see
versionlines in example code, pay attention
- Check that it respects course rules
- Doesn’t overwrite raw data
- Keeps data and code separated
- Fits into your project structure (globals, logs, etc.)
- Rewrite in your own words and style
- Rename variables to match the rest of your project
- Add comments in your own language
- Use house-style alignment and headings
Using LLMs as a help resource
LLMs (ChatGPT, Copilot, etc.) are like a very fast, sometimes-wrong search engine that can write code.
- They are good at:
- Explaining error messages
- Suggesting possible approaches
- Pointing out obvious bugs in short code snippets
- They are not always:
- Correct about Stata syntax
- Efficient in their approach to coding
- Aligned with our house style
- Using the same workflow (projects,
project.do, etc.)
How to ask good questions to an LLM:
Include:
- A short description of your goal
- A minimal code snippet (10–20 lines)
- The exact error message or unexpected output
- Any constraints (e.g., “Stata 17, cannot use user-written packages”)
Example prompt:
“I’m using Stata 17. I’m trying to merge household-level data into plot-level data. Here’s my code and the error
not uniquely identified. Can you help me understand what’s wrong?”
Then:
- Check its explanation against your understanding of
merge(1:mvsm:1, keys, etc.) - Test any suggested fix on a small subset
- Rewrite any accepted code into your own
.dofile with house style
Remember the forklift at the gym analogy: don’t have the LLM do all your “lifting” for you.
When and how to ask humans
Sometimes the fastest path is to ask a person:
- Classmates / study groups
- Great for “am I doing this in a reasonable way?” type questions
- Slack
- Include a short description and a small, well-formatted code block
- Mention the exact error message
- Office hours
- Bring your
.dofile - Be ready to walk through what you’ve already tried
- Bring your
A good question includes:
- What you’re trying to do
- What you expected to happen
- What actually happened (including errors)
- What you’ve already tried based on help files / Google / LLMs
- The file name and exact lines of code that are a problem
- Before you ask for help, push your commits so the person can actually help you!
Summary: a help-searching workflow
When you’re stuck:
- Try Stata help
help commandsearch keyword
- Search the web
- Include
stata+ command + a keyword or error
- Include
- Read answers critically
- Understand before copying
- Adapt to your project and house style
- Test on small subsets
- Use LLMs as assistants, not oracles
- Ask humans (Slack, office hours) with a clear, specific question
The goal is not just to “find the code” but to build your own library of patterns for solving problems in Stata.