Statalist


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

Re: st: standard error of prediction (with weights)


From   Steven Samuels <sjhsamuels@earthlink.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: standard error of prediction (with weights)
Date   Tue, 16 Sep 2008 12:59:07 -0400

On Sep 16, 2008, at 6:01 AM, Hans Olav Melberg wrote:
When using the following:

logit c6 $x6 [pweight=w2all], or
mfx compute, at(gateway=0)

I get:
Marginal effects after logit
y = Pr(c6) (predict)
= .00067379
etc

How do I find standard error of the predicted value?

The predicted value (y = 0.00067) is calculated using weights as well
as at the mean of the variables, except for one variable which is 0.
I found some commands that might be useful, but they did not accept weights.

The code below is shorter than the previous version. Hans didn't say he had survey data. If not, then he can skip -svyset- and the -svy- prefixes and just add [pweight] statements to the -mean- and -logit- commands. He asked for the standard error of prediction, but - adjust- creates standard errors for the linear predictor and translate the resulting CI to the probability scale. I think this is the proper approach. My mail program adds invisible spaces to the text; be sure to zap gremlins before running this code.

Aside: Observe that

sysuse auto
logit foreign mpg weight trunk
adjust //hold all predictors at their means

produces a predicted probability 0f 0.159. The average prediction, also the sample proportion, is 0.297. Thus setting covariates to their means can give a very misleading result

-Steve

*****************Code begins *****************

// Program to created adjusted prediction and CI for weighted data,
// holding one variable at a specified value and the others at their weighted means
//
// For the auto data, the command will be: svy: logit foreign rep78 mpg weight trunk
// -adjust- will be called to predict the probability for rep78=3 and other predictors held at their means

sysuse auto,clear
svyset _n [pweight=length]
local rhs mpg weight trunk // variables to be held at their means ///

// Create weighted means: saved in _b[varname]
quietly svy: mean `rhs'

/// build up the -adjust- command
local l_adj " "
foreach v of varlist `rhs' {
local lv "`v' = `=_b[`v']' "
local l_adj `l_adj' `lv'
}

svy: logit foreign `rhs' rep78

// Call -adjust-
adjust "`l_adj'" rep78=3, pr ci

**************Code Ends**********************


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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