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
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Predicting y(i)--margins or predict?
Date
Mon, 12 Aug 2013 14:37:30 +0200
On Mon, Aug 12, 2013 at 2:01 PM, John Antonakis wrote:
> 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).
Both are possible:
*------------------ begin example ------------------
// data preparation
sysuse nlsw88, clear
gen byte occat = cond(occupation < 3 , 1, ///
cond(inlist(occupation, 5, 6, 8, 13), 2, 3)) ///
if occupation < .
label variable occat "occupation in categories"
label define occat 1 "high" ///
2 "middle" ///
3 "low"
label value occat occat
gen byte edcat = cond(grade < 12, 1, ///
cond(grade == 12, 2, 3)) ///
if grade < .
label define edcat 1 "less than high school" ///
2 "high school" ///
3 "more than high school"
label value edcat edcat
label variable edcat "education in categories"
// the model
logit union i.occat i.edcat i.race, or
// predicted probability of union membership if
// high educated
// modal occuaption (low)
// modal race (white)
margins, at(edcat=3 occat=3 race=1)
// table of predicted probabilities for
// different levels of education
// modal occuaption (low)
// modal race (white)
margins, at(edcat=(1/3) occat=3 race=1)
// you could use -predict- for that
preserve
drop _all
set obs 1
gen byte occat = 3
gen byte race = 1
expand 3
gen byte edcat = _n
label value edcat edcat
predict pr
list edcat pr
restore
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/