Statalist The Stata Listserver

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

Re: st: Finding median when using svy

From   "Jesia Berry" <>
To   <>
Subject   Re: st: Finding median when using svy
Date   Thu, 08 Mar 2007 13:27:45 +1030

Yes, doing it the way I previously suggested doesn't apply the weights,
but the table command does have a 'weight' option that you can use:

 table hssex [pweight= wtpfhx6] , c(median  hsageir count hsageir) row

If you are not reporting the standard errors, this command should
suffice, however, it does not take into account the clustering and
stratification. The 'Survey data' stata manual says " it is important to
use sampling weights in order to get the point estimates right. We must
consider the weighting, clustering, and stratification of the survey
design to get the standard errors right." 

My understanding is that if clustering is not taken into account, it
does not affect the point estimate (eg. the median is correct) but it
underestimates the standard errors resulting in a narrowing of the width
of the CIs and an overstating of the statistical significance. Ignoring
stratification will lead to an overestimating of the standard errors.
While the biases from ignoring stratification and clustering run in
directions, researchers have found that ignoring sample design
typically results in standard error estimates which are too small (Kish,
L. and M. Fraukel, Balanced Repeated Replications for Standard Errors,
Journal of the American Statistical Association, 65(331), 1071-93,

 -pctile- was previously suggested to be used to calculate medians in
survey data (see Statalist archives below), although it looks like
-pctile- doesn't account for survey design either. There was no response
to Ssu Weng's request.

Subject st: RE: survey median estimator
Date: Thu Nov 13 19:20:01 2003
The Nov. 12, 2002 Statalist posting (Clyde Schechter) suggests using
-pctile- and pweights to estimate the median with survey data. However,
I would like standard errors that account for the survey design.
Does anyone know of a way to do this?  Thank you in advance.
Ssu Weng, NM Dept. of Health, Santa Fe, NM, USA

Subject   st: RE: survey median estimator 
Date   Mon, 18 Nov 2002 10:54:52 -0500 

As Nick Cox points out, -egen- can't be combined with pweights.  But
-pctile- does accept pweights.  Unfortunately, -pctile- is not
compatible with -by-.  One possibility would be to hack the code of
-pctile- and make
it byable--I haven't looked to see how easy or hard that would be.  
Another possibility is to loop on the values of the grouping variable
"type."   The resulting medians should be properly estimated. The
standard errors would probably be incorrect because -pctile- will not
account for
the stratification and clustering--but based on the wished for model of
-egen median=median(edpct) if salquart==3, by(type)- that is probably
not of concern here. Hope this helps.

Clyde Schechter


>>> ucb_gal <> 8/03/2007 10:51 am >>>
doing it that way doesn't apply the weights, right?  i thought you had
to use the prefix "svy:" to apply the survey settings.

in which case, table doesn't work with svy...

----- Original Message ----
From: Jesia Berry <>
Sent: Wednesday, March 7, 2007 3:45:46 PM
Subject: Re: st: Finding median when using svy

As an example, to get the median age by sex, you can use the 'table'

nhanes3 dataset available at 

use nhanes3.dta
svyset [pweight= wtpfhx6], strata(sdpstra6) psu(sdppsu6)
table hssex, c(median  hsageir count hsageir) row

Jesia Berry
Research Officer
Research Centre for Injury Studies
(and AIHW National Injury Surveillance Unit)
Flinders University
GPO Box 2100
Adelaide SA 5001
Tel: +61 8 8201 7626
Fax: +61 8 8374 0702 

>>> ucb_gal <> 8/03/2007 4:47 am >>>
I'm using household survey data and using the svyset settings.

I can't figure out how to find the median value of a variable while
using svy:

I can theoretically use:

svy: tab variable

but my dataset is way to big and the variable has way to many values
attempt this.

Any suggestions?

The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing. 

*   For searches and help try:
*   For searches and help try:

The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing. 

*   For searches and help try:
*   For searches and help try:

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