R/NormalDGP.R

Defines functions NormalDGP

Documented in NormalDGP

#' Standard normal errors
#' 
#' 
#' 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)}. 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{u_t=\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 standard
#' @import pracma
#' @export 
#' @examples
#' NormalDGP(n=50, beta=0.5, theta=0.999, rho=0.9)
#' @references
#' \insertAllCited{}
#' @importFrom Rdpack reprompt
#
NormalDGP <- function(n, beta, theta, rho){

	#Generate the standard normal error terms for the predictive regression and the regressor 	
	eps <- rnorm(n, 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.