Ernest Berkhout replied to Dev Vencappa
> > I have a small problem that I am sure can be solved by
> you experts. I am
> > running some dickey fuller test, and computing my own
> Akaike Information
> > criteria or Scharwtz Information Criteria. I saved the
> results of these
> > in a scalar.
> > I want to ask stata to create a variable that computes
> the minimum of
> > the AIC or SIC and return the value in that variable,
> rather than me
> > cheking it from the screen everytime. Can anybody help
> please? I am
> > copying the loop file below.
> >
> >local z "1 2 3 4 5 6"
> >
> >foreach x of local z{
> >
> >regress D.netpremmean L.netpremmean L`x'D.netpremmean
> >matrix b`x'=get(_b)
> >scalar
> AIC`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))*2
> >scalar
> >SIC`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))
> *log(_result(1))
> >}
> >scalar list
> >
> >
> > So rather than calling scalar list and looking at the
> screen, I want a
> > variable that stores the min of AIC and SIC so that I
> can see it in the
> > data editor. I want to do that because at some point I
> would need to loop
> > that over many series.
>
> One approach could be to create a dataset within your loop,
> recording in
> one variable the number of lags you include (`x' that is)
> and in the second
> and third the matching AIC`x' and SIC`i'. As far as I know
> -but that
> knowledge might still be superseded by more experienced
> programmers- that
> might best be done using 'postfile'.
>
> postfile myhandle lags aic sic using adftests, replace
> forvalues x = 1/6 {
> regress D.netpremmean L.netpremmean L`x'D.netpremmean
> matrix b`x'=get(_b)
> scalar
> AIC`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))*2
> scalar
> SIC`x'=log(_result(4)/_result(1))+(colsof(b`x')/_result(1))*
> log(_result(1))
> post myhandle (`x') (AIC`x') (SIC`x')
> }
> postclose myhandle
>
> This should give you a dataset adftests.dta with the values
> you want. From
> there it is easy to detect the minimum value of a variable
> using normal
> Stata functions for generate and/or egen.
Alternatively, assuming that you have more than 6 observations
you could do something like this. I assume by Scharwtz you mean
Schwarz and thus what Stata means by BIC. I'd use Stata's
own functionality here, unless there's some nuance I'm missing.
gen AIC = .
gen BIC = .
forvalues x = 1/6 {
regress D.netpremmean L.netpremmean L`x'D.netpremmean
estimates store whatever
qui estimates stats
qui replace AIC = M[1,5] in `x'
qui replace BIC = M[1,6] in `x'
}
I take it that you want to calculate min(AIC, BIC):
one problem with that is you could lose track of
which number came from which criterion. However,
once they're in variables you can do what you
like with them.
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/