Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: geometric mean saved results

From   "Steichen, Thomas" <>
To   <>
Subject   st: RE: RE: geometric mean saved results
Date   Wed, 18 Sep 2002 16:25:14 -0400

JL Greig writes:

> I apologize--let me provide a few more details.  The
> previous was actually part of a larger little program
> which essentially used a portion of a large database
> (gender==1), displayed a description of the ranksum to
> be performed, quietly tabulated the arithmetic,
> geometric, and harmonic means of a continuous variable
> then attempted to ranksum test for differences in the
> geometric means of that continuous variable across
> categories of categorical variables noted as `1' (var1
> var2), as in the below, full program.  There is only
> one observation of the continuous variable per id.  
> capture program drop taball
> program define taball
> 	while "`1'" ~="" {
> 	use database1, clear
> 	keep if gender==1
> 	display "ranksum GEOMETRIC MEAN fp3 by `1' "
> 	sort `1'
> 	quietly means fp3
> 	local `gmeanfp3' = r(mean_g)
>         ranksum `gmeanfp3' if `1'~=9999, by(`1')
> 		mac shift
> 	}
> end
> taball var1 var2
> I can report the geometric means of my continuous
> variable across categories of var1, etc., but I want
> to test if there are differences in these geometric
> means of the continuous variable between those
> categories of var1, if that makes sense.  
> I know that the local macro generates a constant, and
> thus the above would not work, however I can't think
> of alternatives at this point.
> Again, any suggestions would be appreciated.

Consider rewriting your code as:

capture program drop taball
program define taball
	use database1, clear
	keep if gender == 1

	tempvar log_fp3 mlog_fp3 gm_fp3

	while "`1'" ~= "" {	
		display "ranksum GEOMETRIC MEAN fp3 by `1'"
		sort `1'

        * manually generate geometric means within levels of `1'
		qui gen   `log_fp3' = log(fp3)
		qui egen `mlog_fp3' = mean(`log_fp3'), by(`1')
		qui gen    `gm_fp3' = exp(`mlog_fp3')

          ranksum `gm_fp3' if `1' ~= 9999, by(`1')

		drop `log_fp3' `mlog_fp3' `gm_fp3'

		mac shift

taball var1 var2

Having done that, you should note that using the geometric
mean is no different from using the mean.  Ranks are 
preserved by this transformation, so the statistics in 
-ranksum- will be identical. 

Also, I would be concerned of the effect of using the 
"if `1' ~= 9999" qualifier for -ranksum- while not enforcing
it on the calculation of the geometric means.

Overall, It seems more likely to me that you must want the geometric
means of fp3 computed for levels of a different categorical variable
(not `1'), as the above approach seems to accomplish nothing useful.

CONFIDENTIALITY NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information.  If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system.  Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

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