How to generate the two time series

 How to generate the two time series of length 10000

 #fix the random seed

> set.seed(20140629)

> #define length of simulation

> N <- 10000
> #simulate a normal random walk
> x <- cumsum(rnorm(N))
> #set an initial parameter value
> gamma <- 0.6
> #simulate the cointegrating series
> y <- gamma * x + rnorm(N)
> #plot the two series
> plot(x, type='l')
> lines(y,col="red")
https://www.mathclasstutor.online

# Augmented Dickey-Fuller Test Unit Root Test #

###############################################

Test regression none


Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)

Residuals:
    Min      1Q  Median      3Q     Max
-3.7583 -0.6800 -0.0105  0.6604  3.6463

Coefficients:
             Estimate Std. Error t value
z.lag.1    -0.0008567  0.0004221  -2.030
z.diff.lag  0.0287582  0.0099989   2.876
           Pr(>|t|) 
z.lag.1     0.04241 *
z.diff.lag  0.00403 **
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9956 on 9996 degrees of freedom
Multiple R-squared:  0.001212, Adjusted R-squared:  0.001012
F-statistic: 6.067 on 2 and 9996 DF,  p-value: 0.002328


Value of test-statistic is: -2.0297

Critical values for test statistics:
      1pct  5pct 10pct
tau1 -2.58 -1.95 -1.62

Augmented Dickey-Fuller Test Unit Root Test # 

###############################################

Test regression none


Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)

Residuals:
    Min      1Q  Median      3Q     Max
-5.4824 -0.9477 -0.0207  0.9182  5.1281

Coefficients:
             Estimate Std. Error t value
z.lag.1    -0.0032685  0.0009824  -3.327
z.diff.lag -0.4303026  0.0090285 -47.661
           Pr(>|t|) 
z.lag.1    0.000881 ***
z.diff.lag  < 2e-16 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.392 on 9996 degrees of freedom
Multiple R-squared:  0.1875, Adjusted R-squared:  0.1874
F-statistic:  1154 on 2 and 9996 DF,  p-value: < 2.2e-16


Value of test-statistic is: -3.3269

Critical values for test statistics:
      1pct  5pct 10pct
tau1 -2.58 -1.95 -1.62

 #take a linear combination of the series

> z = y - gamma*x
> plot(z,type='l')
https://www.mathclasstutor.online
summary(ur.df(z,type="none"))

###############################################
# Augmented Dickey-Fuller Test Unit Root Test #
###############################################

Test regression none


Call:
lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)

Residuals:
    Min      1Q  Median      3Q     Max
-3.6372 -0.6856 -0.0036  0.6590  3.5004

Coefficients:
           Estimate Std. Error t value
z.lag.1    -0.99967    0.01423 -70.250
z.diff.lag -0.01232    0.01000  -1.232
           Pr(>|t|) 
z.lag.1      <2e-16 ***
z.diff.lag    0.218 
---
Signif. codes:
  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’
  0.1 ‘ ’ 1

Residual standard error: 0.9983 on 9996 degrees of freedom
Multiple R-squared:  0.5061, Adjusted R-squared:  0.506
F-statistic:  5121 on 2 and 9996 DF,  p-value: < 2.2e-16


Value of test-statistic is: -70.2499

Critical values for test statistics:
      1pct  5pct 10pct
tau1 -2.58 -1.95 -1.62

#Estimate the cointegrating relationship

> #regression without intercept

> coin <- lm(y ~ x -1)

> #obtain the residuals

> coin$resid 

Post a Comment

0 Comments