| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Re: geometric mean with svy (version 9.0)
The mean is saved within e(b).
What you are trying looks very inefficient from
two points of view.
1. It may be that you need each variable to be
logged for other reasons, but doing that just to
get the geometric mean can be made more efficient.
2. Creating a new variable just to hold each
geometric mean is also inefficient.
What you could do is something like this:
gen work = .
qui foreach v of varlist <whatever> {
replace work = ln(`v')
svy : mean work
mat b = e(b)
scalar `v'_gmean = exp(b[1,1])
noi di "`v'{col 40}" `v'_gmean
}
Nick
[email protected]
Ahmed A. Arif, MD., PhD
> I was able to figure out the answer. after running svy:mean on log
> transformed variables, I typed ereturn display,eform(gm) and it gives
> me geometric mean and sd. I tried using foreach syntax to automate the
> process but was not able to run the query.
>
> foreach x of varlist lnbenz lnchol {
> quietly svy:mean`x'
> gen gm`x'=exp(r(mean))
> }
>
> The problem here was r(mean) . Since I am running estimation i wasnt
> able to find any equivalence of r(mean). Here is list of scalar I got
> when I typed ereturn list
>
> . svy:mean lnbenz
> (running mean on estimation sample)
>
The> Survey: Mean estimation
>
> Number of strata = 13 Number of obs = 647
> Number of PSUs = 27 Population size = 1.5e+08
> Design df = 14
>
> --------------------------------------------------------------
> | Linearized
> | Mean Std. Err. [95% Conf. Interval]
> -------------+------------------------------------------------
> lnbenz | .2441459 .221858 -.2316921 .7199839
> --------------------------------------------------------------
>
> . ereturn list
>
> scalars:
> e(df_r) = 14
> e(singleton) = 0
> e(census) = 0
> e(N_pop) = 145459402.6002451
> e(N_psu) = 27
> e(N_strata) = 13
> e(N_over) = 1
> e(N) = 647
> e(N_strata_omit) = 0
> e(stages) = 1
> e(k_eq) = 1
> e(k_eform) = 0
>
> macros:
> e(cmd) : "mean"
> e(prefix) : "svy"
> e(cmdname) : "mean"
> e(command) : "mean lnbenz,"
> e(title) : "Survey: Mean estimation"
> e(vcetype) : "Linearized"
> e(estat_cmd) : "svy_estat"
> e(varlist) : "lnbenz"
> e(predict) : "_no_predict"
> e(wtype) : "pweight"
> e(wvar) : "wtsvoc2y"
> e(wexp) : "= wtsvoc2y"
> e(vce) : "linearized"
> e(su1) : "sdmvpsu"
> e(strata1) : "sdmvstra"
> e(properties) : "b V"
>
> matrices:
> e(b) : 1 x 1
> e(V) : 1 x 1
> e(_N_subp) : 1 x 1
> e(V_srs) : 1 x 1
> e(_N) : 1 x 1
> e(error) : 1 x 1
>
> functions:
> e(sample)
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/