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: Predict command


From   Tirthankar Chakravarty <[email protected]>
To   [email protected]
Subject   Re: st: Predict command
Date   Fri, 23 Apr 2010 11:56:45 +0530

Here is fully commented version of the same code. Hope this helps you
with the individual steps.

********************************************
clear*
clear mata
sysuse auto
regress mpg weight c.weight#c.weight foreign turn
mata
// calculate the p-values
vPval = 2*ttail(st_numscalar("e(df_r)"),abs(st_matrix("e(b)")'
	:/ diagonal(cholesky(diag(st_matrix("e(V)"))))))
// 1 if variable significant (change the significance level here)
vPvalSelect = mm_cond(vPval :< .05, 1, 0) // need Ben Jann's -moremata- package
// vector of beta coefficients of significant variables
vBetaSelect = vPvalSelect:* st_matrix("e(b)")'
// matrix of data on independent variables
st_view(mData=., ., (st_macroexpand(regexr(regexr("`e(cmdline)'",
"`e(depvar)'", ""), "`e(cmd)'", ""))))
	// this will choke on options
// add a constant
mData = mData, J(rows(mData),1,1)
// calculate the linear prediction for the significant variables
vLinPredSelect = mData*vBetaSelect
// full linear predictor for the model
stata("predict vLinPred, xb")
// draw the full linear predictor into Mata
st_view(vLinPred = ., ., "vLinPred")
// plot the two predicitons against each other
mm_plot((vLinPredSelect, vLinPred)) // need Ben Jann's -moremata- package
end
// bring the reduced prediction into Stata
getmata vLinPredSelect
********************************************

T

2010/4/23 Rasika Raghavan <[email protected]>:
> All,
>
> Thanks for your comments.
>
> Tirthankar, the Mata looks a bit hard to comprehend, but will try to
> work it out. Thanks
>
> Rasika
> *
> *   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/
>



-- 
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

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