Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[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 <>
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
<> 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
Small print: I use this email account for mailing lists only.

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index