Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: correct egen command to calculate means - please help

From   Ophelie Desmarais <>
Subject   st: correct egen command to calculate means - please help
Date   Wed, 18 May 2011 19:34:33 +0200

Dear Statalist,

I have tried to find an answer for this on the web but to no avail.

Simplified, I have following dataset where the unit of observation is
the industry (IndustryID) with the respective revenue.

IndustryID, ParentIndustryID, Revenue

The ParentIndustryID links to IndustryID and reflects the hierachical
structure of the industries. For each industry, I want to add a
variable reflecting the mean income of the ParentIndustryID. How do I
do this in Stata? In Excel, this would be simply using AVERAGEIFS.
egen MeanRevenueParent=mean(Revenue), by(ParentIndustry) obviously
does not give the right mean. In terms of pseudo code, this should be
something like:

MeanRevenueParent = Mean(Revenue) WHERE ParentIndustry=IndustryID

Could anyone help me out? I don't want to switch around with Excel all the time.

Thanks a lot,

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index