Page 2 of 3

Re: TVTP Markov Regime switching model

PostPosted: Tue Apr 03, 2012 3:33 pm
by superper2008
Hello Tom:

Thanks for your help. I am waiting for my university's respond about recent version 8.1 of WinRats. At the same time, I have been working on the code of my model. I also have one question if filardo's time varying probability code can be applied into my model by using @msvarsetup which considers "mu" and "phi". Because in the markov multivariate linear regression with time varying probability, there is no lag coeefficients needed, all the coefficents (alpha, beta and gamma) are the swithcing current terms. I think that @mssysregression may be better for my model, is that right? If i am right, it means than I have to write the code with time varying probability in the multivariate regression instead of hamilton style mean- swithcing model with lag coefficients. Could you please give me more suggestions about that?

Besides, I have order the materials of breaks and swithcing model courses and wish that the material can help me a lot.

Appreciate you very much for your help and understanding.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 05, 2012 11:41 am
by superper2008
Hello Tom:

I have been dealing with my model by means of code from yours. However I am meeting a big trouble to write the code about time varying transition probability. In Filardo' code. he used @msvarsetup to estimate time varying Hamilton style mean-switching model with four lags. However, in my model, there is only multivariate linear regression without any lags.

What should I do to apply the code into my multivariate regression (@mssysregression(state=2, switch=ch))?

Can I modify the time varying transition probability model as follows according to Filardo's code?

However, I have no clear picture to code Controlling routine for EM estimation of time-varying probabilities in red highlight part which contain mean and lag term.

Could you please give me more suggestions at your earliest convenience? Appreciate you very much for your help.



Time varying probability

dec equation p1eq p2eq
dec vector v1 v2
nonlin(parmset=tv) v1 v2
*********************************************************************
frml logltvtp = %MSVARPMat(t),log(%MSVarProb(t))
*********************************************************************
Define the logistic index for the transitions
*
equation p1eq *
# constant log{1}
equation p2eq *
# constant log{1}
*
* Standard guess values aiming to make state 1 the recession state.
*
compute v1=log(.7/.3)~~0.0
compute v2=log(.95/.05)~~0.0

@MSVARTVPEMEstimate(cvcrit=.0001) gstart gend
*
maximize(parmset=tv+common,start=(pstar=TVPInit()),$
method=bhhh,iters=20) logltvtp gstart gend

* This overrides the standard fixed definition
*
function %MSVARPmat time
type rect %MSVARPmat
type int time
*
local integer i j
local rect pexpand
local real z
*
compute p(1,1)=%(z=log(%dot(%eqnxvector(p1eq,time-1),v1)),%cdf(z)
compute p(1,2)=%(z=log(%dot(%eqnxvector(p2eq,time-1),v2)),%cdf(-z)

compute %MSVARInitTransition()
*
if nexpand==nstates {
dim pexpand(nstates,nstates-1)
ewise pexpand(i,j)=%if(i==nstates,-1.0,i==j)
compute %MSVARPmat=pexpand*p
ewise %MSVARPmat(i,j)=%if(i==nstates,1.0+%MSVARPmat(i,j),%MSVARPmat(i,j))
}
else {
dim %MSVARPmat(nexpand,nexpand)
ewise %MSVARPmat(i,j)=MSVARTransProbs(MSVARTransLookup(i,j))
}
end
*********************************************************************
*
* Initialize the probabilities using only the intercepts
*
function TVPInit
type vector TVPInit
*
local rect a
local integer i j
*
compute p=||%logistic(v1(1),1.0),1-%logistic(v2(1),1.0)||
compute TVPInit=%MSVARInit()
end
*********************************************************************
*
*Controlling routine for EM estimation of time-varying probabilities
*
procedure MSVARTVPEMEstimate start end
type integer start end
option integer iters 100
option real cvcrit 1.e-6
*
local integer emits time k
local series l11 l22 w11 w22
local vector baseparms testparms
local rect thisEntry
*
@msvartestvector(domu,dovar) baseparms
compute baseparms=baseparms~~v1~~v2
do emits=1,iters
compute %eqnsetcoeffs(p1eq,v1)
compute %eqnsetcoeffs(p2eq,v2)
@msvarestep start end
compute %emlogl=%logl
@msvarmstep(nodop) start end
*
* Compute the weights and dependent variable for the one-step
* correction on the logistics.
*
set l11 start end = 0.0
set l22 start end = 0.0
set w11 start end = 0.0
set w22 start end = 0.0
do time=start,end
compute %MSVARPMat(time)
compute thisEntry=%zeros(nstates,nstates)
do k=1,MSVARFilterSize
compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k)
end do k
compute w11(time)=p(1,1)*(1-p(1,1))*(thisEntry(1,1)+thisEntry(2,1))
compute w22(time)=p(1,2)*(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2))
compute l11(time)=(thisEntry(1,1)- p(1,1)*(thisEntry(1,1)+thisEntry(2,1)))/w11(time)
compute l22(time)=(thisEntry(2,2)-(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2)))/w22(time)
end do time
*
* Update the coefficients
*
linreg(noprint,weight=w11,equation=p1eq) l11 start end
compute v1=v1+%beta
linreg(noprint,weight=w22,equation=p2eq) l22 start end
compute v2=v2+%beta
*
* Check for convergence
*
@msvartestvector(domu,dovar) testparms
compute testparms=testparms~~v1~~v2
compute %cvcrit=%testdiff(baseparms,testparms)
if %cvcrit<cvcrit
break
compute baseparms=testparms
disp "Iteration" emits "Log Likelihood" %emlogl %cvcrit
end do emits
end MSVARTVPEMEstimate

*
*
[/color]

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 05, 2012 1:36 pm
by TomDoan
First, Filardo didn't write the RATS program---we did. I don't believe he ever made his (I believe Gauss) program available.

This is definitely wrong:

Code: Select all
compute p(1,1)=%(z=log(%dot(%eqnxvector(p1eq,time-1),v1)),%cdf(z)
compute p(1,2)=%(z=log(%dot(%eqnxvector(p2eq,time-1),v2)),%cdf(-z)


You shouldn't have the log(...) there. It's just z=linear function,%cdf(z) for the first and %cdf(-z) for the second.

This is the one part in the EM algorithm that's specific to the logistic probability function. All the other parts of EM are the same since they take the transitions as given. This is simpler with the logistic than it would be with the probit type function. The logistic is simpler for EM, harder for Gibbs sampling and they are a toss-up for straight ML. But they should give very similar results. Since you're not doing Gibbs sampling, why are you using the less used and more complicated of two almost identical ways to handle this.

Code: Select all
compute w11(time)=p(1,1)*(1-p(1,1))*(thisEntry(1,1)+thisEntry(2,1))
compute w22(time)=p(1,2)*(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2))
compute l11(time)=(thisEntry(1,1)- p(1,1)*(thisEntry(1,1)+thisEntry(2,1)))/w11(time)
compute l22(time)=(thisEntry(2,2)-(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2)))/w22(time)

Re: TVTP Markov Regime switching model

PostPosted: Tue Apr 10, 2012 4:13 pm
by superper2008
Hello Tom:

Appreciate you very much for your help. Now I am writing the code. But when I try to run the markov switching linear model firstly with fixed probability with my program, the mistakes appears as follows.

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesis\one_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq

@msregression(states=2,switch=ch) apexcess
# constant aprm aprmsq

nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms) p

compute gstart=2006:03:24, gend=2012:03:05
@MSRegInitial gstart gend
@MSRegEMGeneralSetup
do emits=1,50
@MSRegEMStep gstart gend
disp "Iteration" emits "Log likelihood" %logl
end do emits
* Polish estimates with 10 iterations of BHHH
*
compute p=%xsubmat(p,1,nstates-1,1,nstates)
nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms) p
frml logl = f=%MSRegFVec(t),fpt=%MSProb(t,f),log(fpt)
@MSFilterInit
maximize(start=%(%MSRegInitVariances(),pstar=%msinit()),$
parmset=regparms+msparms,$
method=bhhh,iters=10) logl gstart gend

set p1smooth = psmooth(t)(1)
graph(footer="Smoothed Probability of Regime 1",max=1.0,min=0.0)
# p1smooth

## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points
The Error Occurred At Location 274, Line 21 of MSREGMSTEP
Called From Location 170, Line 9 of MSREGEMSTEP
Called From Location 68, Line 2 of loop/block



Could you please help me figure it out?

Appreciate you very much for your help. P.S. I am using WINRATS 8.0 version and waiting for my university's support for 8.1 version.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Wed Apr 11, 2012 4:46 pm
by superper2008
Dear Tom
Could you help me figure it out what is wrong with my code in the Markov switching linear with fixed probabilities in the previous reply?

Look forward to your reply at your earliest convenience.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Wed Apr 11, 2012 9:57 pm
by TomDoan
You have embedded missing data. Because of the recursive nature of the likelihood, you can't have that. You need to squeeze out the missing data points. See the description of the SAMPLE instruction.

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 12, 2012 10:45 am
by superper2008
Hello Tom:
Appreciate you very much for your help. I understood what you told me. However, I am using daily data in Canadian market so that there is no data at weekends or Canadian holidays. I have looked up Sample instruction, but I still have no idea how to squeeze out my missing data. What should I do with my daily data to make our daily consecutive?

Appreciate you again for your patience and help.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 12, 2012 11:28 am
by superper2008
Hello Tom:

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq
sample (smpl=%valid(apexcess)) apexcess / apexcess_nomissing
linreg(define=fulleqn) apexcess
# constant aprm aprmsq


Just like what I wrote above, I used Sample instruction to create "compressed" version of data without any missing value to make my data consecutive entries. However, the mistakes appeared as follows.
## SX22. Expected Type SERIES[REAL], Got REAL Instead
>>>>=%valid(apexcess)) <<<<


could you please help me figure that out?

Appreciate you very much for your help.

Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 12, 2012 4:28 pm
by superper2008
Hello Tom:

I have solved the problem about missing value. Thanks for your help. However, when I put the code together and run them step by step. The mistakes appeared in the middle about EM 50 iteration, but when I continue to run the code in the following, the results could be shown as follows. Could you help me explain about that? Appreciate very much for your kindly help. A millions thanks.

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq
sample(smpl=%valid(apexcess)) apexcess / apexcess_nomissing
sample(smpl=%valid(aprm)) aprm / aprm_nomissing
sample(smpl=%valid(aprmsq)) aprmsq / aprmsq_nomissing

@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing


compute gstart=2006:03:24, gend=2012:03:05
@MSRegInitial gstart gend
@MSRegEMGeneralSetup
do emits=1,25
@MSRegEMStep gstart gend
disp "Iteration" emits "Log likelihood" %logl
end do emits
## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points
The Error Occurred At Location 274, Line 21 of MSREGMSTEP
Called From Location 170, Line 9 of MSREGEMSTEP
Called From Location 68, Line 2 of loop/block

* Polish estimates with 10 iterations of BHHH
*
compute p=%xsubmat(p,1,nstates-1,1,nstates)
nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms) p
frml logl = f=%MSRegFVec(t),fpt=%MSProb(t,f),log(fpt)
@MSFilterInit
maximize(start=%(%MSRegInitVariances(),pstar=%msinit()),$
parmset=regparms+msparms,$
method=bhhh,iters=10) logl gstart gend


MAXIMIZE - Estimation by BHHH
NO CONVERGENCE IN 10 ITERATIONS
LAST CRITERION WAS 0.1477305
Daily(5) Data From 2006:03:24 To 2012:03:05
Usable Observations 1493
Skipped/Missing (from 1552) 59
Function Value 2987.6828

Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. BETAS(1)(1) 0.000064403 0.000452654 0.14228 0.88686041
2. BETAS(1)(2) 0.604359705 0.023436638 25.78696 0.00000000
3. BETAS(1)(3) 1.802335844 0.331478272 5.43727 0.00000005
4. BETAS(2)(1) -0.004748251 0.005501272 -0.86312 0.38807221
5. BETAS(2)(2) 0.868780030 0.175884328 4.93950 0.00000078
6. BETAS(2)(3) 3.143974135 3.127256580 1.00535 0.31473039
7. SIGSQV(1) 0.000180526 0.000007037 25.65336 0.00000000
8. SIGSQV(2) 0.012834751 0.000341708 37.56058 0.00000000
9. P(1,1) 0.962684175 0.007069809 136.16835 0.00000000
10. P(1,2) 0.069079291 0.010034231 6.88436 0.00000000

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 12, 2012 10:00 pm
by TomDoan
[quote="superper2008"]Hello Tom:

I have solved the problem about missing value. Thanks for your help. However, when I put the code together and run them step by step. The mistakes appeared in the middle about EM 50 iteration, but when I continue to run the code in the following, the results could be shown as follows. Could you help me explain about that? Appreciate very much for your kindly help. A millions thanks.

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq
sample(smpl=%valid(apexcess)) apexcess / apexcess_nomissing
sample(smpl=%valid(aprm)) aprm / aprm_nomissing
sample(smpl=%valid(aprmsq)) aprmsq / aprmsq_nomissing
calendar(irregular)
compute gstart=1,gend=%nobs

@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing

When you do the SAMPLE, your data is no longer daily, but irregular with fewer observations. Add the two lines in red and deleting the existing line for setting gstart and gend should fix that.

Note, BTW, that the failure to converge on the last MAXIMIZE is intentional. That's just there to get the BHHH covariance matrix, which EM can't estimate itself.

Re: TVTP Markov Regime switching model

PostPosted: Fri Apr 13, 2012 2:52 pm
by superper2008
Dear Tom:
Appreciate you very much for your help. I have put two lines in red as you suggested in my model. However, there were still mistakes as follows.The Error Occurred At Location 58, Line 7 of MSREGINITIAL Could you please help me figure it out ? Look forward to hearing from you. Thanks again.

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq
sample(smpl=%valid(apexcess)) apexcess / apexcess_nomissing
sample(smpl=%valid(aprm)) aprm / aprm_nomissing
sample(smpl=%valid(aprmsq)) aprmsq / aprmsq_nomissing
calendar(irregular)
compute gstart=1,gend=%nobs

@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing


compute gstart=2006:03:24, gend=2012:03:05
@MSRegInitial gstart gend
@MSRegEMGeneralSetup
do emits=1,50
@MSRegEMStep gstart gend
disp "Iteration" emits "Log likelihood" %logl
end do emits

## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points
The Error Occurred At Location 58, Line 7 of MSREGINITIAL


*
compute p=%xsubmat(p,1,nstates-1,1,nstates)
nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms) p
frml logl = f=%MSRegFVec(t),fpt=%MSProb(t,f),log(fpt)
@MSFilterInit
maximize(start=%(%MSRegInitVariances(),pstar=%msinit()),$
parmset=regparms+msparms,$
method=bhhh,iters=10) logl gstart gend
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## NL6. NONLIN Parameter P(1,1) Has Not Been Initialized. Trying 0
## NL6. NONLIN Parameter P(1,2) Has Not Been Initialized. Trying 0
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 196, Line 19 of %MSPROB

Re: TVTP Markov Regime switching model

PostPosted: Fri Apr 13, 2012 3:17 pm
by superper2008
Dear Tom:

I made one mistake about that previously. After I deleted the line for setting gstart and gend, everything is all right and perfect. The results are shown below. Thanks you very much for your kindly help and suggestions.
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. BETAS(1)(1) 0.000345991 0.000490941 0.70475 0.48096573
2. BETAS(1)(2) 0.604890635 0.026696461 22.65808 0.00000000
3. BETAS(1)(3) 0.187181525 0.686965627 0.27248 0.78525618
4. BETAS(2)(1) -0.006383747 0.006674866 -0.95639 0.33887737
5. BETAS(2)(2) 0.983682912 0.213718251 4.60271 0.00000417
6. BETAS(2)(3) 2.282115414 3.799917039 0.60057 0.54812656
7. SIGSQV(1) 0.000193687 0.000007508 25.79592 0.00000000
8. SIGSQV(2) 0.014987340 0.000506806 29.57217 0.00000000
9. P(1,1) 0.963136585 0.006720898 143.30475 0.00000000
10. P(1,2) 0.075835763 0.010634384 7.13119 0.00000000


Appreciate you very much for your help. Now I am begining with model with time varying probability by means of Filardo's logistic function as you suggested. However, my obersvation model is one multivariate linear regression without any lag so that I have to use code
@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing
nonlin(parmset=common) betas sigsqv[/color
Compared with Filardo's code using[color=#FF0000][color=#FF0000] @MSVARSetup(lags=nlags)
nonlin(parmset=common) mu phi sigma, compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k) & @msvartestvector(domu,dovar) baseparms
, these code is applied into markov swithcing VAR model. Therefore, I am not sure how to modify Filardo's code to fit into my multivariate linear regression with time varying probability. Could you please give me more suggestions about that?

Appreciate you very much for your constant instruction.

Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Mon Apr 16, 2012 1:43 pm
by superper2008
Hello Tom:

Now I am writing code for time-varying multivariate linear regression without no lag coefficients. The code is post as follows, but the mistake occurred in the bottom line. Just what I mentioned in the previous reply, I still didn't understand how to apply @msversteup (nonlin(parmset=common) mu phi sigma)
)into @msregression (nonlin(parmset=common) betas sigsqv)
)

I am trying my best to combine them, but the results can't be showns.I am not sure if I need the code such as @msvartestvector(domu,dovar) baseparms, do k=1,MSVARFilterSize
compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k)
, because in my tested model, there are no lag terms and state-dependent means. Moreover, without the codes above, is it possible to run one result?

Could you please give me more suggestions about that to modify the Filado's code?

Appreciate you very much for your help. Look forward to hearing from you .

cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq logvix
sample(smpl=%valid(apexcess)) apexcess / apexcess_nomissing
sample(smpl=%valid(aprm)) aprm / aprm_nomissing
sample(smpl=%valid(aprmsq)) aprmsq / aprmsq_nomissing
sample(smpl=%valid(logvix)) logvix / logvix_nomissing

calendar(irregular)
compute gstart=1,gend=%nobs
@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing


source msvarsetup.src
nonlin(parmset=common) betas sigsqv

* Define the logistic index for the transitions
*
equation p1eq *
# constant logvix{1}
equation p2eq *
# constant logvix{1}



*
dec equation p1eq p2eq
dec vector v1 v2
nonlin(parmset=tv) v1 v2


function %MSVARPmat time
type rect %MSVARPmat
type int time
*
local integer i j
local rect pexpand
local real z
*
compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
compute %MSVARInitTransition()


if nexpand==nstates {
dim pexpand(nstates,nstates-1)
ewise pexpand(i,j)=%if(i==nstates,-1.0,i==j)
compute %MSVARPmat=pexpand*p
ewise %MSVARPmat(i,j)=%if(i==nstates,1.0+%MSVARPmat(i,j),%MSVARPmat(i,j))
}
else {
dim %MSVARPmat(nexpand,nexpand)
ewise %MSVARPmat(i,j)=MSVARTransProbs(MSVARTransLookup(i,j))
}
end

Initialize the probabilities using only the intercepts
*
function TVPInit
type vector TVPInit
*
local rect a
local integer i j
*
compute p=||%logistic(v1(1),1.0),1-%logistic(v2(1),1.0)||
compute TVPInit=%MSVARInit()
end
procedure MSVARTVPEMEstimate start end
type integer start end
option integer iters 100
option real cvcrit 1.e-6


local integer emits time k
local series l11 l22 w11 w22
local vector baseparms testparms
local rect thisEntry
*
@msvartestvector(domu,dovar) baseparmscompute baseparms=baseparms~~v1~~v2
do emits=1,iters
compute %eqnsetcoeffs(p1eq,v1)
compute %eqnsetcoeffs(p2eq,v2)
@msvarestep start end
compute %emlogl=%logl
@msvarmstep(nodop) start end

set l11 start end = 0.0
set l22 start end = 0.0
set w11 start end = 0.0
set w22 start end = 0.0

do time=start,end
compute %MSVARPMat(time)
compute thisEntry=%zeros(nstates,nstates)
do k=1,MSVARFilterSize
compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k)
end do k
compute w11(time)=p(1,1)*(1-p(1,1))*(thisEntry(1,1)+thisEntry(2,1))
compute w22(time)=p(1,2)*(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2))
compute l11(time)=(thisEntry(1,1)- p(1,1)*(thisEntry(1,1)+thisEntry(2,1)))/w11(time)
compute l22(time)=(thisEntry(2,2)-(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2)))/w22(time)
end do time

* Update the coefficients
*
linreg(noprint,weight=w11,equation=p1eq) l11 start end
compute v1=v1+%beta
linreg(noprint,weight=w22,equation=p2eq) l22 start end
compute v2=v2+%beta

* Check for convergence
*
@msvartestvector(domu,dovar) testparms compute testparms=testparms~~v1~~v2
compute %cvcrit=%testdiff(baseparms,testparms)
if %cvcrit<cvcrit
break
compute baseparms=testparms
disp "Iteration" emits "Log Likelihood" %emlogl %cvcrit
end do emits
end MSVARTVPEMEstimate



frml logltvtp = %MSVARPMat(t),log(%MSVarProb(t))

compute v1=log(.7/.3)~~0.0
compute v2=log(.95/.05)~~0.0


@MSVARTVPEMEstimate(cvcrit=.0001) gstart gend
*
maximize(parmset=tv+common,start=(pstar=TVPInit()),$
method=bhhh,iters=20) logltvtp gstart gend
## MAT15. Subscripts Too Large or Non-Positive
[color=#FF0000]The Error Occurred At Location 213, Line 16 of MSVARTESTVECTOR
Called From Location 59, Line 10 of MSVARTVPEMESTIMA
[/color]

A millions thanks for your kindly help.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Tue Apr 17, 2012 2:39 pm
by superper2008
Hello Tom:

Could you please help me figure it out in the previous reply?

Appreciate you very much for your help and patience and understanding. Look forward to your reply soon.Thanks again.

Sincerely,
Feiyu

Re: TVTP Markov Regime switching model

PostPosted: Thu Apr 19, 2012 1:16 pm
by superper2008
Dear Tom:

I am not sure if you have seen my posts. For these days, I have been trying my best to solve the problems concerning markov switching linear model with time vary transition probability. Under your help, I have firstly addressed the issue about fixed transition probability. However, to meet the requirement of thesis at Master level, I have to move further into time varying transition.

Just as what I post in the previous post, I combined @msregression with @msvarsetup and run every procedure step by step. There seems to be all right except for the last part with maximize likelihood (common+tv) followed by
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 213, Line 16 of MSVARTESTVECTOR
Called From Location 59, Line 10 of MSVARTVPEMESTIMA


I am not sure if the error is related to irregular dataset, or should I set initial value for betas including constant (intercepts) and coefficients (betas and gammas) in the linear regression because I deleted the code line to initial value of mu in Filardo's code which is not considered in my model.

Could you please give me some advice about that? I wish that the problem can be solved under your further help.

Sincerely,
Feiyu