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: How to add Q stats from -wntestq- to -esttab- table (hopefully with -estadd-)


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: How to add Q stats from -wntestq- to -esttab- table (hopefully with -estadd-)
Date   Fri, 16 Sep 2011 19:01:26 -0500

On Fri, Sep 16, 2011 at 2:51 PM, Richard Herron
<[email protected]> wrote:
> @Stas -- Thanks for the pointers! I used -estadd- because I wanted to
> quickly estimate the models and generate the table, although after
> each estimation I added several lines to find Q, which made it very
> clunky.
>
> I learned enough Stata programming to write my own -estadd- function to add Q.
>
> * ----- begin code -----
> * my -estadd- function to calculate Box-Ljung Q
> capture program drop estadd_Q
> program estadd_Q, eclass
>    tempname residuals
>    predict `residuals', residuals
>    wntestq `residuals'
>    ereturn scalar Q = r(stat)
> end
>
> * get data
> webuse friedman2, clear
> generate ln_m1 = ln(m1)
>
> * make some models
> eststo clear
> eststo: quietly arima DS4.ln_m1, ar(1) ma(2)
> eststo: quietly arima DS4.ln_m1, ar(1) ma(1/2)
> eststo: quietly arima DS4.ln_m1, ar(1/2) ma(2)
> eststo: quietly arima DS4.ln_m1, ar(1/2) ma(1/2)
> estadd Q : *
>
> * and create tables with -esttab-
> esttab, stats(aic bic Q) noobslast nomtitles
> * ----- end code -----
>
> It works! Any other suggestions? Thanks!

I am not sure what you mean by "it works". The larger chunk of code
you provided does not actually use -estadd_Q-. More importantly,
-eclass- programming (commands that represent parameter estimation
routines) has a number of requirements that your program does not
satisfy. See [P] ereturn. (To put it informally, you are playing with
fire here :) ).

-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

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