[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Weighted averages

From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: Weighted averages
Date   Wed, 26 Sep 2007 11:26:50 +0100

Pavlos says weighted averages, but his example refers
to geometric means, and no weights are in sight.

I'll pay attention to the action, and not the words.

First off, geometric means make no sense unless all
values are positive, and I'll assume that is taken care

Geometric means are available directly once you install
-egenmore- from SSC. Then you can go

egen var1_gmean = gmean(var1), by(country)

If this weren't true, there would still be no real problem:

egen var1_gmean = mean(log(var1)), by(country)
replace var1_gmean = exp(var1_gmean)

The crucial detail here, often overlooked, is that
-egen, mean()- feeds on an expression, here -log(var1)-,
which can easily be more complicated than a variable name.

We just need to exponentiate afterwards.

I take it that Pavlos just needs to use this variable
downstream of this one line (or two lines).

[email protected]

Pavlos C. Symeou

I have a panel dataset consisting of 25 years and 150 countries. I have
a variable (var1) whose geometric mean I estimate for every country
separately. That is, I use "bysort country: gmeans var1". This gives me
150 different geometric means; one for each country. I want to divide
var1 with its weighted average for each country for each year and
generate a new variable var1_weighted with the new values but I need a
command that can do this automatically, considering the time required to
do this one by one.

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index