Hi Yukai,
First of all thank you for the hard work on this package. I've been looking for a way to perform PSTR in R since forever. Recently I came across Gongalez refined paper mentioning your package and am so glad to find this.
I want to suggest a new feature for the package. When employing the two regimes, single transition function PSTR model with two variables (from here, p.7):
![image](https://user-images.githubusercontent.com/30339577/52161394-012cc680-26f7-11e9-86b4-9be06128bd54.png)
with a logistic transition function with a single location parameter (m=1):
,
it can be shown that the elasticity of I w.r.t S is both cross-sectional and time-variant (you show this when you compute your "response" measures):
.
And I think it would be intuitive to extract these varying coefficients, for all individuals over time, because they show the dynamic of the interested relationships and complement the plot of transition functions.
Let say we applies this to the case of Hansen's data (4 vars instead of 2, but the above formulae applies). We would like to investigate the impact of debt level on investment, conditional on the transition variable selected to be Tobin's Q. Let's fit the model first:
pstr = NewPSTR(Hansen99, dep='inva', indep=4:20, indep_k=c('vala','debta','cfa','sales'),tvars=c('vala'), iT=14); model = EstPSTR(use=pstr, im=1, iq=1, useDelta=TRUE, par=c(1.6,.5), method='CG'); model$est[14:17] ; model$mbeta
Then compute the time varying coefficients, as well as extract Tobin's Q levels for each of the first three firms in the sample
id<-unique(Hansen99$cusip); tvc<-NULL; vala<-NULL; for (i in 1:3){ vala_i<-Hansen99$vala[Hansen99$cusip==id[i]] ; g<-(1+exp(-model$gamma*(vala_i-model$c)))^(-1) ; tvc_i<-model$est[14:17][2] + model$mbeta[2]*g ; tvc<-cbind(tvc,tvc_i); vala<-cbind(vala,vala_i); colnames(tvc)[i]=colnames(vala)[i]=id[i] }
Finally plot these times series side by side:
par(mfcol=c(1,2)); matplot(tvc, type = 'l', lwd=2,col = 1:3, xaxt='n', xlab='year',ylab='coefficient',main='Time varying impact of debt level on investment'); axis(1, at=1:nrow(tvc), labels=c(1974:1987)); legend("topleft", legend = paste('firm_',colnames(tvc),sep=''), col=1:3, lwd=2, cex=1.1); matplot(vala, type = 'l', lwd=2,col = 1:3, xaxt = 'n', xlab='year',ylab="Tobin's Q",main="Tobin's Q level"); axis(1, at=1:nrow(tvc), labels=c(1974:1987)); legend("topleft", legend = paste('firm_',colnames(vala),sep=''), col=1:3, lwd=2, cex=1.1)
We can see that the elasticity of investment w.r.t debt changes over time, and depends on the level of Q: The higher the Q (firms with more investment opportunities), the stronger the impact. In particular, the firm with highest Q (2824) (green curve, right plot) exhibits the most stable the relationship (green curve, left plot). These are the conclusions you made at the end of the package introduction.
![image](https://user-images.githubusercontent.com/30339577/52161553-24f10c00-26f9-11e9-9603-aba7c6affd51.png)
There is a caveat though: If the transition variable is the same as the independent variable (or a function of it), the computation of the elasticity gets a bit more complicated. In general, for a model with r transition functions (r+1 regimes) we have:
.
That means the elasticity of investment w.r.t Tobin's Q need to be computed differently. But I think this could also be incorporated into the new feature.
Hopefully my suggestions make sense!
Thanks,
Long