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: standard error of the forecast using -margins-


From   Alan Neustadtl <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: standard error of the forecast using -margins-
Date   Sat, 13 Mar 2010 11:07:39 -0500

About a week ago I posted a question to the list about using -margins-
to calculate prediction or forecast intervals which didn't generate
any responses.

I posed my question to Stata technical support and Wes Eddings sent me
two solutions that I am posting here to close this topic.  My original
post is at the bottom.

Best,
Alan

***** Stata Tech Support Response *****
Dear Alan,

Yes, you can use -margins-.  If you try to use -margins, predict(stdf)-, though,
you will get an error when the calculation of the standard error fails.  (Please
see the subsection "Requirements for model specification" in -[R] margins-.)
You'll need to use the -nose- option to prevent the error:

     . margins, predict(stdf) nose

Here's a complete example that uses -margins- to replicate the intervals from
-adjust-:

* begin example
sysuse auto, clear
regress price mpg
local dfr = e(df_r)
margins, predict(stdf) nose at(mpg = (20(5)40)) post
matrix stdf = e(b)
regress price mpg
margins, predict(xb) nose at(mpg = (20(5)40)) post
matrix xb = e(b)
clear
matrix stdfxb = [stdf \ xb]'
svmat stdfxb
generate lb = stdfxb2 - invttail(`dfr', .025) * stdfxb1
generate ub = stdfxb2 + invttail(`dfr', .025) * stdfxb1
list
* end example

If you have any other questions, please let us know.

Sincerely,

Wes

Dear Alan,

Here's a more compact set of commands:

* begin commands
sysuse auto, clear
regress price mpg
margins, predict(xb) at(mpg=(20(5)40))
matrix b = r(b)
matrix V_f = ((r(V)/e(rmse)^2 + I(colsof(r(V)))))*e(rmse)^2
_coef_table, bmat(b) vmat(V_f)
* end commands

Our developers are considering whether to add a new feature to -margins-.

Sincerely,

Wes
***** End Stata Tech Support Response *****

On Fri, Mar 5, 2010 at 3:52 PM, Alan Neustadtl <[email protected]> wrote:
> After examining the manual I cannot find a -margins- equivalent to
> -adjust, ci stdf- in Stata 11.
>
> Is there a way to calculate the standard error of the forecast and the
> associated forecast interval?  I would like to use the "at" option to
> estimate intervals at fixed values of a variable, e.g.
> -at(age=(20(10)60))-
>

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