Number of quarters without a recession since the last recession

For an ongoing project about the drivers of recessions for a large cross-section of countries observed between 1990 and 2022, I have to compute the number of quarters without a recession since the last recession. The paper is available below:

Aizenman, J., Ito, H., Park, D., Saadaoui, J, & Uddin, G. S. (2025). Global Shocks, Institutional Development, and Trade Restrictions: What Can We Learn from Crises and Recoveries Between 1990 and 2022? (No w33757). National Bureau of Economic Research.

Now, let me show you how to do it with Stata. I used ChatGPT 4.5 and allowed the web search. Allowing the web search is really a game changer for Stata coding as it allows you to search on the Stata forum and other very good Stata resources over the web. After some iterations (five or six), I arrived at a satisfactory solution. In particular, ChatGPT had some difficulties to “understand” that I considered that the begining of the sample was considered as “recession-free” quarter for each countries in the panel dataset.

First, let us take a look at the data:

Then, flag the non-recession periods with:

* 1. Flag non-recession (1 if RGDP_p ≠ 1)
bysort imfcode (period): gen byte nonrec = (RGDP_p != 1)

Then create reset groups at each recession:

* 2. Create reset groups at each recession
bysort imfcode (period): gen byte grp = sum(RGDP_p == 1)

Finally, accumulate the number of quarters without a recession since the last recession:

* 3. Count nonrec consecutively within each country × grp
bysort imfcode grp (period): gen int cum_nonrec = sum(nonrec)

label var cum_nonrec ///
 "Non-recession count starting at each new group (recession reset)"

That’s all for today! Hopefully, this will be helpful for some of your research projects.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.