R/BIVDGP.R

Defines functions BIVDGP

Documented in BIVDGP

#' Normal errors with break in variance 
#' 
#' 
#' The processes \eqn{y} and \eqn{x} are generated by a predictive regression of the form \eqn{y_t=\beta x_{t-1}+\varepsilon_t} for \eqn{t=1,\cdots,T},
#' in which the regressors follow an AR(1) process - i.e. \eqn{x_t=\theta x_{t-1}+u_t}.  
#' The predictor's errors are distributed according to \eqn{u_t\sim N(0,1)}, whereas the disturbances 
#' of the predictive regression, \eqn{\varepsilon_t}, are distributed \eqn{\varepsilon_t\sim N(0,1)} for \eqn{t\neq T/2} and
#' \eqn{\varepsilon_t\sim 1000 N(0,1)} for \eqn{t= T/2} respectively. An example of standard Normal disturbances with break in variance can be found in 
#' \insertCite{dufour2010exact;textual}{PredictiveDGP}. The initial value of the process \eqn{x} is generated by \eqn{x_0=\frac{w_0}{\sqrt{1-\theta^2}}}, 
#' where \eqn{w_t\sim N(0,1)}. Finally, the contemporaneous correlation between the disturbances \eqn{\varepsilon_t} and \eqn{u_t} is captured by \eqn{\rho\varepsilon_t+w_t\sqrt{1-\rho^2}}.
#' 
#' 
#' @param n the number of observations
#' @param beta the regressor coefficient of the predictive regression
#' @param theta the autocorrelation coefficient of the predictor
#' @param rho the contemporaneous correlation coefficient    
#' @keywords endogeneity persistency normal break-in-variance
#' @import pracma
#' @export 
#' @examples
#' BIVDGP(n=50, beta=0.5, theta=0.999, rho=0.9)
#' @references
#' \insertAllCited{}
#' @importFrom Rdpack reprompt
#' 
#' 
BIVDGP <- function(n, beta, theta, rho){
	
	#Generate the error terms with break in variance for the predictive regression, and the standard normal errors for the regressor.
	eps <- rnorm(n, 0, 1)
	brk <- round(n/2)
	eps[brk] <- 1000*rnorm(1, 0, 1)
	w <- rnorm(n, 0, 1)
	
	#Generate empty variables
	u <- rep(0, times=n)
	x <- rep(0, times=n)
	y <- rep(0, times=n)

	#Generate the initial predictor
	x[1] <- w[1]/(sqrt(1-theta^2))

	#Generate the error terms for the regressors. Note the possibility of feedback from the predictive regression errors to future x.
	for(i in 1:n){

		u[i] <- (rho*eps[i])+(w[i]*sqrt(1-rho^2))
	}
	
	#Generate the X and Y vectors
	for(k in 2:n){

		y[k] <- beta*x[k-1]+eps[k]
		x[k] <- theta*x[k-1]+u[k]

	}

	#Outcome variable
	z <- flipud(cbind(y, x))
	
	#Return output
	return(z)
}
kavehsn/PredictiveDGP documentation built on Dec. 21, 2021, 5:21 a.m.