Title: | Threshold Model and Unit Root Tests in Cross-Section and Time Series Data |
---|---|
Description: | Threshold model, panel version of Hylleberg et al. (1990) <DOI:10.1016/0304-4076(90)90080-D> seasonal unit root tests, and panel unit root test of Chang (2002) <DOI:10.1016/S0304-4076(02)00095-7>. |
Authors: | Ho Tsung-wu [aut, cre] |
Maintainer: | Ho Tsung-wu <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.9.3 |
Built: | 2024-12-01 08:35:37 UTC |
Source: | CRAN |
Functions for analysis of panel data, including the panel threshold model of Hansen (1999,JE), panel unit root test of Chang(2002,JE) based upon instuments generating functions (IGF), and panel seasonal unit root test based upon Hylleberg et al.(1990,JE).
This version offers formatted output. This package designs a specification function ptm() to estimate the panel threshold model of Hansen(1999). The key feature of ptm() is to generalize Hansen's original code to allow multiple (more-than-one) regime-dependent right-hand-side independent variables; Dr. Hansen's original code admits only 1 regime-dependent right-hand-side independent variable. This version also includes panel unit root tests based on the instrument generating functions(IGF), proposed by Chang (2002, J. of Econometrics), and the panel version of Hylleberg et al.(1990) seasonal unit root test, proposed by Otero, et al. (2005, 2007).
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
Maintainer: Ho Tsung-wu <[email protected]>
Chang, Y. (2002) Nonlinear IV Unit Root Tests in Panels with Cross-Sectional Dependency. Journal of Econometrics, 110, 261-292.
Hansen B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
Otero, J., Smith, J., and Giulietti, M. (2005) Testing for seasonal unit roots in heterogeneous panels. Economics Letters, 86, 229-235.
Otero, J., Smith, J., and Giulietti, M. (2007) Testing for seasonal unit roots in heterogeneous panels in the presence of cross section dependence. Economics Letters, 86, 179-184.
Pesaran M. Hashem (2007) A simple panel unit root test in the presence of cross-section dependence. Journal of Applied Econometrics, 22, 265-312.
A quarterly panel data frame with 1000 observations on the following 7 variables, unbalanced panel data ranges from 2001Q1~2010Q1.
data("bank_income")
data("bank_income")
ID
a numeric vector
Qtr
a numeric vector
preTax_Income
a numeric vector
shortRatio
a numeric vector
longRatio
a numeric vector
Current_ratio
a numeric vector
LoanDeposit_ratio
a numeric vector
data(bank_income)
data(bank_income)
Cigaretts consumption of US states
data(cigaretts)
data(cigaretts)
A data frame of 48 US states' cigaretts consumption
State
State abbreviation, N
Year
Year, t
Y_SALES
Cigarette sales in packs per capita, deflated by population
X1_PRICE
P=Real price per pack of cigarettes, deflated by 1983 CPI.
X2_PIMIN
Real minimum price in adjoining states per pack of cigarettes, deflated by CPI
X3_NDI
Per capita disposable income
Baltagi Badi H. (2005) Econometric Analysis of Panel Data. John Wiley.
data(cigaretts) head(cigaretts)
data(cigaretts) head(cigaretts)
Extract the standard error and t-stat of the a-th parameter estimate of a lm object
contts(lm, a)
contts(lm, a)
lm |
lm object |
a |
The a-th parameter estimate of a linear model regression |
se.coef |
The standard error of the selected coefficient |
t.stat |
The t-stat of the selected coefficient |
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
x=rnorm(100) y=1+0.2*x+rnorm(100) LMout=lm(y~x) contts(LMout,1) #$se.coef #[1] 0.1081023 #$t.stat #(Intercept) # 10.60401
x=rnorm(100) y=1+0.2*x+rnorm(100) LMout=lm(y~x) contts(LMout,1) #$se.coef #[1] 0.1081023 #$t.stat #(Intercept) # 10.60401
Annual crime dataset of US counties
data(crime)
data(crime)
A data frame of US counties
county
counties index, N
year
Year, t
crmrte
crime rate(crime/population)
prbarr
probability of arrest (arrests/offenses)
prbconv
probability of conviction, given arrest
prbpris
probability of a prison, given conviction
avgsen
sanction severity(average prison sentence in days )
polpc
ability of police force to detect crime(# of police per capita)
density
population density(POP/area)
taxpc
Taxpayment per capita
region
region index of county
smsa
=1 if SAMA, POP>50000; =0 else
pctmin
See Baltagi(2006) for details
wcon
See Baltagi(2006) for details
wtuc
See Baltagi(2006) for details
wtrd
See Baltagi(2006) for details
wfir
See Baltagi(2006) for details
wser
See Baltagi(2006) for details
wmfg
See Baltagi(2006) for details
wfed
See Baltagi(2006) for details
wsta
See Baltagi(2006) for details
wloc
See Baltagi(2006) for details
mix
See Baltagi(2006) for details
pctymle
See Baltagi(2006) for details
Baltagi Badi H. (2005) Econometric Analysis of Panel Data. John Wiley. Baltagi Badi H. (2006) Estimating an Economic Model of Crime Using Panel Data from North Carolina. J.of Applied Econometrics 21: 543¡V547.
The Durlauf-Johnson data manupipulated by Hansen(2000),excluding missing variables and oil states
data(dur_john)
data(dur_john)
A data frame with 19 countries
gdpGrowth
Economic growth measured by GDP of 1960 and 1985
logGDP60
log Per capita GDP in 1960
Inv_GDP
Average ratio of investment (including Government Investment) to GDP from 1960 to 1985
popGrowth
Average growth rate of working-age population 1960 to 1985
School
Average fraction of working-age population enrolled in secondary school from 1960 to 1985
GDP60
Per capita GDP in 1960
Literacy
fraction of the population over 15 years old that is able to read and write in 1960
Steven N. Durlauf and Paul A. Johnson, "Multiple Regimes and Cross-Country Growth Behavior," Journal of Applied Econometrics, Vol. 10, No. 4, 1995, 365-384.
data(dur_john) head(dur_john)
data(dur_john) head(dur_john)
This function generates the level regresors in HEGY regression, without differenced lag terms.
hegy.reg(wts)
hegy.reg(wts)
wts |
Univariate time series, with a possibly seasonal stochastic trend |
This function automatically identifies the frequency of time series data, and generate necessary level components as described in Eq.(3.7) of Hylleberg et. al (1990).
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y=inf_Q[,1] hegy.reg(y)
data(inf_Q) y=inf_Q[,1] hegy.reg(y)
The function performs seasonal unit root test based on Eq.(3.6) of Hylleberg et al. (1990), univariate time series.
HEGY.test(wts, itsd, regvar = 0, selectlags = list(mode = "signf", Pmax = NULL))
HEGY.test(wts, itsd, regvar = 0, selectlags = list(mode = "signf", Pmax = NULL))
wts |
Univariate time series |
itsd |
Options for c(i,t,sd) |
regvar |
Additional regressors |
selectlags |
Selection of lags |
Mode for selectlags has three options, AIC and BIC use R built-in functions for linear model and their meanings are popular and straightforward. They include only lags that meet specific criterion, others are dropped from regressors. That is, lag orders of your model may not be a regular sequence. See also selPsignf() and selPabic().
stats |
Tests statistics for HEGY regression coefficients. |
hegycoefs |
HEGY regression coefficients. |
lagsorder |
Lags order. "aic" or "bic" returns a scalar; "signf" returns a sequence of numbers |
lagcoefs |
Coefficients of lag terms. |
regvarcoefs |
Coefficient(s) of additional regressor(s). |
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y<-inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="aic", Pmax=12)) hegy.out$stats #HEGY test statistics names(hegy.out) # HEGY objects, which can be called by using $, see below. hegy.out$hegycoefs hegy.out$regvarcoefs
data(inf_Q) y<-inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="aic", Pmax=12)) hegy.out$stats #HEGY test statistics names(hegy.out) # HEGY objects, which can be called by using $, see below. hegy.out$hegycoefs hegy.out$regvarcoefs
This function performs Hausman specification test for panel glm.
htest_pglm(RE, FE, re.method)
htest_pglm(RE, FE, re.method)
RE |
Random effect objects. Support pglm, glmer, glmmTMB |
FE |
Fixed effect objects. |
re.method |
Method that used to estimate the random effect estimation, in addition to "pglm", it also supports "glmmTMB" of package glmmTMB, and "glmer" of package lme4. |
Ho Tsung-wu <[email protected]>, modifed from phtest() of plm
Hausman J.A. (1978). Specification Tests in Econometrics. Econometrica, 46, 1251-1271.
data(ship) library(pglm) Eq1="accident ~ op_75_79+co_65_69+co_70_74+co_75_79" FE.pois <- pglm(Eq1,data=ship,family = "poisson",model = "within",index = 'ship',R=10) RE.pois <- pglm::pglm(Eq1,data=ship,family = "poisson", model = "random", index = 'ship') ## Hausman test htest_pglm(RE=RE.pois, FE=FE.pois, re.method="pglm") Eq2=accident ~ op_75_79+co_65_69+co_70_74+co_75_79 + (1 | ship) re.glmmTMB=glmmTMB::glmmTMB(Eq2,data=ship, family="poisson") ## Hausman test htest_pglm(RE=re.glmmTMB, FE=FE.pois, re.method="glmmTMB")
data(ship) library(pglm) Eq1="accident ~ op_75_79+co_65_69+co_70_74+co_75_79" FE.pois <- pglm(Eq1,data=ship,family = "poisson",model = "within",index = 'ship',R=10) RE.pois <- pglm::pglm(Eq1,data=ship,family = "poisson", model = "random", index = 'ship') ## Hausman test htest_pglm(RE=RE.pois, FE=FE.pois, re.method="pglm") Eq2=accident ~ op_75_79+co_65_69+co_70_74+co_75_79 + (1 | ship) re.glmmTMB=glmmTMB::glmmTMB(Eq2,data=ship, family="poisson") ## Hausman test htest_pglm(RE=re.glmmTMB, FE=FE.pois, re.method="glmmTMB")
This function estimates the unit root regression based on instrument generating function of Change(2002) and returns useful outputs.
IGF(y, maxp, ic, spec)
IGF(y, maxp, ic, spec)
y |
A univariate time series data |
maxp |
the max number of lags |
ic |
Information criteria, either "AIC" or "BIC" |
spec |
regression model specification. |
Estimate univariate unit root test of Chang(2002).
tstat.IGF |
IGF unit root test |
beta |
regression coefficients. The first one is the AR(1) coefficient of unit root, and the last one is the intercept or trend |
sdev |
The IGF standard error for unit root coefficient |
cV |
The scalar C in IGF equation |
p |
The optimal number of lag |
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
Chang, Y. (2002) Nonlinear IV Unit Root Tests in Panels with Cross-Sectional Dependency. Journal of Econometrics, 110, 261-292.
data(inf19) y <- inf19[,1] IGF(y,maxp=35,ic="BIC",spec=2)$tstat.IGF
data(inf19) y <- inf19[,1] IGF(y,maxp=35,ic="BIC",spec=2)$tstat.IGF
Monthly inflation time series of 19 countries, 1971.1~2011.12
data(inf_M)
data(inf_M)
A data frame with 20 countries
AUSTRALIA
inflation of Austrlia
AUSTRIA
inflation of Austria
BELGIUM
inflation of Belgium
CANADA
inflation of Canada
DENMARK
inflation of Denmark
FINLAND
inflation of Finland
FRANCE
inflation of France
GREECE
inflation of Greece
ICELAND
inflation of Iceland
ITALY
inflation of Italy
JAPAN
inflation of Japan
LUXEMBOURG
inflation of Luxembourg
NETHERLANDS
inflation of Netherlands
NORWAY
inflation of Norway
PORTUGAL
inflation of Portugal
SPAIN
inflation of Spain
SWEDEN
inflation of Sweden
SWITZERLAND
inflation of Switzerland
UK
inflation of UK
USA
inflation of USA
Monthly CIP, seasonaly differenced of log CPI of 20 countries
data(inf_M) head(inf_M)
data(inf_M) head(inf_M)
Quarterly inflation time series of 19 countries, 1971Q1~2014Q4
data(inf_Q)
data(inf_Q)
A data frame with 19 countries
AUSTRLIA
inflation of Austrlia
AUSTRIA
inflation of Austria
BELGIUM
inflation of Belgium
CANADA
inflation of Canada
DENMARK
inflation of Denmark
FINLAND
inflation of Finland
FRANCE
inflation of France
GREECE
inflation of Greece
ICELAND
inflation of Iceland
ITALY
inflation of Italy
JAPAN
inflation of Japan
LUXEMBOURG
inflation of Luxembourg
NETHERLANDS
inflation of Netherlands
NORWAY
inflation of Norway
PORTUGAL
inflation of Portugal
SPAIN
inflation of Spain
SWEDEN
inflation of Sweden
SWITZERLAND
inflation of Switzerland
UK
inflation of UK
USA
inflation of USA
Quarterly CIP, seasonaly differenced of log CPI of 20 countries
data(inf_Q) head(inf_Q)
data(inf_Q) head(inf_Q)
Monthly inflation time series of 19 countries, 1984.1~2011.3
data(inf19)
data(inf19)
A data frame with 19 countries
AUSTRIA
inflation of Austria
BELGIUM
inflation of Belgium
CANADA
inflation of Canada
DENMARK
inflation of Denmark
FINLAND
inflation of Finland
FRANCE
inflation of France
GREECE
inflation of Greece
ICELAND
inflation of Iceland
ITALY
inflation of Italy
JAPAN
inflation of Japan
LUXEMBOURG
inflation of Luxembourg
NETHERLANDS
inflation of Netherlands
NORWAY
inflation of Norway
PORTUGAL
inflation of Portugal
SPAIN
inflation of Spain
SWEDEN
inflation of Sweden
SWITZERLAND
inflation of Switzerland
UK
inflation of UK
USA
inflation of USA
Monthly CIP, seasonaly differenced of log CPI of 19 countries
data(inf19) head(inf19)
data(inf19) head(inf19)
Hylleberg et. al (1990,pp.226-227) offer simulated critical values for seasonal unitr to test. interpolpval() is an internal call and should not be used independently.
interpolpval(code, stat, N, swarn = TRUE)
interpolpval(code, stat, N, swarn = TRUE)
code |
Type of HEGY model, this will be automatically identified. |
stat |
Empirical test statistics. |
N |
Sample size calculating stat above. |
swarn |
Logical. Whether the warning message for negative p-value will be returned? The default is TRUE. |
table |
Table for critical value and p-value. |
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
investment data of 565 listed companies, 1973-1987, from Hansen's example
data(invest)
data(invest)
A pooled data frame
invest[,1]
investment/assets
invest[,2]
Tobin's Q
invest[,3]
cash-flow/assets
invest[,4]
debt/assets
This is a pooled data frame, without date (T) and cross-section(N) ID columes
#data(invest) #head(invest)
#data(invest) #head(invest)
This function performs panel data-based HEGY seasonal unit root test, the asymptotics is based upon Otero et al.(2007).
ipsHEGY(data, itsd, Sel, pmax, CIPS = TRUE)
ipsHEGY(data, itsd, Sel, pmax, CIPS = TRUE)
data |
Panel data, T by N |
itsd |
Options for c(i,t,sd). |
Sel |
Selection of lags, having three options: "signf","bic","aic". |
pmax |
Maximum number of lags for searching optimal criteria. |
CIPS |
Logical. If TRUE, using Pesaran(2007) to account for cross-section correlation. The default is TRUE. |
Mode for selectlags has three options, AIC and BIC use R built-in functions for linear model and their meanings are popular and straightforward. "signf" includes only statistically significant lags, and statistically insignificant lags are dropped from regressors. That is, once you select this option, lags of your model may not be continuous.
The critical values for panel HEGY are standard normal for individual t-ratios, however,you need to perform simulation for the critical values of F joint test, at pdR 1.3. To this end, you are encouraged to work this out for yourself: using arima.sim() to sample seasonal time series with unit root (1-order difference) and obtain their statistics under the null using ipsHEGY(), then it is streightforward to obtain critical values.
Otero et al. (2007) provide critical values for quarterly frequency.
P_HEGY |
Panel HEGY statistics. |
U_HEGY |
Idividual HEGY statistics of N units. |
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
Otero, J., Smith, J., and Giulietti, M. (2005) Testing for seasonal unit roots in heterogeneous panels. Economics Letters, 86, 229-235.
Otero, J., Smith, J., and Giulietti, M. (2007) Testing for seasonal unit roots in heterogeneous panels in the presence of cross section dependence. Economics Letters, 86, 179-184.
Pesaran M. Hashem (2007) A simple panel unit root test in the presence of cross-section dependence. Journal of Applied Econometrics, 22, 265-312.
data(inf_Q) dataz<-inf_Q itsd<-c(1,0,c(1:3)) #Seasonal dummy only takes quarters 1:3, #becasue of the presence of common intercept. Sel<-"bic" # "aic","bic", "signf". pmax<-12 OUT<-ipsHEGY(dataz,itsd,Sel,pmax,CIPS=FALSE) OUT$P_HEGY OUT$U_HEGY # Simulation of critical values
data(inf_Q) dataz<-inf_Q itsd<-c(1,0,c(1:3)) #Seasonal dummy only takes quarters 1:3, #becasue of the presence of common intercept. Sel<-"bic" # "aic","bic", "signf". pmax<-12 OUT<-ipsHEGY(dataz,itsd,Sel,pmax,CIPS=FALSE) OUT$P_HEGY OUT$U_HEGY # Simulation of critical values
Determine the optimal number of lags for dynamic regression
lagSelect(y, maxp, ic)
lagSelect(y, maxp, ic)
y |
A univariate time series data |
maxp |
the max number of lags |
ic |
Information criteria, either "AIC" or "BIC" |
Information criteria "AIC" and "BIC" use the R built-in functions.
It returns an integer, indicating the optimal lags
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
#library(pdR) #data(inf19) #y<-inf19[,1] #lagSelect(y,maxp=25,ic="BIC")
#library(pdR) #data(inf19) #y<-inf19[,1] #lagSelect(y,maxp=25,ic="BIC")
Function for looking up tabulated critical values and associated p-values,Hylleberg et. al (1990, Table 1a and Table 1b).
lookupCVtable(code)
lookupCVtable(code)
code |
Type of HEGY model, this will be automatically identified. |
table |
Table for critical value and p-value. |
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
This function is the main function estimating threshold regression for function ptm()
model(r, trim, rep, it, qq1, cf, xt, ct, thresh, tt, qn1, n, qn, cc, yt, ty, k)
model(r, trim, rep, it, qq1, cf, xt, ct, thresh, tt, qn1, n, qn, cc, yt, ty, k)
r |
vector of threshold estimate(s). |
trim |
value of trimmed percentage. |
rep |
number bootstrap repetition. |
it |
number of regime during computation, used in a for loop. |
qq1 |
defined parameter. |
cf |
special declaration, e.g. lag(). |
xt |
regime independent variables. |
ct |
trace of regime dependent variables. |
thresh |
threshold variable. |
tt |
length of time period. |
qn1 |
as defined by nrow(qq1). |
n |
number of cross-section units. |
qn |
number of quantiles to examine. |
cc |
as defined by 2*log(1-sqrt(conf_lev)). |
yt |
vectorized dependent variable. |
ty |
trace of yt. |
k |
number of regime-independent independent variables. |
Original code offered by Dr. B. E.Hansen (http://www.ssc.wisc.edu/~bhansen/).
Hanse B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Compute the panel unit root test statistic of Chang(2002).
pIGF(datamat, maxp, ic, spec)
pIGF(datamat, maxp, ic, spec)
datamat |
T by N panel data.T is the time length,N is the number of cross-section units. |
maxp |
the max number of lags |
ic |
Information criteria, either "AIC" or "BIC". |
spec |
model specification. |
This function estimates the panel unit root test based on univariate instrument generating function of (Chang,2002).
panel.tstat |
panel IGF test statistics |
pvalue |
P-value of the panel.tstat |
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
Chang,Y.(2002) Nonlinear IV Unit Root Tests in Panels with Cross-Sectional Dependency. Journal of Econometrics, 110, 261-292.
data(inf19) datam <- inf19 pIGF(datam,maxp=25,ic="BIC",spec=2)
data(inf19) datam <- inf19 pIGF(datam,maxp=25,ic="BIC",spec=2)
Gross state production data
data(productivity)
data(productivity)
A data frame with US production
US state index, 1-48
Year index
Gross state product
Expediture of public utility- highway construction
Expediture of public utility- water
Expediture of others
Private consumption of each state
Employment rate of each state
Unemployment rate of each state
data(productivity) head(productivity)
data(productivity) head(productivity)
A generalized specification for estimating panel threshold model.
ptm(dep, ind1, ind2, d, bootn, trimn, qn, conf_lev, t, n)
ptm(dep, ind1, ind2, d, bootn, trimn, qn, conf_lev, t, n)
dep |
Dependent variable |
ind1 |
Independent variables: regime dependent |
ind2 |
Independent variables:regime independent |
d |
Threshold variable |
bootn |
Vector of bootstrap repetition |
trimn |
Vector of trimmed percentage |
qn |
Number of quantiles to examine |
conf_lev |
Confidence level |
t |
Length of time period |
n |
Number of cross-section units |
This code fits only balanced panel data. It generalizes the simple code of Dr. Hansen (http://www.ssc.wisc.edu/~bhansen/), allowing multiple (more-than-one) regime-dependent (ind1) variables. We generalize the original code to better fit general need of threshold modeling in panel data.
bootn and trimn are vector of 3 by 1, indicating numbers of three corresponding regimes.
This version corrects a slight error incurred by argument max_lag, which is used by Hansen to arrange investment data via lags. In this package, users manipulate data to fit personal research to ptm(), hence this argument is omitted lest should degree of freedom will suffer a loss of N.
Ho Tsung-wu <[email protected]>, College of Management, National Taiwan Normal University.
Hansen B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
# library(pdR) #data(invest) #dat<-invest[1:1500,] # subsetting the first 1500 obs., #for simplicity #t <- 15 #Length of time period #nt <- nrow(dat) #n <- nt/t # number of cross-section units #dep<- as.matrix(dat[,1]) # investment/assets #th1<- as.matrix(dat[,2]) #Tobin's Q #th2<- as.matrix(dat[,3]) # cash-flow/assets #ind1<- cbind(th1,th2) #regime-dep covariates #d <- as.matrix(dat[,4]) # Threshold variable #ind2 <- cbind((th1^2),(th1^3),(th1*d)) # regime-indep covariates: #bootn<-c(100,200,300) # bootstrapping replications for each threshold esitmation #trimn<-c(0.05,0.05,0.05) #trimmed percentage for each threshold esitmation #qn<-400 #conf_lev<-0.95 #Output=ptm(dep,ind1,ind2,d,bootn,trimn,qn,conf_lev,t,n) #Output[[1]] #Formatted output of 1st threshold, 2 regimes #Output[[2]] #Formatted output of 2nd threshold, 3 regimes #Output[[3]] #Formatted output of 3rd threshold, 4 regimes # In the output, the Regime-dependent Coefficients matrix # is, from top to bottom, regime-wise.
# library(pdR) #data(invest) #dat<-invest[1:1500,] # subsetting the first 1500 obs., #for simplicity #t <- 15 #Length of time period #nt <- nrow(dat) #n <- nt/t # number of cross-section units #dep<- as.matrix(dat[,1]) # investment/assets #th1<- as.matrix(dat[,2]) #Tobin's Q #th2<- as.matrix(dat[,3]) # cash-flow/assets #ind1<- cbind(th1,th2) #regime-dep covariates #d <- as.matrix(dat[,4]) # Threshold variable #ind2 <- cbind((th1^2),(th1^3),(th1*d)) # regime-indep covariates: #bootn<-c(100,200,300) # bootstrapping replications for each threshold esitmation #trimn<-c(0.05,0.05,0.05) #trimmed percentage for each threshold esitmation #qn<-400 #conf_lev<-0.95 #Output=ptm(dep,ind1,ind2,d,bootn,trimn,qn,conf_lev,t,n) #Output[[1]] #Formatted output of 1st threshold, 2 regimes #Output[[2]] #Formatted output of 2nd threshold, 3 regimes #Output[[3]] #Formatted output of 3rd threshold, 4 regimes # In the output, the Regime-dependent Coefficients matrix # is, from top to bottom, regime-wise.
This function is a subroutine for model(), estimation procedure.
r_est(y, r, trim, tt, qq1, qn1, qn, n, cf, xt, ct, thresh)
r_est(y, r, trim, tt, qq1, qn1, qn, n, cf, xt, ct, thresh)
y |
vector of dependent variable. |
r |
numer of regime. |
trim |
value of trimmed percentage. |
tt |
length of time period. |
qq1 |
parameter defined by as.matrix(unique(thresh)[floor(sq*nrow(as.matrix(sort(unique(thresh)))))]). |
qn1 |
as defined by nrow(qq1). |
qn |
number of quantiles to examine. |
n |
parameter of cross-section units. |
cf |
special declaration, e.g. lag(). |
xt |
regime independent variables. |
ct |
trace of regime dependent variables. |
thresh |
threshold variable. |
Hanse B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Original code from Dr. Hansen (http://www.ssc.wisc.edu/~bhansen/).
ret() is similar to embed(), but returns a data.frame specified with colnames, not matrix.
ret(wts, k)
ret(wts, k)
wts |
Univariate time series. |
k |
k-1 lagged terms. |
ret() is similar to embed(), but returns a data.frame with colnames, not matrix. Moreover, unlike embed(),ret() fills lagged cells with NA, instead of trimming them.
A T by k dataframe returns. If you need 2 lags, you have to specify k=3, then it returns a dataframe with T by 3 dataframe, the first column is lag0.
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y=inf_Q[,2] ret(y,3)
data(inf_Q) y=inf_Q[,2] ret(y,3)
Generate a data matrix of seasonal components, having two pattern cycles.
SeasComponent(wts, type)
SeasComponent(wts, type)
wts |
A univeriate time series with monthly or quarterly frequency. |
type |
Types of patterns of seasonal cycle. |
This function generates data matrix for controlling the pattern of seasonal cycles. type="dummyCycle" generates DUMMY variables with season frequency. type="trgCycle" generates trigonometric pattern.
A dataframe returns. Number of columns is determined by frequency.
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Barsky, Robert B. and Jeffrey A. Miron (1989) The Seasonal Cycle and the Business Cycle. Journal of Political Economy, 97 (3): 503-32.
Granger, Clive William John and Newbold, Paul (1986) Forecasting Economic Time Series. 2nd edition. Published by New Milford, Connecticut, U.S.A.: Emerald Group Pub Ltd.
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y=inf_Q[,2] SeasComponent(y,type="dummyCycle") SeasComponent(y,type="trgCycle")
data(inf_Q) y=inf_Q[,2] SeasComponent(y,type="dummyCycle") SeasComponent(y,type="trgCycle")
Lagged coefficient estimates are kept if they meet the inequality condition of AIC or BIC.
selPabic(lmdet, type, Pmax = NULL)
selPabic(lmdet, type, Pmax = NULL)
lmdet |
Object of lm() |
type |
Take the value of "aic" or "bic". |
Pmax |
The maximum number of lag orders. |
This is an internal function used for HEGY.test(). Beginning with pamx, the lag order will be drop if its inclusion worsens the minimum condition. Hence, they may not be a regular sequence. For example, for pmax=10, the selected lags may look like (1,4,5,8,9), rather than 1,2,3,...10.
This function returns the lag orders.
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y=inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="aic", Pmax=12)) hegy.out$lagsorder hegy.out$lagcoefs
data(inf_Q) y=inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="aic", Pmax=12)) hegy.out$lagsorder hegy.out$lagcoefs
Lagged coefficient estimates are kept if they are statistically significant
selPsignf(lmdet, cvref = 1.65, Pmax = NULL)
selPsignf(lmdet, cvref = 1.65, Pmax = NULL)
lmdet |
Object of lm() |
cvref |
Reference of critical values, the default is 1.65. |
Pmax |
The maximum number of lag orders. |
This is an internal function used for HEGY.test(). Beginning with pamx, the lag order will be kept if it is statistically significant. Hence, the lag orders may not be a regular sequence. For example, for pmax=10, the seelcted lags may look like (1,4,5,8,9), rather than 1,2,3,...10.
This function returns the lag orders.
Ho Tsung-wu <[email protected]>, modifed from Javier Lopez-de-Lacalle
Javier Lopez-de-Lacalle in https://github.com/cran/uroot/blob/master/R/hegy.R
data(inf_Q) y=inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="signf", Pmax=12)) hegy.out$lagsorder hegy.out$lagcoefs
data(inf_Q) y=inf_Q[,1] hegy.out<-HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="signf", Pmax=12)) hegy.out$lagsorder hegy.out$lagcoefs
Panel data on the number of ship accidents, McCullagh and Nelder(1989)
data("ship")
data("ship")
accident
the number of ship accidents
ship
Ship iD
service
the number of months in service
op_75_79
the operating period between 1975 and 1979
co_65_69
consecutive construction periods of 5 years
co_70_74
consecutive construction periods of 5 years
co_75_79
consecutive construction periods of 5 years
yr_con
years of construction
yr_op
years of operation
McCullagh, P., and J. A. Nelder (1989) Generalized Linear Models. 2nd ed. London: Chapman and Hall/CRC.
data(ship)
data(ship)
A function for estimating the subsampled data.
SMPLSplit_est(data,dep,indep,th,plot,h=1,nonpar=2)
SMPLSplit_est(data,dep,indep,th,plot,h=1,nonpar=2)
data |
the data in either data.frame or matrix. |
dep |
the name of dependent variable. |
indep |
the name(s) of independent variable(s). |
th |
the name of threshold variable. |
plot |
=1, plot; =0, do not plot. |
h |
h=1, heteroskedasticity-consistent covariance; h=0, homoskedastic case. |
nonpar |
Indicator for non-parametric method used to estimate nuisance scale in the presence of heteroskedasticity (only relevant if h=1).Set nonpar=1 to estimate regressions using a quadratic.Set nonpar=2 to estimate regressions using an Epanechnikov kernel with automatic bandwidth. |
This code estimates the parameters of sub-sampled data. It generalizes the simple code of Dr. Hansen, allowing White Corrected Heteroskedastic Errors.
threshold |
values of threshold estimates. |
est0 |
coefficient estimates of global data. |
est.low |
coefficient estimates of low regime. |
est.high |
coefficient estimates of high regime. |
est0.info |
additional information of global data. |
est.joint.info |
additional information of joint threshods. |
est.low.info |
additional information of est.low. |
est.high.info |
additional information of est.high. |
Original code offered by Dr. B. E.Hansen (http://www.ssc.wisc.edu/~bhansen/).
Hanse B. E. (2000) Sample Splitting and Threshold Estimation. Econometrica, 68, 575-603.
## Not run, becasue of bootstrap replicaiton takes time. Users may unmark # and run. data("dur_john") rep <- 500 trim_per <- 0.15 dep <- "gdpGrowth" indep <- colnames(dur_john)[c(2,3,4,5)] SMPLSplit_est(data=dur_john,dep,indep,th="GDP60",plot=0,h=1,nonpar=2)
## Not run, becasue of bootstrap replicaiton takes time. Users may unmark # and run. data("dur_john") rep <- 500 trim_per <- 0.15 dep <- "gdpGrowth" indep <- colnames(dur_john)[c(2,3,4,5)] SMPLSplit_est(data=dur_john,dep,indep,th="GDP60",plot=0,h=1,nonpar=2)
A sample code for learning sample splitting.
SMPLSplit_example(data,dep,indep,th1,th2,trim_per,rep,plot)
SMPLSplit_example(data,dep,indep,th1,th2,trim_per,rep,plot)
data |
the data in either data.frame or matrix. |
dep |
the name of dependent variable. |
indep |
the name(s) of independent variable(s) |
th1 |
the first threshold variable. |
th2 |
the second threshold variable. |
trim_per |
trimmed percentage. |
rep |
nNumber of bootstrap repetitions. |
plot |
=1, plot; =0, do not plot. |
This code is the learning example for learning Hansen's econometric sample splitting. I detailed the description of each threshold stage.
Original code offered by Dr. B. E.Hansen (http://www.ssc.wisc.edu/~bhansen/).
Hanse B. E. (2000) Sample Splitting and Threshold Estimation. Econometrica, 68, 575-603.
## Not run, becasue of bootstrap replicaiton takes time. Users may unmark # and run. data("dur_john") #rep <- 500 #trim_per <- 0.15 #dep <- "gdpGrowth" #indep <- colnames(dur_john)[c(2,3,4,5)] #th1 <- "GDP60" #th2 <- "Literacy" #OUT=SMPLSplit_est(data=dur_john,dep,indep,th=th1,plot=0,h=1,nonpar=2) #OUT$TEST #OUT$Hypothesis #OUT$Threshold #stat=matrix(as.numeric(OUT$TEST),byrow = TRUE,8,2) #colnames(stat)=c("F-Stat","P-value") #rownames(stat)=OUT$Hypothesis #stat
## Not run, becasue of bootstrap replicaiton takes time. Users may unmark # and run. data("dur_john") #rep <- 500 #trim_per <- 0.15 #dep <- "gdpGrowth" #indep <- colnames(dur_john)[c(2,3,4,5)] #th1 <- "GDP60" #th2 <- "Literacy" #OUT=SMPLSplit_est(data=dur_john,dep,indep,th=th1,plot=0,h=1,nonpar=2) #OUT$TEST #OUT$Hypothesis #OUT$Threshold #stat=matrix(as.numeric(OUT$TEST),byrow = TRUE,8,2) #colnames(stat)=c("F-Stat","P-value") #rownames(stat)=OUT$Hypothesis #stat
A function for testing sample split given subsampled data.
SMPLSplit_het(data,dep,indep,th,trim_per,rep,plot)
SMPLSplit_het(data,dep,indep,th,trim_per,rep,plot)
data |
the data in either data.frame or matrix |
dep |
the name of dependent variable. |
indep |
the name(s) of independent variable(s). |
th |
the name of threshold variable. |
trim_per |
trimmed percentage. |
rep |
number of bootstrap repetition. |
plot |
=1, plot; =0, do not plot. |
This code tests for the presence of threshold. It generalizes the simple code of Dr. Hansen, allowing Heteroskedastic Errors (White Corrected).
fstat |
LM-test for no threshold. |
pvalue |
bootstrap P-Value. |
Original code offered by Dr. B. E.Hansen (http://www.ssc.wisc.edu/~bhansen/).
Hanse B. E. (2000) Sample Splitting and Threshold Estimation. Econometrica, 68, 575-603.
SSE calculation
sse_calc(y, x)
sse_calc(y, x)
This function is a sub-routine for model(), calculating SSE of each regression
y |
vector of dependent variable. |
x |
matrix of independent variables. |
Hanse B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Original code from Dr. Hansen (http://www.ssc.wisc.edu/~bhansen/).
Compute the resursive mean of each series
tbar(x)
tbar(x)
x |
A univariate time series data |
This function computes the resursive mean
Ho Tsung-wu <[email protected]>
data(inf19) y <- inf19[,1] tbar(y)
data(inf19) y <- inf19[,1] tbar(y)
This function is a sub-routine for model(), calculating SSE of each threshold regression.
thr_sse(y, q, r, cf, xt, ct, thresh, tt, n)
thr_sse(y, q, r, cf, xt, ct, thresh, tt, n)
y |
parameter. |
q |
qq1 in model(). |
r |
parameter. |
cf |
as defined in model(). |
xt |
as defined in model(). |
ct |
as defined in model(). |
thresh |
as defined in model(). |
tt |
as defined in model(). |
n |
as defined in model(). |
Hanse B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Original code from Dr. Hansen (http://www.ssc.wisc.edu/~bhansen/).
Estimation of trace.
tr(y, tt, n)
tr(y, tt, n)
This function is a sub-routine for model(), calculating trace of matrix
y |
data vector. |
tt |
time period length. |
n |
number of cross-section units. |
Hanse B. E. (1999) Threshold effects in non-dynamic panels: Estimation, testing and inference. Journal of Econometrics,93, 345-368.
Original code from Dr. Hansen (http://www.ssc.wisc.edu/~bhansen/).