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: Predicted values where a subgroup of variables are held constant


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Predicted values where a subgroup of variables are held constant
Date   Fri, 18 Mar 2011 14:28:15 +0000

Looking at this again, it's very likely that Michael got confused. Focus on this code: 

foreach var of local varlist `pred' {
	sum `var', meanonly
	replace `var' = r(mean)
} 

There are two syntaxes being confused here. 

1. 

foreach var of local <whatever> { 

} 

2. 

foreach var of varlist <whatever> { 

}

Now Michael's call would look to Stata like an attempt at syntax 1. But all depends on whether the locals -varlist- and -pred- are defined and what they contain. 

As Michael says nothing about what was defined upstream of the code he cites, it is difficult to comment further, except to advise careful study of the help for -foreach-. 

As Tim's post implies, there is, however, no need to do this yourself given -margins- and -adjust-. 

Nick 
[email protected] 

Tim Wade

Is something like this what you are looking for?

sysuse auto.dta
regress price  mpg gear_ratio length weight
*price with covariates at means and mpg at 20
margins, at((mean) _all mpg=20)
*generate predicted results at means for each observation of mpg
adjust gear_ratio length weight, gen(yhat)
*confirm result is same for margins
list yhat if mpg==20

On Thu, Mar 17, 2011 at 5:11 PM, Michael Harhay

> I want to do a straightforward xb prediction after an OLS regression
> on a patient population, but for a subgroup of variables I want to use
> the sample mean not the true individual value for the prediction:
> I've been playing with both the "predict" and "margins" command but
> with no success. Is there an "if" like command I can put after predict
> to force this?
> After no success trying that I also tried to go about this in a roundabout way:
> preserve
> foreach var of local varlist `pred' {
>    sum `var', meanonly
>    replace `var' = r(mean)
>    }
>
> predict sev5, xb
> The predictions are still not adjusted.
> Any quick thoughts?

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