. capt prog drop _all
. * spurious regression: independent random walks
. prog irwd, rclass
1. version 11
2. drop _all
3. set obs $N
4. local drift 2
5. g double x = 0 in 1
6. g double y = 0 in 1
7. replace x = x[_n - 1] + $trcoef * `drift' + rnormal() ///
> in 2/l
8. replace y = y[_n - 1] + $trcoef * `drift' + rnormal() ///
> in 2/l
9. reg y x
10. return scalar b = _b[x]
11. return scalar se = _se[x]
12. return scalar t = _b[x]/_se[x]
13. return scalar r2 = abs(return(t)) > invttail($N - 2, 0.025)
14. end
.
. global N 100
. global nsim 10000
. set seed 1010101
.
. // consider IRWs with no drift
. global trcoef 0
. simulate birwd=r(b) sirwd=r(se) tirwd=r(t) rejirwd=r(r2), ///
> reps($nsim) nodots saving(irw0, replace): irwd
command: irwd
birwd: r(b)
sirwd: r(se)
tirwd: r(t)
rejirwd: r(r2)
. su
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
birwd | 10000 .0003267 .6336891 -3.682241 3.301136
sirwd | 10000 .100645 .0649186 .0116683 .6898782
tirwd | 10000 -.0225758 7.390102 -34.39042 35.8372
rejirwd | 10000 .7572 .4287966 0 1
. l in 1/20
+--------------------------------------------+
| birwd sirwd tirwd rejirwd |
|--------------------------------------------|
1. | .4797036 .0366694 13.08186 1 |
2. | -.3215804 .126415 -2.543845 1 |
3. | .5518465 .0509739 10.82607 1 |
4. | -.9704604 .0774199 -12.53502 1 |
5. | .9274789 .0991612 9.353246 1 |
|--------------------------------------------|
6. | -.7858061 .0432042 -18.18819 1 |
7. | -.5938631 .0538909 -11.01972 1 |
8. | .6821204 .1127544 6.049611 1 |
9. | .5334677 .0528825 10.0878 1 |
10. | .0958101 .0618102 1.550069 0 |
|--------------------------------------------|
11. | -.3524039 .0844574 -4.172564 1 |
12. | .251032 .1512837 1.659346 0 |
13. | .8574678 .1752042 4.894105 1 |
14. | -.3218689 .0791635 -4.065877 1 |
15. | .2293266 .0713637 3.21349 1 |
|--------------------------------------------|
16. | -.3609286 .1122861 -3.214365 1 |
17. | -.5108765 .1038393 -4.919877 1 |
18. | -.0265709 .0448767 -.5920879 0 |
19. | -1.321453 .0955171 -13.83473 1 |
20. | -1.061208 .0308577 -34.39042 1 |
+--------------------------------------------+
.
. // consider IRWs with drift
. global trcoef 1
. simulate birwd=r(b) sirwd=r(se) tirwd=r(t) rejirwd=r(r2), ///
> reps($nsim) nodots saving(irw1, replace): irwd
command: irwd
birwd: r(b)
sirwd: r(se)
tirwd: r(t)
rejirwd: r(r2)
. su
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
birwd | 10000 1.001838 .0777357 .7386733 1.313212
sirwd | 10000 .0061999 .0019246 .0020809 .018849
tirwd | 10000 175.4512 49.80395 60.38373 473.0911
rejirwd | 10000 1 0 1 1
. l in 1/20
+------------------------------------------+
| birwd sirwd tirwd rejirwd |
|------------------------------------------|
1. | 1.002217 .0063258 158.4322 1 |
2. | 1.103606 .0050269 219.5395 1 |
3. | 1.083013 .0069692 155.399 1 |
4. | .9581092 .0051847 184.7967 1 |
5. | 1.085191 .0053837 201.5711 1 |
|------------------------------------------|
6. | .9154854 .0059151 154.7701 1 |
7. | 1.065713 .008413 126.6743 1 |
8. | 1.042774 .00848 122.9693 1 |
9. | 1.104847 .0062487 176.8136 1 |
10. | .9713724 .0048474 200.3911 1 |
|------------------------------------------|
11. | .8808553 .0062393 141.1783 1 |
12. | 1.08984 .0076755 141.9889 1 |
13. | 1.003118 .0056677 176.9884 1 |
14. | .9593877 .003884 247.0105 1 |
15. | .9122529 .0037094 245.9296 1 |
|------------------------------------------|
16. | .9130253 .0113659 80.33036 1 |
17. | .9648722 .0040714 236.988 1 |
18. | .9089801 .0085264 106.6083 1 |
19. | 1.079193 .0054492 198.045 1 |
20. | .9045779 .0067149 134.7114 1 |
+------------------------------------------+
.