Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: holding variables to weighted means with prvalue


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: holding variables to weighted means with prvalue
Date   Wed, 11 Aug 2010 15:49:25 -0400

Yes, -margins- is best if you have Stata 11 (note the spelling).

Steve

On Wed, Aug 11, 2010 at 1:18 PM, Christine Brickman
<[email protected]> wrote:
> Thanks, Steve.
>
> Moments ago, I just discovered I can accomplish this with margins, which is new
> to Stata 11, I believe.
>
>
> svyset [pweight=weight]
>
> svy: regress i.male [list of remaining variables]
>
> margins i.male
>
> If you weight the data in the regression command, margins retains the weight.
> But there’s also an option to turn it off if you choose.
>
>
>
> ----- Original Message ----
> From: Steve Samuels <[email protected]>
> To: [email protected]
> Sent: Wed, August 11, 2010 12:06:24 PM
> Subject: Re: st: holding variables to weighted means with prvalue
>
> 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
> [email protected]
> 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
> <[email protected]> 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/
>
>
>
>
>
> *
> *   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/
>



-- 
Steven Samuels
[email protected]
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax:    206-202-4783

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index