Giter VIP home page Giter VIP logo

yukai-yang / pstr Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 23.0 1.09 MB

an R package for testing, estimating and evaluating the Panel Smooth Transition Regression (PSTR) model.

License: GNU General Public License v3.0

R 100.00%
bootstrap bootstrap-test cran evaluation heterogeneity linearity model-specifition modelling nonlinearity panel-data parallel-computing pstr-model regression smooth-transition transition-variables wild-bootstrap wild-cluster-bootstrap

pstr's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @yukai-yang
  • ๐Ÿ‘€ Iโ€™m interested in ...
  • ๐ŸŒฑ Iโ€™m currently learning ...
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on ...
  • ๐Ÿ“ซ How to reach me ...

pstr's People

Contributors

wenjingwang avatar yukai-yang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pstr's Issues

plot_response error

Function
ret = plot_response(obj=pstr, vars=1:4, log_scale = c(F,T), length.out=100)
in example of using return error:

Error in if (varname != tvarname) { :
missing value where TRUE/FALSE needed

Endogeneity-robust feature

Hi Yukai,
Just out of curiosity, does this package allow for endogenous regressors? Let's say for example in the investment-cash flow volatility regression, what if investment level somehow reversely affecting cash flow vol? (e.g., low investment could lead to lower stock prices, causing financial constrains etc. and thus making cash flow more volatile in the future).
A possible solution is adopting an instrumental variable approach for the PSTR model, as outlined in section 6 in the paper by Fouquau et al. here: http://www.univ-orleans.fr/deg/masters/ESA/CH/FH.pdf (the published version is at https://www.sciencedirect.com/science/article/pii/S0264999307000831).

Regards,
Long

PSTR Model estimation error

Error output
Error: The PSTR model is not estimated yet.

To Reproduce
I'll make this relevant to the handbook, so please run:

  1. pstr = NewPSTR(Hansen99, dep='inva', indep=4:20, indep_k=c('vala','debta','cfa','sales'), tvars=c('vala'), iT=14)
  2. pstr = EstPSTR(use=pstr)
  3. plot_coefficients(pstr)

-> Error comes out.

Additional information

  1. When estimating, this warning pops up:
Warning message:
In if (class(ttmp) == "try-error") { :
  the condition has length > 1 and only the first element will be used
  1. The same error comes up for plot_coefficients(pstr) and other pertinent commands, but not for print(pstr, "estimates")

Software:

  • R version: 4.0.3
  • PSTR version: 1.2.4
  • Windows 10

Compute the time varying coefficient from the PSTR model

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
with a logistic transition function with a single location parameter (m=1):
image,
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):
image.
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

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:
image.
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

problem for installation 1.2.4

hello,
I just come across a problem when installing the package of version 1.2.4.

  • installing source package 'PSTR' ...
    ** R
    Error : (็”ฑ่ญฆๅ‘Š่ฝฌๆขๆˆ)ๆ— ๆณ•้‡ๆ–ฐ็ผ–็ 'PSTR.R'่กŒ41
    ERROR: unable to collate and parse R files for package 'PSTR'
  • removing 'D:/R/R-3.5.3/library/PSTR'
    In R CMD INSTALL
    Error in i.p(...) :
    (converted from warning) installation of package โ€˜C:/Users/Xiangtuo/AppData/Local/Temp/RtmpyaO9AV/file3d10d956938/PSTR_1.2.4.tar.gzโ€™ had non-zero exit status

could you help me to have a look?

best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.