Hi everyone,
Hope you're well
In my research, I focus on IPOs since 2000 (no panel data). My dataset consists of one line per IPO incl. multiple information (e.g., financials, industry, issue year, etc.).
I want to calculate the averge industry revenue in the pre-IPO year. In a simplified version, my dataset looks like the table below.
I calculated the column "Avg. Industry Revenue in IPO Year" with the following command:
egen avg_industry_revenue_IPO_year = mean(Revenue), by (Industry IPO Year)
However, I do not find a proper solution to calculate the last column ("Avg. Industry Revenue in Year Before IPO). In excel, I would do it with the following command:
Averageifs(Revenue column; Industry Column; Industry; IPO Year; Year Before IPO)
As IPO Year and Year Before IPO are two different columns, I do not know to calculate this in Stata. I want to find out the average industry revenue in the year before the IPO (i.e., what was on average the revenue of competitors that went public in the year before the IPO of the observation?)
Looking forward to your support
Thank you very much!
Best,
Michael
Hope you're well

In my research, I focus on IPOs since 2000 (no panel data). My dataset consists of one line per IPO incl. multiple information (e.g., financials, industry, issue year, etc.).
I want to calculate the averge industry revenue in the pre-IPO year. In a simplified version, my dataset looks like the table below.
I calculated the column "Avg. Industry Revenue in IPO Year" with the following command:
egen avg_industry_revenue_IPO_year = mean(Revenue), by (Industry IPO Year)
However, I do not find a proper solution to calculate the last column ("Avg. Industry Revenue in Year Before IPO). In excel, I would do it with the following command:
Averageifs(Revenue column; Industry Column; Industry; IPO Year; Year Before IPO)
As IPO Year and Year Before IPO are two different columns, I do not know to calculate this in Stata. I want to find out the average industry revenue in the year before the IPO (i.e., what was on average the revenue of competitors that went public in the year before the IPO of the observation?)
Looking forward to your support

Thank you very much!
Best,
Michael
Firm | Revenue | IPO Year | Year before IPO | Industry | Avg. Industry Revenue in IPO Year | Avg. Industry Revenue in Year Before IPO |
A | 67 | 2011 | 2010 | Technology | 78.5 | |
B | 90 | 2011 | 2010 | Technology | 78.5 | |
C | 97 | 2011 | 2010 | Industrial | 98.0 | |
D | 99 | 2011 | 2010 | Industrial | 98.0 | |
E | 48 | 2012 | 2011 | Technology | 41.0 | 78.5 |
F | 34 | 2012 | 2011 | Technology | 41.0 | 78.5 |
G | 14 | 2012 | 2011 | Industrial | 41.5 | 98.0 |
H | 69 | 2012 | 2011 | Industrial | 41.5 | 98.0 |
I | 12 | 2013 | 2012 | Technology | 15.5 | 41.0 |
J | 19 | 2013 | 2012 | Technology | 15.5 | 41.0 |
K | 53 | 2013 | 2012 | Industrial | 34.0 | 41.5 |
L | 15 | 2013 | 2012 | Industrial | 34.0 | 41.5 |
M | 71 | 2014 | 2013 | Technology | 58.5 | 15.5 |
N | 46 | 2014 | 2013 | Technology | 58.5 | 15.5 |
O | 36 | 2014 | 2013 | Industrial | 64.0 | 34.0 |
P | 92 | 2014 | 2013 | Industrial | 64.0 | 34.0 |
Comment