Understanding Dickey-Fuller-Result I am currently looking into the dickey-fuller test but seem to not understand something fundamental. To understand the test better, I created 4 time series: cons, lin, r1 and r2. How these are generated can be seen in the code below. While r1 pulls samples from N(0,1), r2 follows the definition of a random walk. These are displayed as Figure 1.

I would expect to obtain Z(t) > 0.05 for r2 and fail to reject H0 that it is a random walk. On the other hand, I would expect Z(t) < 0.05 for lin, con and r1 and reject H0 since these are certainly no random walks.
UPDATE
The results however are not as clear as I would hope, for these very basic examples. While I fail to reject H0 for r2 (as anticipated), the same applies for lin and con with much higher certainty. Only drawing random samples (r1) is correctly identified not to be a random walk with certainty.
. do "dickey-fuller-example.do"

. set obs 80
Number of observations (_N) was 0, now 80.

. gen points = _n

. gen cons = 0

. gen lin = 0.02 * _n

. gen r1 = 0

. replace r1 = rnormal() if _n>1
(79 real changes made)

. gen r2  = 0 

. replace r2 = r2[_n-1] + rnormal() if _n>1
(79 real changes made)

. 
. two con cons lin r1 r2 points, msize(small...)

. 
. tsset points

Time variable: points, 1 to 80
        Delta: 1 unit

. 
. dfuller cons

DickeyFuller test for unit root           Number of obs  = 79
Variable: cons                             Number of lags =  0

H0: Random walk without drift, d = 0

                                       DickeyFuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)                 .       -3.539       -2.907       -2.588
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 1.0000.

. dfuller lin

DickeyFuller test for unit root           Number of obs  = 79
Variable: lin                              Number of lags =  0

H0: Random walk without drift, d = 0

                                       DickeyFuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)             0.151       -3.539       -2.907       -2.588
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.9694.

. dfuller r1

DickeyFuller test for unit root           Number of obs  = 79
Variable: r1                               Number of lags =  0

H0: Random walk without drift, d = 0

                                       DickeyFuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)            -7.259       -3.539       -2.907       -2.588
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.0000.

. dfuller r2

DickeyFuller test for unit root           Number of obs  = 79
Variable: r2                               Number of lags =  0

H0: Random walk without drift, d = 0

                                       DickeyFuller
                   Test      -------- critical value ---------
              statistic           1%           5%          10%
--------------------------------------------------------------
 Z(t)            -2.186       -3.539       -2.907       -2.588
--------------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.2112.

. 
end of do-file

Can somebody explain me what happens here? These are my main questions?

*

*Why do I fail to reject H0 for r2 with comparatively low confidence?

*Why do I fail to reject H0 for lin and cons?

*Is there an easy example like this to confirm that the test works correctly?

 A: The Dickey-Fuller test has the null hypothesis $$\text{H}_{0}\text{: The time series has unit root},$$with the alternative hypothesis $$\text{H}_{\text{A}}\text{: The time series is stationary.}$$Caveat: evidence in favor of 'stationary' in the alternative hypothesis is agnostic regarding weak or strong stationarity.
You fail to reject $\text{H}_{0}$ of the Dickey-Fuller test for r2 because r2 is a random walk and has a unit root (i.e. was generated by a process conforming to $\text{H}_{0}$).
You fail to reject $\text{H}_{0}$ of the Dickey-Fuller test for lin because each observation of lin at time $t$ 'looks like' the value of the observation at $t-1$ plus a perturbation. The Dickey-Fuller test as you have specified it tests whether the estimated value of $\beta=0$ under the null in:
$$\Delta y_{t} = \alpha +\beta y_{t-1} + \varepsilon _{t}$$
As the value of $\Delta y_{t}$ in lin is uncorrelated with the value of $y_{t-1}$, there is no evidence to reject a hypothesized value of $\beta=0$.
You fail to reject $\text{H}_{0}$ of the Dickey-Fuller test for cons because there is no variation in the outcome. Here $\Delta y_t = 0$ at every point in time, and while it does not matter whether $\alpha = 0$ or not, $\beta=0$ for sure. The missing test statistic results from not having any variance estimate ($\varepsilon=0$ also).
These results, (along with the test rejecting the null for r1) are consistent with Stata's dfuller working correctly.
