Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

RE: st: replacing with mean

From   Nick Cox <>
To   "''" <>
Subject   RE: st: replacing with mean
Date   Thu, 2 Dec 2010 08:42:01 +0000

No; it is not necessary as you could calculate the means in Mata. But Michael's suggestion will typically be easier to work with. 

-compress- usually gives extra memory painlessly. 


Fabio Zona more thing.... is it necessary to generate a new variable of the mean? This consumes memory in stata..

Michael N. Mitchell

   Will this do the trick?

egen missrev = mean(revenues), by(industry)
replace revenues = missrev if missing(revenues)

On 2010-12-01 10.31 PM, Fabio Zona wrote:

> I have a set of industries, with a different number of firms in each industry; per each firm I have a value, say it be Revenues
> Industry         Firm         Revenues
> A                  1            100
> A                  2            150
> A                  3          missing1
> A                  4            120
> B                  5             80
> B                  6            130
> B                  7          missing2
> ..
> I need to replace the missing value of Revenues with the mean of the Revenues within the same industries (For example, missing1 for firm 3, needs to be replaced with the mean of the values 100, 150, 120, that is, with the mean of the revenues of other firms 1, 2 and 4 which belong to the same industry to which firm 3 belongs).
> I need to do this hundreds of time.
> How can I do it easily?

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index