I estimate different specifications of a MS-TVTP model. I mean by different speficification, different set of lag (for the exogenous and transition variables). But i would like to make a loop to do it automatically. I arrived to creat a basic loop for estimation of a set of lag associated to the transition variable:
Code: Select all
************************************* Initialisation
*** Terme autoregressif sur la variable endogene ***
compute nlags = 2
*** Nombre de retards sur la veariable de transition ***
compute ivlags = 6
*** Retards sur les exogenes
compute con1lags = 0
*** Set the information variable
set tvar = usa(t)
compute tvlabel = %label(usa)
*** Set the dependent variable
set g = singapore(t)
compute enlabel = %label(singapore)
*** set the exogenous variables
set con1 = malaysia(t-con1lags)
compute exlabel = %label(malaysia)
**************************************************************************************************
* Computes the vector of probabilities (levels, not logs) of the augmented states
* at period <<time>>. G (the data being analyzed), NSTATES, LAGSTATE and the
* parameters MU, PHI and SIGMA are all global variables.
function HamiltonF time
type vector HamiltonF
type integer time
*** Declaring local variables
local integer i j
local real u
*** Setting array size
dim HamiltonF(nstates)
*** e(t) = y(t) - mu(st=0) - phi(L)*(y(t-1)-mu(st-1) if st = 0 ***
*** e(t) = y(t) - mu(st=1) - phi(L)*(y(t-1)-mu(st-1) if st = 1 ***
*** e(t) = y(t) - mu(st=0) -c1(st=0)*dfra_nlgq(t)-phi(L)*(y(t-1)-mu(st-1) if st = 0 ***
*** e(t) = y(t) - mu(st=1) -c1(st=1)*dfra_nlgq(t)-phi(L)*(y(t-1)-mu(st-1) if st = 1 ***
*** with mu(st) = mu(0)+mu(1)St, St={0,1} ***
do i=1,nstates
compute u=g(time)-mu(lagstate(i,1))-d1(lagstate(i,1))*con1(time)
do j=1,nlags
compute u=u-phi(lagstate(i,j+1),j)*(g(time-j)-mu(lagstate(i,j+1)) $
-d1(lagstate(i,j+1))*con1(time))
end do j
compute HamiltonF(i)=%density(u/sigma)/sigma
end do i
end
*** LOGLFTP computes the log likelihood for a fixed transition probability model
frml loglftp = f=HamiltonF(t),pt_t1=HamiltonPt_t1(),pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
*** LOGLTVTP computes the log likelihood for a time-varying transition model
frml logltvtp = TVPProbs(t),f=HamiltonF(t),pt_t1=HamiltonPt_t1(),pt_t=pstar=%msupdate(f,pt_t1,fpt),log(fpt)
*****************************************************************************************
**** Compuation
do ivlags=1,6
disp ' '
disp '====================================================================================================='
disp " Markov-switching FTP vs TVTP vs AR(" nlags ") for " tlabel
disp '====================================================================================================='
disp '====================================================================================================='
disp " Variable of information: " ilabel " with " ivlags " lags"
disp '====================================================================================================='
***
linreg g
# constant con1 g{1 to nlags}
compute a1=log(.70/(1-.70)), a2=log(.85/(1-.85))
compute mu(1)=%beta(1),mu(2)=%beta(1)
compute sigma =sqrt(%seesq)
compute d1(1)= %beta(2), d1(2)= %beta(2)
compute phi = %const(%beta(3))
*****************************************************************************************
*
* Maximize
*
*** Perform the Broyden, Fletcher, Goldfarb and Shanno (bfgs) method
maximize(parmset=standard,start=(pstar=MarkovInit()),method=bfgs,pmethod=simplex,piters=40) loglftp 1976:01 *
***
compute baselogl=%funcval,baseregs=%nreg
compute p11f=p11,p22f=p22
*** Initialize non-linear parameters
nonlin(parmset=tv) a11 a22
compute a11 = 0.0, a22 = 0.0
***
frml p1frml = a1+a11*tvar(t-ivlags)
frml p2frml = a2+a22*tvar(t-ivlags)
*** Perform the Broyden, Fletcher, Goldfarb and Shanno (bfgs) method
maximize(parmset=standard+tv,start=(pstar=MarkovInit()),method=bfgs,pmethod=simplex,piters=40) logltvtp %regstart() *
end do ivlags
This is the loop in the precedent code:
Code: Select all
Do ivlags=1,6
....
end do ivlagsWhat i try to do, is to estimate automatically 36 specifications. And for this i must creat a loop for con1lags. In this way i will have for con1lags=0, 6 spec with different ivlags, for con1lags=2, again 6 spec different ect ect up to con1lags=5
the variable con1 is define like this:
Code: Select all
set con1 = malaysia(t-con1lags)
compute exlabel = %label(malaysia)
The problem is that con1 is needed to computing the function HalmiltonF. And i need to create a loop with this function inside but i think that it is impossible. Moreover, in the function it is no con1lags but con1, so i must put in the function:
Code: Select all
set con1 = malaysia(t-con1lags)
compute exlabel = %label(malaysia)
aybe the better way is to use another object than a function?
My goal is to have something like this
Code: Select all
do con1lags=0,5
....
do ivlags=1,6
.....
end do ivlags
end do con1lagsI can join my prg if necessary.
Thanks
Regards