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: Predicting y(i)--margins or predict?


From   Tim Wade <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Predicting y(i)--margins or predict?
Date   Mon, 12 Aug 2013 12:53:37 -0400

If you have an x value that takes on many values you can  use
-levelsof-  to store them in a local and loop over the values. you can
also collect the results using -postfile-

set more off
sysuse auto.dta

tempfile results
tempname temphold
postfile `temphold' wt phat  using `results', replace

logistic foreign mpg weight length
levelsof(weight), local(zz)
foreach num in `zz' {
margins, atmeans at(weight=(`num'))
matrix A=r(table)
local est=A[1,1]
post `temphold' (`num') (`est')
}


postclose `temphold'

use `results', clear

list


Tim


On Mon, Aug 12, 2013 at 8:01 AM,  <[email protected]> wrote:
> Hi:
>
> After estimating a regression model with i observations, I would like to
> make a prediction of what y will be at a particular value of x for each i
> observation.  That is, I want to use the fitted values from a regression to
> predict what y will be for each observation at a particular value for x
> (while holding constant at their means the the rest of the covariates).
>
> I can't see whether I have to use margins or predict for this, or how I
> should go about doing it (without having to do it manually).
>
> Is there a command for that?
>
> Best regards,
> John Antonakis
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index