# ChatGPT prompts + code for economists

This is a scratchpad of sorts for economists wanting to use ChatGPT.

Some of my most used prompts:

- Rewrite this five times varying the length, structure, and sentence order:

# DAGs

Scott Cunningham prompted ChatGPT with this:

Create a directed acyclic graph DAG in latex using tikz of an instrumental variables design. Label the IV with “Z”, the treatment “D”, the outcome “Y”, and the unobserved confounder (with dashed lines) “U”. Then have an error term “varepsilon” pointing to the outcome but from the top right direction. Have U be above D and Y in between them. Have Z be top left of D

It gave him this response:

Which he then put into TeXShop:

Giving him this:

# Structural estimation

Today’s fun GPT+Econ exercise: asking it to develop example code for structural estimation from a description + latex equations. The goal was to get it to give me a function that could estimate an approximate mixed-logit model. Step 1: ask GPT-4 how best to structure my prompt.

Step 2: Ask for a verbal algorithm. I wrote this quickly, just directly copying three equations from my JMP, and left in a subscripting typo (the “t” subscript in e_{t} isn’t defined)

First-try result seems pretty good (more after screenshot cuts off)! It made some reasonable decisions that I wasn’t clear about, so I had to iterate a couple of times about order of operations and things. Then (Step 3) I asked it to convert the algorithm to code

The code also had a couple of minor bugs (hallucinated an IV regression package in python) but only took 2 minutes to fix and it got it right on the next try. Also constructed e_t in Step 3 correctly even though my subscript was wrong!

*First published May 17, 2023*