Agentic AI for Economists/

Run your first .do file

Lesson 3 of 3

Run your first .do file

Now you will write a real analysis script and execute it. The agent will create a .do file — a script in the language used by StataTM — and run it through dodo, which compiles it to SQL and executes it on DuckDB.

Stata is a registered trademark of StataCorp LLC. This platform is not affiliated with or endorsed by StataCorp.

The pipeline

When you run a .do file, this happens:

  • dodoc compiles the .do file to SQL (DuckDB dialect)
  • DuckDB executes the SQL query
  • You see the result as a table
  • This is deterministic — same input, same output, every time. No model involved in the execution. The agent writes the code; dodo runs it.

    Your task

  • Ask the agent to write a .do file that summarizes trade values by country.
  • The file should go in src/summary_by_country.do (analysis scripts belong in src/).
  • Ask the agent to run it.
  • Check the output — does it make sense? Three countries, sorted by trade value.
  • `` Prompt to copy: Write a .do file at src/summary_by_country.do that imports data/trade_data.csv, collapses trade_value by country, sorts by trade_value, and lists the result. Then run it. `

    What the .do file should look like

    `stata * Summarize trade data by country import delimited "data/trade_data.csv", clear collapse (sum) trade_value, by(country) sort trade_value list `

    Note: the path to the CSV is relative to the workspace root, not to the src/ directory. The dodo tool runs from the workspace root.

    Checkpoints

  • Script created — A .do file exists at src/summary_by_country.do.
  • Script ran — The agent called run_do_file and it returned successfully.
  • Results correct — The output contains Poland, Hungary, and Germany with the right totals.
  • Data untouched — The original data/trade_data.csv` was not modified (good practice: never overwrite source data).