LLMs are quite capable at coding tasks, especially in the languages python and R, for which the most online resources are available. LLMs can write, edit, modify, translate, or debug snippets of code based on instructions in plain English (or other natural languages). Moreover, they can act as tutors when using new libraries, functions, or even programming languages that the user is not very familiar with by quickly generating output that shows what libraries and functions are needed for specific types of operations or what syntactic structures to use in a given programming language. This allows the human programmer to consult the LLM and weave together code from many different snippets generated by it.

The reasons why LLMs are so proficient at coding include the following: There are vast repositories of code available online that are included in their training data, for example from GitHub. The syntax of computer code seems to be relatively easy to learn for these systems. Moreover, the AI labs producing cutting-edge LLMs themselves benefit from the code generation abilities of these systems, which provides them with strong incentives for improving these capabilities. In fact, coding may be one of the areas where current LLMs lead to the greatest productivity gains: Peng et al. (2023)Peng, S., Kalliamvakou, E., Cihon, P., and
Demirer, M. (2023). The impact of AI
on developer productivity: Evidence from GitHub Copilot.
report a controlled experiment in which programmers using OpenAI-powered GitHub Copilot completed their assignments on average 55.8% faster, amounting to a 126% productivity increase.
In the OpenAI ecosystem, Advanced Data Analysis has made the use of ChatGPT Plus for coding tasks in the programming language python even more convenient, as it can write code, execute it, learn from it, write follow-up code, and display the requested results. It also allows users to upload code, ask for specific modifications, and download it again to continue work on it. GitHub Copilot offers seamless integration into Visual Studio and several other integrated development environments for programmers, and works for many different programming and markup languages.*While writing this paper, I used ChatGPT
Plus to write LaTeX code. I asked it
how to define the boxes around the
sample prompts throughout the paper in a way
that they are visually appealing and break
across pages, and I asked it to produce
Table in LaTeX based on the table
of contents for section 3. I used
GitHub Copilot when working on the replication code
for this section.
Meta's Code LlaMA, released in August 2023, offers powerful coding assistance on an open-source basis.

Writing code

I just provided a short "Go ahead'' to continue the generation of the program:

I also attempted to simulate the Ramsey model. The LLM correctly generated code to simulate the path of consumption and capital for given initial conditions, but it did not manage to solve for the correct starting point for consumption, even after I added a reminder to my prompt that initial consumption needs to lie on the stable arm of a saddle-path stable system.

Explaining code

Whereas the previous example wrote code based on English language instructions, LLMs can also do the reverse and explain what a given piece of code does in plain English, akin to a tutor. The following examples demonstrates this use case:

Translating code

LLMs can also convert code in one programming language into another language, for example to port a project to another platform or to integrate code snippets found in an online coding forum such as StackExchange that is in the wrong language.

The following prompt, building on the preceding conversation, provides an example:

Debugging code

One of the most frustrating parts of programming is to debug code. LLMs also exhibit useful capabilities in this domain. They can not only help to interpret error messages but also verify code.
In my first example, I simply pasted a typical error message from python that is obtained when the user forgets to import a library, without any further instructions:

The next example, building on the python function two examples earlier but with an error introduced, illustrates how LLMs can help to catch mistakes such as typos in code:

More generally, LLMs are also sometimes able to detect when indices are mixed up, and to provide advice when one describes the ways in which a program malfunctions. They are less capable at detecting high-level mistakes in the algorithms underlying code — for this, human debugging is usually still required.

From: Generative AI for Economic Research: Use Cases and Implications for Economists
by Anton Korinek, Journal of Economic Literature, Vol. 61, No. 4, December 2023.
Copyright (c) by American Economic Association. Reproduced with permission.