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, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: programming own arch ml


From   Martien Lamers <Martien.Lamers@UGent.be>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: programming own arch ml
Date   Mon, 16 Aug 2010 12:12:25 +0200

Dear Statalist, I am currently trying to program my own ARCH/GARCH models using Statas ml command, since I expect to write more complicated maximum likelihood programs in the future. So far, my attempts have not been very successful. I have checked the help files of Stata, Statalist archives and multiple -ml- threads on problems like mine, have gone through the book of Gould et al. on programming maximum likelihood in Stata (although they do not really discuss time series) and have asked people at my department to no avail. Any comments would be appreciated since I am quite new to this topic. My apologies for being a n00b. 

This is the do-file I have written:

*******************************************
program drop _all

set more off
sysuse sp500, clear
gen return=(change/open) * 100
gen t=_n
tsset t

* Stata's ARCH command *
arch return volume, arch(1)

* Own maximum likelihood program * 
program archtry
                args lnf mu a0 a1 
                tempvar err ext h
                qui gen double `err'=$ML_y1-`mu'
                qui gen double `ext'=`err'[_n-1]
                qui gen double `h'=`a0'+`a1'*`ext'^2
                qui replace `lnf'=-0.5*(ln(`h') + (`err')^2/`h')
end

ml model lf archtry (return = volume) /a0 /a1
ml max
********************************************

I used the arch command to see the results I want to end up with. 

As far as I can tell, the program is in the correct syntax. Using -ml check- shows that I have passed the tests, however it seems as though the intial values are not feasible:

The initial values are not feasible.  This may be because the initial values have been chosen poorly or because there is an error in archtry and it always returns missing no matter what the parameter values.
Stata is going to search for a feasible set of initial values. If archtry is broken, this will not work and you will have to press Break to stop the search.

Searching...
initial:       log likelihood =     -<inf>  (could not be evaluated)
searching for feasible values ...........................................................................................
> .......................................................................................................................
> .......................................................................................................................
> .......................................................................................................................
> .......................................................................................................................
> .......................................................................................................................
> .......................................................................................................................
> .......................................................................................................................
> ............................................................................

could not find feasible values
r(491);

Using -ml search- gives the same error that it cannot find feasible values. Using -ml init /a0=0.05 /a1=0.01- again gives no feasible values. Using -reg return volume- and extracting the vector of parameters and using them as initial values again gives the same problem.

I thought the program could not handle the [_n-1] operator but it seems that for every try to search feasible values it does generate an `h’ and an `lnf’. So now I am unsure, whether the fault is in the program or in the way I try and maximize the likelihood. 

Any comments would be of use. Thank you in advance.

Martien Lamers
Department of Financial Economics
Ghent University

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index