| 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.4 |
| Built: | 2026-07-15 07:13:28 UTC |
| Source: | https://github.com/cran/pdR |
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")
IDa numeric vector
Qtra numeric vector
preTax_Incomea numeric vector
shortRatioa numeric vector
longRatioa numeric vector
Current_ratioa numeric vector
LoanDeposit_ratioa 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
StateState abbreviation, N
YearYear, t
Y_SALESCigarette sales in packs per capita, deflated by population
X1_PRICEP=Real price per pack of cigarettes, deflated by 1983 CPI.
X2_PIMINReal minimum price in adjoining states per pack of cigarettes, deflated by CPI
X3_NDIPer capita disposable income
Baltagi Badi H. (2005) Econometric Analysis of Panel Data. John Wiley.
data(cigaretts) head(cigaretts)data(cigaretts) head(cigaretts)
Annual crime dataset of US counties
data(crime)data(crime)
A data frame of US counties
countycounties index, N
yearYear, t
crmrtecrime rate(crime/population)
prbarrprobability of arrest (arrests/offenses)
prbconvprobability of conviction, given arrest
prbprisprobability of a prison, given conviction
avgsensanction severity(average prison sentence in days )
polpcability of police force to detect crime(# of police per capita)
densitypopulation density(POP/area)
taxpcTaxpayment per capita
regionregion index of county
smsa=1 if SAMA, POP>50000; =0 else
pctminSee Baltagi(2006) for details
wconSee Baltagi(2006) for details
wtucSee Baltagi(2006) for details
wtrdSee Baltagi(2006) for details
wfirSee Baltagi(2006) for details
wserSee Baltagi(2006) for details
wmfgSee Baltagi(2006) for details
wfedSee Baltagi(2006) for details
wstaSee Baltagi(2006) for details
wlocSee Baltagi(2006) for details
mixSee Baltagi(2006) for details
pctymleSee 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
gdpGrowthEconomic growth measured by GDP of 1960 and 1985
logGDP60log Per capita GDP in 1960
Inv_GDPAverage ratio of investment (including Government Investment) to GDP from 1960 to 1985
popGrowthAverage growth rate of working-age population 1960 to 1985
SchoolAverage fraction of working-age population enrolled in secondary school from 1960 to 1985
GDP60Per capita GDP in 1960
Literacyfraction 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 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.IGFdata(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
AUSTRALIAinflation of Austrlia
AUSTRIAinflation of Austria
BELGIUMinflation of Belgium
CANADAinflation of Canada
DENMARKinflation of Denmark
FINLANDinflation of Finland
FRANCEinflation of France
GREECEinflation of Greece
ICELANDinflation of Iceland
ITALYinflation of Italy
JAPANinflation of Japan
LUXEMBOURGinflation of Luxembourg
NETHERLANDSinflation of Netherlands
NORWAYinflation of Norway
PORTUGALinflation of Portugal
SPAINinflation of Spain
SWEDENinflation of Sweden
SWITZERLANDinflation of Switzerland
UKinflation of UK
USAinflation 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
AUSTRLIAinflation of Austrlia
AUSTRIAinflation of Austria
BELGIUMinflation of Belgium
CANADAinflation of Canada
DENMARKinflation of Denmark
FINLANDinflation of Finland
FRANCEinflation of France
GREECEinflation of Greece
ICELANDinflation of Iceland
ITALYinflation of Italy
JAPANinflation of Japan
LUXEMBOURGinflation of Luxembourg
NETHERLANDSinflation of Netherlands
NORWAYinflation of Norway
PORTUGALinflation of Portugal
SPAINinflation of Spain
SWEDENinflation of Sweden
SWITZERLANDinflation of Switzerland
UKinflation of UK
USAinflation 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
AUSTRIAinflation of Austria
BELGIUMinflation of Belgium
CANADAinflation of Canada
DENMARKinflation of Denmark
FINLANDinflation of Finland
FRANCEinflation of France
GREECEinflation of Greece
ICELANDinflation of Iceland
ITALYinflation of Italy
JAPANinflation of Japan
LUXEMBOURGinflation of Luxembourg
NETHERLANDSinflation of Netherlands
NORWAYinflation of Norway
PORTUGALinflation of Portugal
SPAINinflation of Spain
SWEDENinflation of Sweden
SWITZERLANDinflation of Switzerland
UKinflation of UK
USAinflation of USA
Monthly CIP, seasonaly differenced of log CPI of 19 countries
data(inf19) head(inf19)data(inf19) head(inf19)
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,deterministic =c(1,0,0),lag.method="AIC",maxlag=12,CIPS = TRUE)ipsHEGY(data,deterministic =c(1,0,0),lag.method="AIC",maxlag=12,CIPS = TRUE)
data |
Panel data, T by N |
deterministic |
Options for deterministic components. |
lag.method |
Selection of optimal lags, having for options: "fixed","AIC", "BIC", "AICc". |
maxlag |
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 four options, AIC,AICc and BIC use R built-in functions for linear model and their meanings are popular and straightforward. "fixed" fixes maxlag as the number of lags.
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.
The univariate HEGY is based on R package uroot, simply modified to include cross-secionaal average.
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_M) #Seasonal dummy only takes quarters 1:3, #becasue of the presence of common intercept. OUT<-ipsHEGY(inf_M, deterministic = c(1,1,1), lag.method = "AIC", maxlag = 12,CIPS=TRUE) OUT$P_HEGY OUT$U_HEGY # Simulation of critical valuesdata(inf_M) #Seasonal dummy only takes quarters 1:3, #becasue of the presence of common intercept. OUT<-ipsHEGY(inf_M, deterministic = c(1,1,1), lag.method = "AIC", maxlag = 12,CIPS=TRUE) 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")
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/).
Panel data on the number of ship accidents, McCullagh and Nelder(1989)
data("ship")data("ship")
accidentthe number of ship accidents
shipShip iD
servicethe number of months in service
op_75_79the operating period between 1975 and 1979
co_65_69consecutive construction periods of 5 years
co_70_74consecutive construction periods of 5 years
co_75_79consecutive construction periods of 5 years
yr_conyears of construction
yr_opyears 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/).