Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: holding variables to weighted means with prvalue


From   Steve Samuels <sjsamuels@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: holding variables to weighted means with prvalue
Date   Wed, 11 Aug 2010 12:06:24 -0400

Not with -prvalue-.  Some of the holding specifications, like -max-
and -min- have no survey meaning.  So, apparently, none of them do.

Below is a do file which uses -adjust- which creates predictions at
the observed values for all covariates, holding others at their
weighted means.  It optionally plots the adjusted predictions.

Steve

Steven Samuels
sjsamuels@gmail.com
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax:    206-202-4783


On Wed, Aug 11, 2010 at 10:43 AM, Christine Brickman
<cbrickman79@yahoo.com> wrote:
> I want to compute predicted values while holding variable at their weighted
> means.  Even though I'm weighting the regression, STATA is holding the variables
>
> at their unweighted means.  Here's my syntax:
>
> svyset [pweight=weight]
> svy: regress [VARLIST]
> forvalues i = 0(1)1 {
>                 prvalue, x(male=`i')
>     }
>
> Is there a way to hold all variables except male at their weighted means?
>
> Thanks!
> Christine

/**************************START CODE***********************************/
/***************************************************************************
This do file e creates predicted values from survey regression
 which vary in one predictor at a time, holding others at their
estimated population means.
 Also computed are upper and lower confidence interval endpoints for
the prediction.
 An optional graphics section plots predictions and CI endpoints for
each variable against that variable.
 ****************************************************************************/
 di c(level) // current confidence level . To change, -set level-.

sysuse auto,clear
svyset _n [pweight=rep78]

/***************************************************************************
Define a predictor list for the right-hand-side of the svy: logit equation
 ****************************************************************************/
local rhs mpg weight trunk

svy: mean `rhs' //outputs weighted means in _b[varname]

/***************************************************************************
For each varying predictor, build up the -adjust- command.
For the adjusted predictor which varies mpg, the adjust command starts:

 "adjust weight = 2941.106382978724 trunk = 13.73191489361702"
 ****************************************************************************/

foreach v of varlist `rhs' {
local less : list rhs -v //Remove variable v from the rhs
local list_`v' " "

foreach w of varlist `less' {
local lw "`w' = `=_b[`w']'" // e.g. "weight = 2941.106382978724"
local list_`v' `list_`v'' `lw' // Augment the list
}
 di "`v'"
 di "`list_`v''"
}

/***************************************************************************
 SET UP THE -SVY: REG
****************************************************************************/
 svy: reg foreign `rhs'

/***************************************************************************
For each predictor variable v (e.g. mpg), use -adjust- to compute:
 pred_v : linear prediction
 se_v : the se of the linear prediction
T
 llim_v : lower 95% confidence interval endpoint
 ulim_v : upper 95% confidence interval endpoint
 ****************************************************************************/

 foreach v of varlist `rhs' {
adjust "`list_`v''" , g(pred_`v' se_`v') se //The key line

gen llim_`v' = pred_`v' - (invttail(e(df_r), (1- c(level)/100)/2))*se_`v'
gen ulim_`v' = pred_`v' + (invttail(e(df_r), (1- c(level)/100)/2))*se_`v'

label var pred_`v' "Predicted Prob"
label var llim_`v' "Lower CI"
label var ulim_`v' "Upper CI"
}
// save (choose a new name)

// Optional Graph Module
/*
foreach v of varlist `rhs' {
twoway scatter pred_`v' llim_`v' ulim_`v' `v', msymbol(o o o)
title("Plot of Prediction against `:variable label `v''" "Other
Predictors at their Mean") note("Program: `pname'. Data: ")
saving(graph_`v', replace)
}
*/
/************************END CODE ***********************************/

*
*   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   |   Site index