--
You received this message because you are subscribed to the Google Groups "tsdyn" group.
To post to this group, send email to ts...@googlegroups.com.
To unsubscribe from this group, send email to tsdyn+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tsdyn?hl=en.
Dear Laura, this answer might come a little bit late, nevertheless I thing that a possible way to implement the IRF is by writing the companion matrix of the model, for that you would need either to retrieve the matrix of parameters from the TVAR, or you can enter it manually. Consider the following code below:
#### Number of endogenous variables included in the VAR, entered manually so can change this number
ny<-2
#### Number of lags on the model, entered manually
p<-5
#### Entering the parameters matrix, this is done manually, at the moment I am not sure how to retrieve it automatically from the TVAR function
#### This is a random matrix which serves as an example, so you should enter the parameters obtained from the TVAR estimation
### First create the vector containing the parameters
LR_coef<-c(runif(ny*p, min=-0.95, max=0.85)) ##### these are the coefficients for the lower regime
UR_coef<-c(runif(ny*p, min=-0.95, max=0.55)) ##### these are the coefficients for the upper regime
LR_m<-matrix(LR_coef, nrow=ny, ncol=ny*p) ##### Now you have the matrix with the coefficients for the lower regime
UR_m<-matrix(UR_coef, nrow=ny, ncol=ny*p) ##### Now you have the matrix with the coefficients for the upper regime
#### Now you need to set up the companion matrix
diagonal<-diag(p*ny-ny)
zeros<-rep(0,(p*ny-ny)*ny)
zeros
step_1<-cbind(diagonal, matrix(zeros,nrow=p*ny-ny, ncol=ny))
LR<-rbind(LR_m,step_1) #### The companion matrix for the lower regime
UR<-rbind(UR_m,step_1) #### The companion matrix for the upper regime
#### Function for powering the matrix
matrix.power <- function(mat, n)
{
# test if mat is a square matrix
# treat n < 0 and n = 0 -- this is left as an exercise
# trap non-integer n and return an error
if (n == 1) return(mat)
result <- diag(1, ncol(mat))
while (n > 0) {
if (n %% 2 != 0) {
result <- result %*% mat
n <- n - 1
}
mat <- mat %*% mat
n <- n / 2
}
return(result)
}
#### Here starts the IRA
n<-35 ### This is the number of observations you want to have after the initial schock
LR_IRF<-numeric(length=n) ### This is the vector for storing your responses in the lower regime
UR_IRF<-numeric(length=n) ### This is the vector for storing your responses in the upper regime
d<-seq(1:n) ### The sequence parameter for the loop
#### Now the loop starts
for (i in seq(d))
{
### Obtain the exponential of the matrices
LR_n<-matrix.power(LR,i)
UR_n<-matrix.power(UR,i)
### [1,1] is for the effect of shock of the variable one on variable one
### if you are interested in the shock of variable two on one, then just replace [1,1] for [2,1]
### if you are interested in the shock of variable two on two, then write [2,2] and so on..
LR_IRF[i]=LR_n[1,1]
UR_IRF[i]=UR_n[1,1]
}
plot(ts(LR_IRF))
plot(ts(UR_IRF))
As far as I know, in the case of threshold models you have to report separately the short run effects for each regime, Just a remark, the function for powering the matrix is not from me, I found it in some example on the internet but cannot recall the author or the website where I found it,
Hope it helps!!!
Sergio René
--
You received this message because you are subscribed to the Google Groups "tsdyn" group.
To post to this group, send email to ts...@googlegroups.com.
To unsubscribe from this group, send email to tsdyn+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tsdyn?hl=en.For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to tsdyn+un...@googlegroups.com.
Hi,
I came across this thread while looking for GIRFs for the TVAR package. As far as I see they haven't been implemented yet. So I wrote my own functions which I wanted to share with you.
My approach is based on the appendix of Baum and Koester (2011, see attachment page 30) who build on Pesaran et al. (1996).
So far my two functions (GIRF() and the helper-function simTVAR() ) only work with an endogenous threshold variable. I want to extend it to make it work with an exogenous threshold variable as well. However, I have some problems with TVAR.sim() and an exogenous threshold variable (thus a working example of TVAR.sim() with an exogenous threshold variable would be appreciated).
The functions are in the attachment. The code is far from perfect and it takes some time running it (around 3min on my computer with the zerolyd dataset and default options). I mainly tested it with the “zerolyd” dataset (and a bigger VAR with 5 variables as well). So my code loads the tsDyn package, then there are the two functions and the example with the zerolyd dataset at the end. It should be straightforward.
The code runs without errors in both examples. However, I wanted to share it with you to get some feedback, because I'm not sure about two things:
1. the bootstrap residuals should correspond to their variables, right? For example in the zerolyd dataset, a bootstrap residual for long.rate should be a residual from long.rate and shouldn't be from short.rate?
2. For varcov in TVAR.sim(): I used the default value. As far as I can see the choice of varcov doesn't matter, because I bootstrap the residuals anyway. Varcov would make sense if I let TVAR.sim() choose the residuals according to some predefined variance-covariance matrix. Is this correct?
In the end I tested the code with two datasets and I hope that I got the idea of the papers right, but I would appreciate, if someone would give it a trial and play around a little bit and give me some feedback on it!
Best,
Alex
impulseResp$girf[, , 1] will give you the values for the first regime
impulseResp$girf[, , 2] will give you the values for the second regime
impulseResp$girf[1, 3, 2]: will give you the response in the first period of the third variable in the second regime
impulseResp$med[ , , ,]: same structure as $girf
Finally if you want to take a look at the structure of impulseResp:str(impulseResp) will be useful
Cheers,
Alex
--
You received this message because you are subscribed to a topic in the Google Groups "tsdyn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tsdyn/XFF6lKOjqww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tsdyn+unsubscribe@googlegroups.com.
To post to this group, send email to ts...@googlegroups.com.
Visit this group at https://groups.google.com/group/tsdyn.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to tsdyn+un...@googlegroups.com.
To post to this group, send email to ts...@googlegroups.com.
Visit this group at https://groups.google.com/group/tsdyn.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to tsdyn+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to tsdyn+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "tsdyn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tsdyn/XFF6lKOjqww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tsdyn+unsubscribe@googlegroups.com.
To post to this group, send email to ts...@googlegroups.com.
Visit this group at https://groups.google.com/group/tsdyn.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "tsdyn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tsdyn+unsubscribe@googlegroups.com.